Update MediaSession metadata for initially loaded track
The MediaSession metadata was only set on track change, but not for the track already set during load. Fixes #1252
This commit is contained in:
parent
8c69b68806
commit
997b510ec6
|
@ -0,0 +1 @@
|
||||||
|
Update MediaSession metadata for initially loaded track (#1252)
|
|
@ -277,6 +277,7 @@ export default {
|
||||||
})
|
})
|
||||||
if (this.currentTrack) {
|
if (this.currentTrack) {
|
||||||
this.getSound(this.currentTrack)
|
this.getSound(this.currentTrack)
|
||||||
|
this.updateMetadata()
|
||||||
}
|
}
|
||||||
// Add controls for notification drawer
|
// Add controls for notification drawer
|
||||||
if ('mediaSession' in navigator) {
|
if ('mediaSession' in navigator) {
|
||||||
|
@ -642,6 +643,28 @@ export default {
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
updateMetadata () {
|
||||||
|
// If the session is playing as a PWA, populate the notification
|
||||||
|
// with details from the track
|
||||||
|
if (this.currentTrack && 'mediaSession' in navigator) {
|
||||||
|
let metadata = {
|
||||||
|
title: this.currentTrack.title,
|
||||||
|
artist: this.currentTrack.artist.name,
|
||||||
|
}
|
||||||
|
if (this.currentTrack.album && this.currentTrack.album.cover) {
|
||||||
|
metadata.album = this.currentTrack.album.title
|
||||||
|
metadata.artwork = [
|
||||||
|
{ src: this.currentTrack.album.cover.urls.original, sizes: '96x96', type: 'image/png' },
|
||||||
|
{ src: this.currentTrack.album.cover.urls.original, sizes: '128x128', type: 'image/png' },
|
||||||
|
{ src: this.currentTrack.album.cover.urls.original, sizes: '192x192', type: 'image/png' },
|
||||||
|
{ src: this.currentTrack.album.cover.urls.original, sizes: '256x256', type: 'image/png' },
|
||||||
|
{ src: this.currentTrack.album.cover.urls.original, sizes: '384x384', type: 'image/png' },
|
||||||
|
{ src: this.currentTrack.album.cover.urls.original, sizes: '512x512', type: 'image/png' },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
navigator.mediaSession.metadata = new MediaMetadata(metadata)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
|
@ -723,26 +746,7 @@ export default {
|
||||||
this.playTimeout = setTimeout(async () => {
|
this.playTimeout = setTimeout(async () => {
|
||||||
await self.loadSound(newValue, oldValue)
|
await self.loadSound(newValue, oldValue)
|
||||||
}, 500);
|
}, 500);
|
||||||
// If the session is playing as a PWA, populate the notification
|
this.updateMetadata()
|
||||||
// with details from the track
|
|
||||||
if (this.currentTrack && 'mediaSession' in navigator) {
|
|
||||||
let metadata = {
|
|
||||||
title: this.currentTrack.title,
|
|
||||||
artist: this.currentTrack.artist.name,
|
|
||||||
}
|
|
||||||
if (this.currentTrack.album && this.currentTrack.album.cover) {
|
|
||||||
metadata.album = this.currentTrack.album.title
|
|
||||||
metadata.artwork = [
|
|
||||||
{ src: this.currentTrack.album.cover.urls.original, sizes: '96x96', type: 'image/png' },
|
|
||||||
{ src: this.currentTrack.album.cover.urls.original, sizes: '128x128', type: 'image/png' },
|
|
||||||
{ src: this.currentTrack.album.cover.urls.original, sizes: '192x192', type: 'image/png' },
|
|
||||||
{ src: this.currentTrack.album.cover.urls.original, sizes: '256x256', type: 'image/png' },
|
|
||||||
{ src: this.currentTrack.album.cover.urls.original, sizes: '384x384', type: 'image/png' },
|
|
||||||
{ src: this.currentTrack.album.cover.urls.original, sizes: '512x512', type: 'image/png' },
|
|
||||||
]
|
|
||||||
}
|
|
||||||
navigator.mediaSession.metadata = new MediaMetadata(metadata);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
immediate: false
|
immediate: false
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue