I'm trying to add VAST video pre-roll ads to the SThree sample Roku SDK project (the "Simple Grid with Video and Details page (.zip)" version).I can get it to work on app start by putting the following code into main.brslibrary "Roku_Ads.brs"
...
Sub RunUserInterface()
...
raf = Roku_Ads()
raf.setAdPrefs(false) 'disable back-filled ads
raf.setDebugOutput(true)
raf.setAdUrl("http://pubads.g.doubleclick.net/...")
adPods = raf.getAds()
shouldPlayContent = raf.showAds(adPods)
I however don't want to play an ad on startup, I want to play an ad before a video play. So I figure I can just add the lines above to components/screens/DetailsScreen/DetailsScreen.brs' on Button press handler
Sub onItemSelected()
' first button is Play
if m.top.itemSelected = 0
'START ADDING FOR PRE-ROLL
raf = Roku_Ads()
raf.setAdPrefs(false) 'disable back-filled ads
raf.setDebugOutput(true)
raf.setAdUrl("http://pubads.g.doubleclick.net/...")
adPods = raf.getAds()
shouldPlayContent = raf.showAds(adPods)
'END ADDING FOR PRE-ROLL
if shouldPlayContent
m.videoPlayer.visible = true
m.videoPlayer.setFocus(true)
m.videoPlayer.control = "play"
m.videoPlayer.observeField("state", "OnVideoPlayerStateChange")
end if
end if
End Sub
When I run this I get an error:Roku_Ads Framework version 1.8
BRIGHTSCRIPT: ERROR: roAppInfo: class PLUGIN|MARKUP on thread RENDER: roku_ads_lib:/Roku_Ads.brs(527)
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in roku_ads_lib:/Roku_Ads.brs(528)
528: ??
Backtrace:
#4 Function roku_ads_util_getappid(key_ As String) As String
file/line: roku_ads_lib:/Roku_Ads.brs(528)
#3 Function roku_ads_checkallowedfeature(keytype_ As String, util_ As Object) As Boolean
file/line: roku_ads_lib:/Roku_Ads.brs(1287)
#2 Function roku_ads_constructor() As Object
file/line: roku_ads_lib:/Roku_Ads.brs(264)
#1 Function roku_ads() As Object
file/line: roku_ads_lib:/Roku_Ads.brs(32)
#0 Function onitemselected() As Void
file/line: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(75)
What am I doing wrong here? Can you not play an ad when a method is called from a onChange="onItemSelected"
in the component.xml?
Thanks in advance