From d04a1e251576b26a2331d6472ad9a085d41e5f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=8C=E7=B3=96=E5=8C=85=E5=AD=90?= Date: Sun, 15 Jan 2023 17:19:52 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8Dchrome=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E5=AA=92=E4=BD=93=E4=BF=A1=E6=81=AF=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/api/Music.vue | 67 ++++++++++++++------------- src/views/api/aplayer/vue-aplayer.vue | 5 +- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/views/api/Music.vue b/src/views/api/Music.vue index efc2fc7..62c40c3 100644 --- a/src/views/api/Music.vue +++ b/src/views/api/Music.vue @@ -142,7 +142,7 @@ - + @@ -306,38 +306,39 @@ export default class Music extends BaseList { /** * 创建媒体信息 */ - // 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 = 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) + } + }) + } } diff --git a/src/views/api/aplayer/vue-aplayer.vue b/src/views/api/aplayer/vue-aplayer.vue index 7b56ab5..2b84d87 100644 --- a/src/views/api/aplayer/vue-aplayer.vue +++ b/src/views/api/aplayer/vue-aplayer.vue @@ -539,7 +539,10 @@ this.rejectPlayPromise = null } }, - + switch(index) { + this.playIndex = index + this.thenPlay() + }, // progress bar onProgressDragBegin (val) {