Skip to content

Commit

Permalink
Don't load song data until stream is loaded
Browse files Browse the repository at this point in the history
Fixes #1609
  • Loading branch information
1hitsong authored and cewert committed Jan 14, 2024
1 parent 353fdf2 commit 5db1b48
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions components/music/AudioPlayerView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 5db1b48

Please sign in to comment.