# player flickers before playing client side midroll ads in linear stream

**URL:** <https://forum.developer.roku.com/t/player-flickers-before-playing-client-side-midroll-ads-in-linear-stream/10999>\
**Category:** Archived\
**Tags:** roku-developer-program\
**Created:** [January 29, 2024, 4:31pm UTC](https://forum.developer.roku.com/t/player-flickers-before-playing-client-side-midroll-ads-in-linear-stream/10999 "2024-01-29T16:31:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reshma](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@Reshma](https://forum.developer.roku.com/u/Reshma)\
**Post date:** [January 29, 2024, 4:31pm UTC](https://forum.developer.roku.com/t/player-flickers-before-playing-client-side-midroll-ads-in-linear-stream/10999/1 "2024-01-29T16:31:53Z")

</div>

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  
&nbsp;  
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
