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

This commit is contained in:
2023-01-15 17:19:52 +08:00
parent 62c995a321
commit d04a1e2515
2 changed files with 38 additions and 34 deletions
+34 -33
View File
@@ -142,7 +142,7 @@
</template> </template>
</el-dialog> </el-dialog>
<el-drawer v-model="musicPlaying" :close-on-click-modal="false" size="40%" title="播放音乐"> <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> </el-drawer>
</div> </div>
</template> </template>
@@ -306,38 +306,39 @@ export default class Music extends BaseList<MusicPage> {
/** /**
* 创建媒体信息 * 创建媒体信息
*/ */
// musicPlay() { musicPlay() {
// if(!('mediaSession' in window.navigator)) return; if(!('mediaSession' in window.navigator)) return;
// const currentMusic = this.player.currentMusic const player = <any>this.$refs.player
// const mediaSession: any = navigator.mediaSession const currentMusic = player.currentMusic
// mediaSession.metadata = new MediaMetadata({ const mediaSession: any = navigator.mediaSession
// title: currentMusic.name, mediaSession.metadata = new MediaMetadata({
// artist: currentMusic.artist, title: currentMusic.name,
// album: currentMusic.album, artist: currentMusic.artist,
// artwork: [{src: currentMusic.cover}] album: currentMusic.album,
// }); artwork: [{src: currentMusic.pic}]
// mediaSession.setActionHandler('play', () => { // 播放 });
// this.player.play() mediaSession.setActionHandler('play', () => { // 播放
// }) player.play()
// mediaSession.setActionHandler('pause', () => { // 暂停 })
// this.player.pause() mediaSession.setActionHandler('pause', () => { // 暂停
// }) player.pause()
// const currentIndex = this.musicList.findIndex(item => item.id === currentMusic.id) })
// mediaSession.setActionHandler('previoustrack', () => { // 上一首 const currentIndex = this.musicList.findIndex(item => item.src === currentMusic.src)
// if (currentIndex === 0) { // 已经是第一首 mediaSession.setActionHandler('previoustrack', () => { // 上一首
// this.player.switch(this.musicList.length - 1) if (currentIndex === 0) { // 已经是第一首
// } else { player.switch(this.musicList.length - 1)
// this.player.switch(currentIndex - 1) } else {
// } player.switch(currentIndex - 1)
// }) }
// mediaSession.setActionHandler('nexttrack', () => { // 下一首 })
// if (currentIndex === this.musicList.length - 1) { // 已经是最后一首 mediaSession.setActionHandler('nexttrack', () => { // 下一首
// this.player.switch(0) if (currentIndex === this.musicList.length - 1) { // 已经是最后一首
// } else { player.switch(0)
// this.player.switch(currentIndex + 1) } else {
// } player.switch(currentIndex + 1)
// }) }
// } })
}
} }
+4 -1
View File
@@ -539,7 +539,10 @@
this.rejectPlayPromise = null this.rejectPlayPromise = null
} }
}, },
switch(index) {
this.playIndex = index
this.thenPlay()
},
// progress bar // progress bar
onProgressDragBegin (val) { onProgressDragBegin (val) {