Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
gsarath
Visitor

Resume Video content after Midroll playback of VideoScreen

Hi,

I am writing a sample application to verify integration steps for incorporating Ad Framework API's to play the Ad contents for roVideoScreen.

I am facing issues in resuming the video content after mid roll playback for videoscreen.
Below mentioned are the various code approaches I have tried, In all the approaches the video is not resuming and receiving message isPartialResult that the playback is interrupted:
1) video.Pause()
playContent = adIface.showAds(ads)
video.Resume()

2) playContent = adIface.showAds(ads)
video.Seek(resumeinMs)

3) playContent = adIface.showAds(ads)

4) playContent = adIface.showAds(ads)
metadata.PlayStart = seekPos * 1000
video.SetContent(metadata)

Please provide sample code for integrating the midroll to the video playback.
0 Kudos
5 REPLIES 5
renojim
Community Streaming Expert

Re: Resume Video content after Midroll playback of VideoScre

There's sample code in the documentation.

Calling getAds() in a while Loop::
while shouldPlayContent
videoMsg = wait(0, contentVideoScreen.GetMessagePort())
adPods = adIface.getAds(videoMsg)
if adPods <> invalid and adPods.Count() > 0
contentVideoScreen.Close() ' stop playback of content
shouldPlayContent = adIface.showAds(adPods) ' render current ad pod
if shouldPlayContent
' *** Insert client app’s resume-playback code here
end if
end if
' *** Insert client app’s video event handler code here
end while

It looks like you have to close the video screen and recreate it.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
BCVatOVG
Visitor

Re: Resume Video content after Midroll playback of VideoScre

The problem is that you can not have 2 video screens at the same time. You need to capture the position, stop the video, play the ads and then set the seek to the current position and then continue play.


video_player = scene.FindNode("video_player")
video_player.observeField("position", m.port)

video_ads_to_play = m.ads.ads_to_play(curent_position)
if video_ads_to_play <> invalid
video_player.control = "stop"
if m.ads.play_ads(video_ads_to_play)
video_player.seek = curent_position
video_player.control = "play"
end if
end if
0 Kudos
gsarath
Visitor

Re: Resume Video content after Midroll playback of VideoScre

Thanks for your reply.

@renojim: I am looking for the sample code to resume the video content
Even in the sample provided part of documentation, the code for resuming playback is not specified:
' *** Insert client app’s resume-playback code here

@BCVatOVG: I am looking for sample code of "roVideoScreen" not "roSGScreen"
0 Kudos
gsarath
Visitor

Re: Resume Video content after Midroll playback of VideoScre

I am able to resume the playback after midroll with the below mentioned code changes:
port = CreateObject("roMessagePort")
contentVideoScreen = CreateObject("roVideoScreen")
contentVideoScreen.setMessagePort(port)

adIface = Roku_Ads()
adUrl = "file://pkg:/images/ads.xml"
adIface.setAdUrl(adUrl)
ads = adIface.getAds()
if ads <> invalid and ads.count() > 0 ' to play pre roll
shouldPlayContent = adIface.showAds(ads)
end if

videoclip = CreateObject("roAssociativeArray")
videoclip.StreamBitrates = bitrates
videoclip.StreamUrls = urls
videoclip.StreamQualities = qualities
videoclip.StreamFormat = StreamFormat
videoclip.Title = title

contentVideoScreen.SetContent(videoclip)
contentVideoScreen.show()

curPos = 0
while shouldPlayContent
videoMsg = wait(0, contentVideoScreen.GetMessagePort())
adPods = adIface.getAds(videoMsg)
if adPods <> invalid and adPods.Count() > 0
contentVideoScreen.Close() ' stop playback of content
shouldPlayContent = adIface.showAds(adPods) ' render current ad pod
if shouldPlayContent
' *** Insert client app’s resume-playback code here
port = CreateObject("roMessagePort")
contentVideoScreen = CreateObject("roVideoScreen")
contentVideoScreen.setMessagePort(port)

contentVideoScreen.PlayStart = curPos
contentVideoScreen.SetContent(videoclip)
contentVideoScreen.show()
end if
end if
' *** Insert client app’s video event handler code here
if type(msg) = "roVideoScreenEvent"
print "showVideoScreen | msg = "; msg.GetMessage() " | index = "; msg.GetIndex()
if msg.isScreenClosed() then 'ScreenClosed event
print "Closing video screen"
exit while
else if msg.isFullResult() then
print "play back completed"
exit while
else if msg.isPaused() then
print("video Paused")
else if msg.isResumed() then
print("video Resumed")
else if msg.isPartialResult()
print "playback interrupted"
exit while
else if msg.isRequestFailed()
print "request failed - error: "
exit while
else if msg.isPlaybackPosition() then
print("playback position="+str(msg.GetIndex()))
curPos = msg.GetIndex()
end if
end if

end while

After completion of midroll ad, the main video content resumes. But I am not able to see only playbackposition event and able to see all the other events(pause/resume/FullResult/PartialResult). Can some one please specify is there anything I have missed?
0 Kudos
gsarath
Visitor

Re: Resume Video content after Midroll playback of VideoScre

Found the missing piece of code for fetching the playposition after midroll playback. Need to add the setPositionNotificationPeriod(1) for new instance video object to fix this issue.


while shouldPlayContent
. . .
' *** Insert client app’s resume-playback code here
. . .
contentVideoScreen.SetPositionNotificationPeriod(1)
. . .
' *** Insert client app’s video event handler code here
end while
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.