Skip to content

Commit

Permalink
Merge pull request #1941 from cewert/report-finished-state
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert authored Sep 29, 2024
2 parents 0295a78 + c906457 commit f0f2882
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/PlaystateTask.bs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end sub
sub PlaystateUpdate()
if m.top.status = "start"
url = "Sessions/Playing"
else if m.top.status = "stop"
else if m.top.status = "stop" or m.top.status = "finished"
url = "Sessions/Playing/Stopped"
else if m.top.status = "update"
url = "Sessions/Playing/Progress"
Expand Down
36 changes: 28 additions & 8 deletions components/video/VideoPlayerView.bs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import "pkg:/source/utils/misc.bs"
import "pkg:/source/utils/config.bs"
import "pkg:/source/roku_modules/log/LogMixin.brs"

sub init()
m.log = log.Logger("VideoPlayerView")
' Hide the overhang on init to prevent showing 2 clocks
m.top.getScene().findNode("overhang").visible = false
m.currentItem = m.global.queueManager.callFunc("getCurrentItem")
Expand Down Expand Up @@ -600,6 +602,7 @@ end sub
'
' When Video Player state changes
sub onState(msg)
m.log.debug("start onState()", m.top.state)
if isValid(m.captionTask)
m.captionTask.playerState = m.top.state + m.top.globalCaptionMode
end if
Expand All @@ -608,12 +611,23 @@ sub onState(msg)
m.osd.playbackState = m.top.state

' When buffering, start timer to monitor buffering process
if m.top.state = "buffering" and m.bufferCheckTimer <> invalid
if m.top.state = "buffering"
' start buffer timer
if isValid(m.bufferCheckTimer)
m.bufferCheckTimer.control = "start"
m.bufferCheckTimer.ObserveField("fire", "bufferCheck")
end if

' start timer
m.bufferCheckTimer.control = "start"
m.bufferCheckTimer.ObserveField("fire", "bufferCheck")
' update server if needed
if not m.playReported
m.playReported = true
ReportPlayback("start")
end if
else if m.top.state = "error"
m.log.error(m.top.errorCode, m.top.errorMsg, m.top.errorStr, m.top.errorCode)

print m.top.errorInfo

if not m.playReported and m.top.transcodeAvailable
m.top.retryWithTranscoding = true ' If playback was not reported, retry with transcoding
else
Expand All @@ -623,7 +637,6 @@ sub onState(msg)

' Stop playback and exit player
m.top.control = "stop"
m.top.backPressed = true
else if m.top.state = "playing"

' Check if next episode is available
Expand All @@ -649,16 +662,22 @@ sub onState(msg)
m.playbackTimer.control = "stop"
ReportPlayback("stop")
m.playReported = false
else if m.top.state = "finished"
m.playbackTimer.control = "stop"
ReportPlayback("finished")
else
m.log.warning("Unhandled state", m.top.state, m.playReported, m.playFinished)
end if

m.log.debug("end onState()", m.top.state)
end sub

'
' Report playback to server
sub ReportPlayback(state = "update" as string)

if m.top.position = invalid then return

m.log.debug("start ReportPlayback()", state, int(m.top.position))

params = {
"ItemId": m.top.id,
"PlaySessionId": m.top.PlaySessionId,
Expand All @@ -677,6 +696,8 @@ sub ReportPlayback(state = "update" as string)
playstateTask = m.global.playstateTask
playstateTask.setFields({ status: state, params: params })
playstateTask.control = "RUN"

m.log.debug("end ReportPlayback()", state, int(m.top.position))
end sub

'
Expand All @@ -702,7 +723,6 @@ sub bufferCheck(msg)

' Stop playback and exit player
m.top.control = "stop"
m.top.backPressed = true
end if
end if

Expand Down

0 comments on commit f0f2882

Please sign in to comment.