Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update server when video is in state finished #1941

Merged
merged 8 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 27 additions & 6 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 Down Expand Up @@ -649,16 +663,21 @@ sub onState(msg)
m.playbackTimer.control = "stop"
ReportPlayback("stop")
m.playReported = false
else if m.top.state = "finished"
m.playbackTimer.control = "stop"
ReportPlayback("finished")
m.top.backPressed = true ' force exit from video player to set TV back to SDR
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 Down
Loading