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: 
tmat1075
Visitor

Adding RAF ad between videos in a playlist

I feel like there's something I'm missing. I'd like to fire off an ad between videos in a playlist, but I can't find a straight-forward way to do it.  I put together this hack that sort of works:


if msg.GetField() = "position" then
                ' keep track of where we reached in content'
                curPos = msg.GetData()
                  ' Start ad at beginning of video'
                  if curIndex <> video.contentIndex
                    print "playing video:"
                    curIndex = video.contentIndex
                    print curIndex
                    ' if ad has not played yet'
                    if adPlayed[video.contentIndex] <> true then
                      adPlayed[video.contentIndex] = true
                      ' check for mid-roll ads'
                      adPods = RAF.getAds()
                      if adPods <> invalid and adPods.count() > 0
                        print "PlayerTask: mid-roll ads, stopping video"
                          'ask the video to stop - the rest is handled in the state=stopped event below'
                        video.control = "stop"
                      end if
                    end if
                  end if
end if


basically, I'm just checking if the current video id has changed and dropping in the ad.  However, this allows for a flash of the next video to play before the ad loads.  Is there anyway to have it more seamless?
0 Kudos
4 REPLIES 4
RokuNB
Roku Guru

Re: Adding RAF ad between videos in a playlist

I have no ready-made answer to this but... any chance that listening on "state" field could be of help?
0 Kudos
tmat1075
Visitor

Re: Adding RAF ad between videos in a playlist

Thanks @RokuNB !   I tried printing out the state, and it doesn't change between videos in the playlist. It continues as "playing".
0 Kudos
tmat1075
Visitor

Re: Adding RAF ad between videos in a playlist

My Code: https://gist.github.com/matula/eec01b7265c9b1be05e8f44768970ab1

One more issue I notice is that hitting that "<-" button while an ad is playing won't actually stop the ad.  It appears RAF isn't recognizing the back key press... though, if I run it as a pre-roll, I can see in the logs that the key press is registered, and everything works fine.  It's only in the loop that issue happens.  Any thoughts?
0 Kudos
destruk
Binge Watcher

Re: Adding RAF ad between videos in a playlist

If you are using scenegraph and you want to know when it moves to the next video you need to observe the "contentIndex" field of the video component.
That way the "playing" State will fire when the first video plays or any video is resumed, the video contentindex will fire when it moves to videos 2, 3, 4, 5, etc, and the "finished" State will fire when the playlist is done.  I haven't looked at the RAF code, or which version you're using, so it might work differently.
0 Kudos