radio stations now display the current track

This commit is contained in:
booploops 2022-06-15 07:59:23 -07:00
parent b8f582312f
commit 58aa41f525
2 changed files with 31 additions and 5 deletions

View file

@ -922,6 +922,15 @@ const app = new Vue({
}
})
this.mk.addEventListener(MusicKit.Events.timedMetadataDidChange, (e) => {
app.mk.nowPlayingItem.attributes.name = e.title
app.mk.nowPlayingItem.attributes.artistName = e.performer
app.mk.nowPlayingItem.attributes.albumName = e.album
app.currentArtUrl = e.links[0].url
app.mk.nowPlayingItem._songId = e._adamId ? e._adamId : -1
app.mk.nowPlayingItem.id = e._adamId ? e._adamId : -1
})
this.mk.addEventListener(MusicKit.Events.nowPlayingItemDidChange, (a) => {
if (self.$refs.queue) {
self.$refs.queue.updateQueue();
@ -1993,14 +2002,21 @@ const app = new Vue({
},
async getNowPlayingItemDetailed(target) {
let nowPlayingItem = JSON.parse(JSON.stringify(this.mk.nowPlayingItem))
if(nowPlayingItem.type === "radioStation" && app.mk.nowPlayingItem.id !== -1) {
nowPlayingItem.playParams = {kind: "songs"}
nowPlayingItem.attributes.playParams.catalogId = app.mk.nowPlayingItem.id
nowPlayingItem.attributes.playParams.id = app.mk.nowPlayingItem.id
nowPlayingItem.id = app.mk.nowPlayingItem.id
}
try {
let u = await app.mkapi(app.mk.nowPlayingItem.playParams.kind,
(app.mk.nowPlayingItem.songId == -1),
(app.mk.nowPlayingItem.songId != -1) ? app.mk.nowPlayingItem.songId : app.mk.nowPlayingItem["id"],
let u = await app.mkapi(nowPlayingItem.playParams.kind,
(nowPlayingItem.songId == -1),
(nowPlayingItem.songId != -1) ? nowPlayingItem.songId : nowPlayingItem["id"],
{ "include[songs]": "albums,artists", l: app.mklang });
app.searchAndNavigate(u.data.data[0], target)
} catch (e) {
app.searchAndNavigate(app.mk.nowPlayingItem, target)
app.searchAndNavigate(nowPlayingItem, target)
}
},
async searchAndNavigate(item, target) {
@ -4323,7 +4339,15 @@ const app = new Vue({
this.showMenuPanel(menus[useMenu], event)
try {
let result = await this.inLibrary([this.mk.nowPlayingItem])
// if its a radio station, then change the attributes to match a song
const nowPlayingItem = JSON.parse(JSON.stringify(this.mk.nowPlayingItem))
if(nowPlayingItem.type == "radioStation" && app.mk.nowPlayingItem.id != -1) {
nowPlayingItem.type = "song"
nowPlayingItem.attributes.playParams.catalogId = app.mk.nowPlayingItem.id
nowPlayingItem.attributes.playParams.id = app.mk.nowPlayingItem.id
nowPlayingItem.id = app.mk.nowPlayingItem.id
}
let result = await this.inLibrary([nowPlayingItem])
if (result[0].attributes.inLibrary) {
menus.normal.items.find(x => x.id == 'addToLibrary').hidden = true
menus.normal.items.find(x => x.id == 'removeFromLibrary').hidden = false

View file

@ -21,6 +21,8 @@
<apple-music-volume theme="dark"></apple-music-volume>
<amp-user-menu/>
<amp-tv-overlay/>
<amp-podcast-playback-controls/>
<amp-lcd/>
</div>
</script>
<script>