Forum Discussion
RobSMS
10 years agoVisitor
I just figured it out a few days ago... I'm going to explain as simply as possible. These code items probably won't work, but are included to serve as an example.
I also want to point out that this is just what I've learned. There may be better ways to do it, but this worked for me. I'd love to hear suggestions if anyone has anything to offer.
Make sure you have added the RAF Library to your manifest
And to the first line in your main.brs (Main thread)
Then you need to setup a few fields in your main scene.
Then in your main thread (generally main.brs) initialize RAF and add an observeField that points to the msg port
In your while loop for the main thread
And now for the explanation....
When a user selects a piece of content to play, I set the "adPlayFlag" to true. This triggers the RAF function in the main thread and plays the ad.
When the ad has finished playing, I set the "adFinishedPlaying" flag to true.
I then have a observeField that that triggers the video to play when "adFinishedPlaying" is marked to true.
The above code is just an example to give you a basis of how I managed to get RAF working. There is obviously a bit more that you will need to include [size=100](ie: "Back" button presses while ads play), but this should get you started. [/size]
Hope this helps... I'll answer any questions as best as I can.
I also want to point out that this is just what I've learned. There may be better ways to do it, but this worked for me. I'd love to hear suggestions if anyone has anything to offer.
Make sure you have added the RAF Library to your manifest
bs_libs_required=roku_ads_lib
And to the first line in your main.brs (Main thread)
Library "Roku_Ads.brs"
Then you need to setup a few fields in your main scene.
<field id="adPlayFlag" type="bool" alwaysNotify="true" />
<field id="adFinishedPlaying" type="bool" alwaysNotify="true" />
Then in your main thread (generally main.brs) initialize RAF and add an observeField that points to the msg port
m.adIface = Roku_Ads()
m.adIface.setAdUrl()
scene.observeField("adPlayFlag", m.port)
In your while loop for the main thread
while(true)
msg = wait(0, m.port)
msgType = type(msg)
' Watches adPlayFlag for a "true" result then plays advertisement.
if msgType = "roSGNodeEvent"
if (msg.GetField() = "adPlayFlag") and scene.adPlayFlag = true
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
scene.adFinishedPlaying = true
end if
end if
end if
end while
And now for the explanation....
When a user selects a piece of content to play, I set the "adPlayFlag" to true. This triggers the RAF function in the main thread and plays the ad.
When the ad has finished playing, I set the "adFinishedPlaying" flag to true.
I then have a observeField that that triggers the video to play when "adFinishedPlaying" is marked to true.
The above code is just an example to give you a basis of how I managed to get RAF working. There is obviously a bit more that you will need to include [size=100](ie: "Back" button presses while ads play), but this should get you started. [/size]
Hope this helps... I'll answer any questions as best as I can.