适配chrome浏览器媒体信息显示

This commit is contained in:
灌糖包子 2023-01-15 17:19:52 +08:00
parent 62c995a321
commit d04a1e2515
Signed by: sookie
GPG Key ID: 0599BECB75C1E68D
2 changed files with 38 additions and 34 deletions

View File

@ -142,7 +142,7 @@
</template>
</el-dialog>
<el-drawer v-model="musicPlaying" :close-on-click-modal="false" size="40%" title="播放音乐">
<a-player autoplay showLrc :list="musicList" :music="musicList[0]"/>
<a-player ref="player" autoplay showLrc :list="musicList" :music="musicList[0]" @play="musicPlay"/>
</el-drawer>
</div>
</template>
@ -306,38 +306,39 @@ export default class Music extends BaseList<MusicPage> {
/**
* 创建媒体信息
*/
// musicPlay() {
// if(!('mediaSession' in window.navigator)) return;
// const currentMusic = this.player.currentMusic
// const mediaSession: any = navigator.mediaSession
// mediaSession.metadata = new MediaMetadata({
// title: currentMusic.name,
// artist: currentMusic.artist,
// album: currentMusic.album,
// artwork: [{src: currentMusic.cover}]
// });
// mediaSession.setActionHandler('play', () => { //
// this.player.play()
// })
// mediaSession.setActionHandler('pause', () => { //
// this.player.pause()
// })
// const currentIndex = this.musicList.findIndex(item => item.id === currentMusic.id)
// mediaSession.setActionHandler('previoustrack', () => { //
// if (currentIndex === 0) { //
// this.player.switch(this.musicList.length - 1)
// } else {
// this.player.switch(currentIndex - 1)
// }
// })
// mediaSession.setActionHandler('nexttrack', () => { //
// if (currentIndex === this.musicList.length - 1) { //
// this.player.switch(0)
// } else {
// this.player.switch(currentIndex + 1)
// }
// })
// }
musicPlay() {
if(!('mediaSession' in window.navigator)) return;
const player = <any>this.$refs.player
const currentMusic = player.currentMusic
const mediaSession: any = navigator.mediaSession
mediaSession.metadata = new MediaMetadata({
title: currentMusic.name,
artist: currentMusic.artist,
album: currentMusic.album,
artwork: [{src: currentMusic.pic}]
});
mediaSession.setActionHandler('play', () => { //
player.play()
})
mediaSession.setActionHandler('pause', () => { //
player.pause()
})
const currentIndex = this.musicList.findIndex(item => item.src === currentMusic.src)
mediaSession.setActionHandler('previoustrack', () => { //
if (currentIndex === 0) { //
player.switch(this.musicList.length - 1)
} else {
player.switch(currentIndex - 1)
}
})
mediaSession.setActionHandler('nexttrack', () => { //
if (currentIndex === this.musicList.length - 1) { //
player.switch(0)
} else {
player.switch(currentIndex + 1)
}
})
}
}

View File

@ -539,7 +539,10 @@
this.rejectPlayPromise = null
}
},
switch(index) {
this.playIndex = index
this.thenPlay()
},
// progress bar
onProgressDragBegin (val) {