jf-roku/components/mediaPlayers/AudioPlayer.brs
1hitsong 57a4a5cf38
Create global audio player (#1024)
* Create global audio player
* Fix crash when pressing back
2023-02-27 18:51:27 -05:00

40 lines
1.1 KiB
Plaintext

sub init()
m.playReported = false
m.top.observeField("state", "audioStateChanged")
end sub
' State Change Event Handler
sub audioStateChanged()
currentState = LCase(m.top.state)
reportedPlaybackState = "update"
if currentState = "playing" and not m.playReported
reportedPlaybackState = "start"
m.playReported = true
else if currentState = "stopped" or currentState = "finished"
reportedPlaybackState = "stop"
m.playReported = false
end if
ReportPlayback(reportedPlaybackState)
end sub
' Report playback to server
sub ReportPlayback(state as string)
if not isValid(m.top.position) then return
params = {
"ItemId": m.global.queueManager.callFunc("getCurrentItem").id,
"PlaySessionId": m.top.content.id,
"PositionTicks": int(m.top.position) * 10000000&, 'Ensure a LongInteger is used
"IsPaused": (LCase(m.top.state) = "paused")
}
' Report playstate via global task
playstateTask = m.global.playstateTask
playstateTask.setFields({ status: state, params: params })
playstateTask.control = "RUN"
end sub