From 5db1b48f963308e84d1b67f2451c048b934bc74a Mon Sep 17 00:00:00 2001 From: 1hitsong <3330318+1hitsong@users.noreply.github.com> Date: Fri, 12 Jan 2024 21:07:36 -0500 Subject: [PATCH] Don't load song data until stream is loaded Fixes #1609 --- components/music/AudioPlayerView.bs | 78 +++++++++++++++-------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/components/music/AudioPlayerView.bs b/components/music/AudioPlayerView.bs index d9c3e1f93..ee6ab7090 100644 --- a/components/music/AudioPlayerView.bs +++ b/components/music/AudioPlayerView.bs @@ -388,46 +388,10 @@ end sub ' Update values on screen when page content changes sub pageContentChanged() - ' Reset buffer bar without animation - m.bufferPosition.width = 0 + m.LoadAudioStreamTask.control = "STOP" - useMetaTask = false currentItem = m.global.queueManager.callFunc("getCurrentItem") - if not isValid(currentItem.RunTimeTicks) - useMetaTask = true - end if - - if not isValid(currentItem.AlbumArtist) - useMetaTask = true - end if - - if not isValid(currentItem.name) - useMetaTask = true - end if - - if not isValid(currentItem.Artists) - useMetaTask = true - end if - - if useMetaTask - m.LoadMetaDataTask.itemId = currentItem.id - m.LoadMetaDataTask.observeField("content", "onMetaDataLoaded") - m.LoadMetaDataTask.control = "RUN" - else - if isValid(currentItem.ParentBackdropItemId) - setBackdropImage(ImageURL(currentItem.ParentBackdropItemId, "Backdrop", { "maxHeight": "720", "maxWidth": "1280" })) - end if - - setPosterImage(ImageURL(currentItem.id, "Primary", { "maxHeight": 500, "maxWidth": 500 })) - setScreenTitle(currentItem) - setOnScreenTextValues(currentItem) - m.songDuration = currentItem.RunTimeTicks / 10000000.0 - - ' Update displayed total audio length - m.totalLengthTimestamp.text = ticksToHuman(currentItem.RunTimeTicks) - end if - m.LoadAudioStreamTask.itemId = currentItem.id m.LoadAudioStreamTask.observeField("content", "onAudioStreamLoaded") m.LoadAudioStreamTask.control = "RUN" @@ -451,6 +415,46 @@ sub onAudioStreamLoaded() data = m.LoadAudioStreamTask.content[0] m.LoadAudioStreamTask.unobserveField("content") if data <> invalid and data.count() > 0 + ' Reset buffer bar without animation + m.bufferPosition.width = 0 + + useMetaTask = false + currentItem = m.global.queueManager.callFunc("getCurrentItem") + + if not isValid(currentItem.RunTimeTicks) + useMetaTask = true + end if + + if not isValid(currentItem.AlbumArtist) + useMetaTask = true + end if + + if not isValid(currentItem.name) + useMetaTask = true + end if + + if not isValid(currentItem.Artists) + useMetaTask = true + end if + + if useMetaTask + m.LoadMetaDataTask.itemId = currentItem.id + m.LoadMetaDataTask.observeField("content", "onMetaDataLoaded") + m.LoadMetaDataTask.control = "RUN" + else + if isValid(currentItem.ParentBackdropItemId) + setBackdropImage(ImageURL(currentItem.ParentBackdropItemId, "Backdrop", { "maxHeight": "720", "maxWidth": "1280" })) + end if + + setPosterImage(ImageURL(currentItem.id, "Primary", { "maxHeight": 500, "maxWidth": 500 })) + setScreenTitle(currentItem) + setOnScreenTextValues(currentItem) + m.songDuration = currentItem.RunTimeTicks / 10000000.0 + + ' Update displayed total audio length + m.totalLengthTimestamp.text = ticksToHuman(currentItem.RunTimeTicks) + end if + m.global.audioPlayer.content = data m.global.audioPlayer.control = "none" m.global.audioPlayer.control = "play"