I finally got this working (kind of...I'll explain at the end) for the scene-graph video-player sample that is found
here.
I basically took what was suggested before and then tweaked it so that it would work in this example. Here is what I had to do:
1. Add RAF Library to your manifest.
2. Added the library to main.brs.
3. Rather than setup the fields in the main scene, I did this within main.brs:
m.global.addField("adPlayFlag", "bool", true)
m.global.addField("adFinishedPlaying", "bool", true)
m.global.addField("videoEventData", "int", true)
4. I had to modify the next step a little (added to the ShowHeroScreen sub of main.brs):
m.adIface = Roku_Ads()
m.adIface.setAdUrl()
m.global.observeField("adPlayFlag", m.port)
5. For the while look of the main thread (main.brs), I make it look like this:
while(true)
msg = wait(0, m.port)
msgType = type(msg)
if msgType = "roSGScreenEvent"
if msg.isScreenClosed() then return
end if
if msgType = "roSGNodeEvent"
if (msg.GetField() = "adPlayFlag") and m.global.adPlayFlag = true
m.global.setField("adPlayFlag","false")
m.adPods = m.adIface.getAds()
if m.adPods <> invalid and m.adPods.count() > 0
playContent = m.adIface.showAds(m.adPods)
end if
if playContent
' Play video flag
m.global.setField("adFinishedPlaying","true")
end if
end if
end if
end while
6. On the SpringBoard.brs file I added the following to the onItemSelected sub:
m.global.setField("videoEventData",event.getData())
m.global.setField("adPlayFlag","true")
m.global.observeField("adFinishedPlaying", "PlayVideo")
7. And finally, I added the following function to the SpringBoard.brs file:
function PlayVideo() as void
m.global.setField("adFinishedPlaying","false")
m.Video.control = "play"
if m.global.getField("videoEventData") <> 0 then m.Video.seek = m.top.seekposition
m.SpringDetails.visible = false
m.Video.visible = true
m.Video.setFocus(true)
end function
With these slight changes, it works for me using the referenced scene graph video-player example....Mostly. I am running into a problem where it won't play the ad a second time and I get the following error:
RAF 1.8; render failure: failed to create media playerI am not sure what is causing this problem. From other posts it sounds like there is already another video player active that is interfering with it. I will post something when I figure it out. In the meantime, please offer your comments or suggestions.