修复音乐播放媒体信息显示问题
This commit is contained in:
parent
c4645b29e4
commit
b0e8e8aab3
1
components.d.ts
vendored
1
components.d.ts
vendored
@ -38,7 +38,6 @@ declare module '@vue/runtime-core' {
|
|||||||
ElTable: typeof import('element-plus/es')['ElTable']
|
ElTable: typeof import('element-plus/es')['ElTable']
|
||||||
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
|
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
|
||||||
ElTag: typeof import('element-plus/es')['ElTag']
|
ElTag: typeof import('element-plus/es')['ElTag']
|
||||||
ElTooltip: typeof import('element-plus/es')['ElTooltip']
|
|
||||||
ElTransfer: typeof import('element-plus/es')['ElTransfer']
|
ElTransfer: typeof import('element-plus/es')['ElTransfer']
|
||||||
ElTree: typeof import('element-plus/es')['ElTree']
|
ElTree: typeof import('element-plus/es')['ElTree']
|
||||||
ElUpload: typeof import('element-plus/es')['ElUpload']
|
ElUpload: typeof import('element-plus/es')['ElUpload']
|
||||||
|
|||||||
@ -28,8 +28,8 @@ export interface MusicLyricModel {
|
|||||||
export interface MusicPlayerItem {
|
export interface MusicPlayerItem {
|
||||||
id: number
|
id: number
|
||||||
title: string
|
title: string
|
||||||
artist: string | undefined
|
artist?: string
|
||||||
album?: string | undefined
|
album?: string
|
||||||
src: string
|
src: string
|
||||||
pic: string
|
pic: string
|
||||||
lrc?: string
|
lrc?: string
|
||||||
|
|||||||
@ -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 v-if="musicPlaying" ref="player" autoplay showLrc :list="musicList" :music="currentMusic" @play="musicPlay"/>
|
<a-player v-if="musicPlaying" ref="player" autoplay showLrc :list="musicList" v-model:music="currentMusic" @play="musicPlay"/>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -221,6 +221,7 @@ export default class Music extends BaseList<MusicPage> {
|
|||||||
id: index,
|
id: index,
|
||||||
title: item.title || item.name,
|
title: item.title || item.name,
|
||||||
artist: item.artist,
|
artist: item.artist,
|
||||||
|
album: item.album,
|
||||||
src: `/api/v2/common/music/load/${item._id}`,
|
src: `/api/v2/common/music/load/${item._id}`,
|
||||||
pic: `/api/v2/common/music/album/${item._id}`,
|
pic: `/api/v2/common/music/album/${item._id}`,
|
||||||
}
|
}
|
||||||
@ -310,33 +311,31 @@ export default class Music extends BaseList<MusicPage> {
|
|||||||
musicPlay() {
|
musicPlay() {
|
||||||
if(!('mediaSession' in window.navigator) || !this.currentMusic) return;
|
if(!('mediaSession' in window.navigator) || !this.currentMusic) return;
|
||||||
const player = <any>this.$refs.player
|
const player = <any>this.$refs.player
|
||||||
const mediaSession: any = navigator.mediaSession
|
|
||||||
const currentId = this.currentMusic.id
|
const currentId = this.currentMusic.id
|
||||||
mediaSession.metadata = new MediaMetadata({
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
title: this.currentMusic.title,
|
title: this.currentMusic.title,
|
||||||
artist: this.currentMusic.artist,
|
artist: this.currentMusic.artist,
|
||||||
album: this.currentMusic.album,
|
album: this.currentMusic.album,
|
||||||
artwork: [{src: this.currentMusic.pic}]
|
artwork: [{src: location.origin + this.currentMusic.pic}]
|
||||||
})
|
})
|
||||||
const currentIndex = this.musicList.findIndex(item => item.id === currentId)
|
navigator.mediaSession.setActionHandler('play', () => { // 播放
|
||||||
mediaSession.setActionHandler('play', () => { // 播放
|
|
||||||
player.play()
|
player.play()
|
||||||
})
|
})
|
||||||
mediaSession.setActionHandler('pause', () => { // 暂停
|
navigator.mediaSession.setActionHandler('pause', () => { // 暂停
|
||||||
player.pause()
|
player.pause()
|
||||||
})
|
})
|
||||||
mediaSession.setActionHandler('previoustrack', () => { // 上一首
|
navigator.mediaSession.setActionHandler('previoustrack', () => { // 上一首
|
||||||
if (currentIndex === 0) { // 已经是第一首
|
if (currentId === 0) { // 已经是第一首
|
||||||
player.switch(this.musicList.length - 1)
|
player.switch(this.musicList.length - 1)
|
||||||
} else {
|
} else {
|
||||||
player.switch(currentIndex - 1)
|
player.switch(currentId - 1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
mediaSession.setActionHandler('nexttrack', () => { // 下一首
|
navigator.mediaSession.setActionHandler('nexttrack', () => { // 下一首
|
||||||
if (currentIndex === this.musicList.length - 1) { // 已经是最后一首
|
if (currentId === this.musicList.length - 1) { // 已经是最后一首
|
||||||
player.switch(0)
|
player.switch(0)
|
||||||
} else {
|
} else {
|
||||||
player.switch(currentIndex + 1)
|
player.switch(currentId + 1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Parse lrc, suppose multiple time tag
|
* Parse lrc, suppose multiple time tag
|
||||||
* @param {string} lrc_s - Format:
|
* @param {string} lrcRaw - Format:
|
||||||
* [mm:ss]lyric
|
* [mm:ss]lyric
|
||||||
* [mm:ss.xx]lyric
|
* [mm:ss.xx]lyric
|
||||||
* [mm:ss.xxx]lyric
|
* [mm:ss.xxx]lyric
|
||||||
@ -9,10 +9,10 @@
|
|||||||
*
|
*
|
||||||
* @return {Array} [[time, text], [time, text], [time, text], ...]
|
* @return {Array} [[time, text], [time, text], [time, text], ...]
|
||||||
*/
|
*/
|
||||||
export function parseLrc (lrc_s: string): Array<[number, string]> {
|
export function parseLrc (lrcRaw: string): Array<[number, string]> {
|
||||||
if (!lrc_s) return []
|
if (!lrcRaw) return []
|
||||||
lrc_s = lrc_s.replace(/([^\]^\n])\[/g, (match, p1) => p1 + '\n[')
|
lrcRaw = lrcRaw.replace(/([^\]^\n])\[/g, (match, p1) => p1 + '\n[')
|
||||||
const lyric = lrc_s.split('\n')
|
const lyric = lrcRaw.split('\n')
|
||||||
const lrc: Array<[number, string]> = []
|
const lrc: Array<[number, string]> = []
|
||||||
const lyricLen = lyric.length
|
const lyricLen = lyric.length
|
||||||
for (let i = 0; i < lyricLen; i++) {
|
for (let i = 0; i < lyricLen; i++) {
|
||||||
@ -36,8 +36,7 @@ export function parseLrc (lrc_s: string): Array<[number, string]> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// sort by time
|
// sort by time
|
||||||
lrc.sort((item1, item2) => item1[0] - item2[0])
|
return lrc.sort((item1, item2) => item1[0] - item2[0])
|
||||||
return lrc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function warn (message: string) {
|
export function warn (message: string) {
|
||||||
|
|||||||
@ -190,7 +190,7 @@
|
|||||||
*/
|
*/
|
||||||
volume: {
|
volume: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 0.8,
|
default: 0.5,
|
||||||
validator (value) {
|
validator (value) {
|
||||||
return value >= 0 && value <= 1
|
return value >= 0 && value <= 1
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user