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: 
Reshma
Reel Rookie

player flickers before playing client side midroll ads in linear stream

Player flickers when playback to Midroll ad transition . please help me.

here is the code

while keepPlaying
msg = wait(0, port)
if type(msg) = "roSGNodeEvent"
if msg.GetField() = "position" then
' keep track of where we reached in content
m.curPos = msg.GetData()
' check for mid-roll ads
if(m.curPos >= duration - 10 and not videoCompleted)
videoCompleted = true
end if
adPods = RAF.getAds(msg)
if adPods <> invalid and adPods.count() > 0
print "AdsEventTask: mid-roll ads, stopping video"
'ask the video to stop - the rest is handled in the state=stopped event below
video.control = "stop"
' m.adTimes[key.tostr()] = keepPlaying
for i = 0 to m.adMarkers.Count() - 1
if m.adMarkers[i].startTime = adPods.rendertime * 1000
m.adMarkers.Delete(i)
exit for
end if
end for
m.top.adPositions = m.adMarkers
end if

else if msg.GetField() = "control" then
control = msg.GetData()
if video.state = "stopped" and video.visible = false
exit while
end if
else if msg.GetField() = "duration" then
duration = msg.GetData()


else if msg.GetField() = "state" then
curState = msg.GetData()
print "AdsEventTask: state = "; curState
if curState = "stopped" then
if adPods = invalid or adPods.count() = 0 then
exit while
end if

print "AdsEventTask: playing midroll/postroll ads"
keepPlaying = RAF.showAds(adPods, invalid, view)
adPods = invalid
if isPlayingPostroll then
exit while
end if
if keepPlaying then
print "AdsEventTask: mid-roll finished, seek to "; stri(m.curPos)
video.visible = true
video.seek = m.curPos
video.control = "play"
video.setFocus(true) 'important: take the focus back (RAF took it above)
else
m.top.backOut = true
exit while
end if
 
else if curState = "finished" then
print "AdsEventTask: main content finished"
' render post-roll ads
adPods = RAF.getAds(msg)
if adPods = invalid or adPods.count() = 0 then
exit while
end if
print "AdsEventTask: has postroll ads"
isPlayingPostroll = true
' stop the video, the post-roll would show when the state changes to "stopped" (above)
video.control = "stop"
end if
end if
end if
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.