I am currently using Eclipse IDE with the Roku Developer Plugin to create a channel. I have experience in programming and code but brightscript has been a little more difficult for me to find my comfort with.
I have successfully created a channel that streams sufficiently. What I'm trying to do now is test the inclusion of RAF. I have tried looking through the code of an existing RAF template along with my current working streaming program.
Unfortunately the calls and variable names are different enough, and my ignorance is high enough I'm struggling to connect some dots. As I included the RAF library and code, or the code I thought I needed, the video no longer plays when I press the play button. The channel loads and the preview/details load just when I press play it does nothing.
Here is the code for that section of code on the page.
Sub onItemSelected()
' first button is Play
if m.top.itemSelected = 0
m.videoPlayer = CreateObject("roSGNode", "Video")
m.videoPlayer.id="videoPlayer"
m.videoPlayer.translation="[0, 0]"
m.videoPlayer.width="1280"
m.videoPlayer.height="720"
m.videoPlayer.content = m.top.content
'show video player
m.top.AppendChild(m.videoPlayer)
m.videoPlayer.visible = true
m.videoPlayer.setFocus(true)
m.videoPlayer.control = "play"
m.videoPlayer.observeField("state", "OnVideoPlayerStateChange")
m.videoPlayer.observeField("visible", "onVideoVisibleChange")
'THIS IS THE CODE I ADDED FROM THE RAF EXAMPLE
'EVERYTHING IN BELOW THIS UNTIL THE END OF THE
'SUB IF REMOVED THE VIDEO PLAYS.
'--------------------------------------------------------------------------------
adIface = Roku_Ads() 'RAF initialize
print "Roku_Ads library version: " + adIface.getLibVersion()
adIface.setDebugOutput(true) 'for debug pupropse
'Indicates whether the default Roku backfill ad service URL
'should be used in case the client-configured URL fails (2 retries)
'to return any renderable ads.
adIface.setAdPrefs(true, 2)
' Normally, would set publisher's ad URL here. Uncomment following line to do so.
' adIface.setAdUrl(m.videoContent.adUrl)
' Otherwise uses default Roku ad server (with single preroll placeholder ad)
'Returns available ad pod(s) scheduled for rendering or invalid, if none are available.
adPods = adIface.getAds()
playContent = true
'render pre-roll ads
if adPods <> invalid and adPods.count() > 0 then
playContent = adIface.showAds(adPods)
endif
while(true)
msg = wait(0, m.port)
msgType = type(msg)
if msgType = "roSGScreenEvent"
if msg.isScreenClosed() then return
else if msgType = "roSGNodeEvent"
if (msg.GetNode() = "DetailsScreen")
if msg.GetField() = "position" then
'render mid-roll ads
curPos = m.video.position
videoEvent = createPlayPosMsg(curPos)
adPods = adIface.getAds(videoEvent)
if adPods <> invalid and adPods.count() > 0
m.video.control = "stop"
playContent = adIface.showAds(adPods)
if playContent then
m.video.seek = curPos
m.video.control = "play"
endif
endif
else if msg.GetField() = "state" then
curState = m.video.state
if curState = "finished" then
'render post-roll ads
videoEvent = createPlayPosMsg(curPos, true)
adPods = adIface.getAds(videoEvent)
m.video.control = "stop"
if adPods <> invalid and adPods.count() > 0
adIface.showAds(adPods)
end if
exit while
endif
else if msg.GetField() = "navBack" then
'back button handling
if msg.GetData() = true then
m.video.control = "stop"
exit while
endif
end if
end if
end if
end while
'----------------------------------------------------------------------
'THIS IS THE END OF THE RAF CODE I INSERTED INTO THE VIDEO TEMPLATE.
end if
End Sub
On Eclipse it gives me an error that I have tried researching and figuring out but as I mentioned I'm stuck.
Current Function:
086: m.videoPlayer.control = "play"
087: m.videoPlayer.observeField("state", "OnVideoPlayerStateChange")
088: m.videoPlayer.observeField("visible", "onVideoVisibleChange")
089:
090: 'THIS IS THE CODE I ADDED FROM THE RAF EXAMPLE
091: 'EVERYTHING IN BELOW THIS UNTIL THE END OF THE
092: 'SUB IF REMOVED THE VIDEO PLAYS.
093: '--------------------------------------------------------------------------------
094:* adIface = Roku_Ads() 'RAF initialize
095: print "Roku_Ads library version: " + adIface.getLibVersion()
096:
097: adIface.setDebugOutput(true) 'for debug pupropse
098:
Function Call Operator ( ) attempted on non-function. (runtime error &he0) in pkg:/components/screens/DetailsScreen/DetailsScreen.brs(94)
094: adIface = Roku_Ads() 'RAF initialize
Backtrace:
#0 Function onitemselected() As Void
file/line: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(94)
Local Variables:
global Interface:ifGlobal
m roAssociativeArray refcnt=2 count:7
adiface <uninitialized>
adpods <uninitialized>
playcontent <uninitialized>
msg <uninitialized>
msgtype <uninitialized>
curpos <uninitialized>
videoevent <uninitialized>
curstate <uninitialized>
roku_ads <uninitialized>
createplayposmsg <uninitialized>
Threads:
ID Location Source Code
0 pkg:/source/main.brs(34) msg = wait(0, port)
1* ...ailsScreen/DetailsScreen.brs(94) adIface = Roku_Ads() 'RAF initialize
*selected
Brightscript Debugger>
I'm hoping to narrow down how to modify my channel to make this work. I did leave out this code:
'RAF content params
adIface.setContentId(m.videoContent.contentId)
adIface.SetContentGenre(m.videoContent.contentGenre)
'Nielsen content params
adIface.enableNielsenDAR(true)
adIface.setContentLength(m.videoContent.conntentLength)
adIface.setNielsenProgramId(m.videoContent.nielsenProgramId)
adIface.setNielsenGenre(m.videoContent.nielsenGenre)
adIface.setNielsenAppId(m.videoContent.nielsenAppId)
Didnt want to work with Nielson stuff yet but not sure if I need to include it to make RAF work.
Thank you for your time, truly.
Also note you cannot invoke RAF from a render thread - which will be the next issue, looking at your code. It should either be done from the main thread or from a task thread (see https://github.com/rokudev/RAF4RSG-sample ).