I have pieced together some ideas I found in this forum, plus some stuff I made up myself, to make a "Play All Videos" option from my video details screen.
It works great, and even loops back to the first video once the last one in the playlist is played. The issue is that if I hit the "back" button to stop the video, it would just start the video over again. I fixed it to send me back out to my app home screen as a work-around, but that doesn't work either because my "stack" still has the videoplayer screen in it still in the loop.
What I would like to have happen is if I hit the back button, I would like for the video to stop, the video details screen of the current video to show (or even the video that we played to start the loop). I would even be happy if it would just take me back to the home screen and clear the stack. Is there some easy way to clear the stack? Here is some of the code.
This code is called when someone selects "Play all videos" (showVideoPlayerScreenAll()) from any video details screen in the playlist. An array (items) is passed in as the playlist. The index of the selected choice (passIndex) is passed in. The actual video itself and all of its parameters are being passed in (video) and is actually an associative array containing the name, id, caption and all sorts of other info about the video that is pulled and filtered from JSON at a vendor's API.
After the first video is complete, getNewVidInfo runs increments the passIndex and sets up the new video. It passes the initial items array, the new passIndex and the new video into playAllVids which sets the screen name and play start and then calles the main showVideoPlayerAll function again, completing the first iteration of the overall loop.
I am open to any suggestions on this.
Function getNewVidInfo (items, passIndex)
passIndex = passIndex + 1
if (passIndex = items.count())
passIndex = 0
end if
index = passIndex
feedUrl = "/asset?id=" + tostr(items[index].ContentId) + "&fields=hls_url,closed_caption_urls,rating,duration,time_start,date,trick_mode_urls"
conn = InitFeedConnection(feedUrl)
response = conn.LoadFeed()
if response = invalid
return -1
end if
print "the contentID in question is " items[index].contentId
video = convertDvidsApiAssetResponse(response,items[index])
playAllVids(items, passIndex, video)
End Function
Function playAllVids(items, passIndex, video)
while true
screenName = "asset_watch/" + right(video.ContentId,6)
analyticsTrackScreenview(screenName)
video.PlayStart = video.TimeStart
showVideoPlayerScreenAll(items, passIndex, video)
end while
End Function
Function showVideoPlayerScreenAll(items, passIndex, video As Object, pageTitle = invalid, parentPageTitle = invalid) As Integer
print "we are on video screen and items are " items
print "we are on video screen and index is " passIndex
if type(video) <> "roAssociativeArray" then
print "invalid data passed to showVideoPlayerScreen"
return -1
endif
'print video
port = CreateObject("roMessagePort")
screen = CreateObject("roVideoScreen")
screen.setMessagePort(port)
if(video.ContentId <> invalid)
PlayStartVariableName = right(video.ContentId,6)+"pos" ' remove video- from contentid
screen.SetPositionNotificationPeriod(5)
endif
screenName = "asset_watch/" + right(video.ContentId,6)
screen.SetContent(video)
setBreadCrumbs(screen, pageTitle, parentPageTitle)
screen.Show()
while true
event = wait(0, port)
if type(event) = "roVideoScreenEvent" then
'if event.getmessage()="Playback interrupted by user." then
'print "playback interrupted by user"
'showHomeScreen()
'end if
if event.isScreenClosed()
print "Screen closed by user"
showHomeScreen()
'return -1
else if event.isFullResult()
print "video finished"
if(RegRead(PlayStartVariableName) <> invalid)
RegDelete(PlayStartVariableName)
end if
getNewVidInfo(items, passIndex)
'return 0
'print "showHomeScreen | event = "; event.getMessage() " | index = "; event.GetIndex()
'else if event.isScreenClosed()
'print "Screen closed by user"
'showHomeScreen()
'return -1
else if event.isRequestFailed()
'print "Video request failure: "; event.GetIndex(); " " event.GetData()
else if event.isStatusMessage()
'print "Video status: "; event.GetIndex(); " " event.GetData()
else if event.isButtonPressed()
'print "Button pressed: "; event.GetIndex(); " " event.GetData()
else if event.isPlaybackPosition() then
currentPosition = event.GetIndex()
' If we're less than 10 seconds from the end of the video go ahead and delete the position tracker
if(currentPosition + 10 > video.length and RegRead(PlayStartVariableName) <> invalid)
RegDelete(PlayStartVariableName)
else
'print "CurrentPosition";currentPosition
RegWrite(PlayStartVariableName, currentPosition.toStr())
end if
end if
end if
end while
End Function