Im working on getting my channel to run with ads
' ********** Copyright 2016 Roku Corp. All Rights Reserved. ********** ' 1st function that runs for the scene component on channel startup sub init() 'To see print statements/debug info, telnet on port 8089 m.Image = m.top.findNode("Image") m.Details = m.top.findNode("Details") m.Title = m.top.findNode("Title") m.Video = m.top.findNode("Video") m.SpringDetails = m.top.findNode("SpringBoardDetails") m.LabelList = m.top.findNode("LabelList") m.CategoryLabel = m.top.findNode("CategoryLabel") m.RuntimeLabel = m.top.findNode("RuntimeLabel") m.Video.ObserveField("state","OnVideoPlayerStateChange") m.Title.font.size = 40 m.CategoryLabel.color = "#333333" m.Title.color = "#333333" m.Details.color = "#444444" m.RuntimeLabel.color = "#333333" end sub ' set proper focus to buttons if Details opened and stops Video if Details closed Sub onVisibleChange() ? "[DetailsScreen] onVisibleChange" if m.top.visible = true then m.buttons.jumpToItem = 0 m.buttons.setFocus(true) else if m.videoPlayer <> invalid m.videoPlayer.visible = false m.videoPlayer.control = "stop" m.poster.uri="" m.background.uri="" end if End Sub ' set proper focus to Buttons in case if return from Video PLayer Sub OnFocusedChildChange() if m.top.isInFocusChain() and not m.buttons.hasFocus() and not m.videoPlayer.hasFocus() then m.buttons.setFocus(true) end if End Sub ' set proper focus on buttons and stops video if return from Playback to details Sub onVideoVisibleChange() if m.videoPlayer.visible = false and m.top.visible = true m.buttons.setFocus(true) m.videoPlayer.control = "stop" 'clear video player content, for proper start of next video player m.videoPlayer.content = invalid 'remove video player m.top.removeChild(m.videoPlayer) end if End Sub ' event handler of Video player msg Sub OnVideoPlayerStateChange() if m.videoPlayer.state = "error" ' error handling m.videoPlayer.visible = false else if m.videoPlayer.state = "playing" ' playback handling playContent() else if m.videoPlayer.state = "finished" m.videoPlayer.visible = false end if End Sub sub playContent() content = m.buttons.content if content <> invalid then m.video.content = content m.video.visible = false m.PlayerTask = CreateObject("roSGNode", "PlayerTask") m.PlayerTask.observeField("state", "taskStateChanged") m.PlayerTask.video = m.video m.PlayerTask.control = "RUN" end if end sub sub taskStateChanged(event as Object) print "Player: taskStateChanged(), id = "; event.getNode(); ", "; event.getField(); " = "; event.getData() state = event.GetData() if state = "done" or state = "stop" exitPlayer() end if end sub ' on Button press handler 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") end if End Sub ' Content change handler Sub OnContentChange() m.description.content = m.top.content m.description.Description.width = "770" m.poster.uri = m.top.content.hdBackgroundImageUrl m.background.uri = m.top.content.hdBackgroundImageUrl End Sub '///////////////////////////////////////////' ' Helper function convert AA to Node Function ContentList2SimpleNode(contentList as Object, nodeType = "ContentNode" as String) as Object result = createObject("roSGNode",nodeType) if result <> invalid for each itemAA in contentList item = createObject("roSGNode", nodeType) item.setFields(itemAA) result.appendChild(item) end for end if return result End Function Function OnkeyEvent(key, press) as Boolean ? ">>> Details >> OnkeyEvent" result = false if press AND key = "back" AND m.videoPlayer <> invalid AND m.videoPlayer.visible m.videoPlayer.visible = false result = true end if return result End Function
Yet I keep getting these errors
Invalid value for left-side of expression. (runtime error &he4) in pkg:/components/SpringBoard.brs(117) 117: m.description.content = m.top.content
It looks like you have overlooked defining `
m.description
probably in the init() you need to add
m.description = m.top.findNode("description")
I managed to get around it
' ********** Copyright 2016 Roku Corp. All Rights Reserved. ********** ' 1st function that runs for the scene component on channel startup sub init() 'To see print statements/debug info, telnet on port 8089 m.Image = m.top.findNode("Image") m.Details = m.top.findNode("Details") m.Title = m.top.findNode("Title") m.Video = m.top.findNode("Video") m.SpringDetails = m.top.findNode("SpringBoardDetails") m.LabelList = m.top.findNode("LabelList") m.CategoryLabel = m.top.findNode("CategoryLabel") m.RuntimeLabel = m.top.findNode("RuntimeLabel") m.Video.ObserveField("state","OnVideoPlayerStateChange") m.Title.font.size = 40 m.CategoryLabel.color = "#333333" m.Title.color = "#333333" m.Details.color = "#444444" m.RuntimeLabel.color = "#333333" end sub Sub OnVideoPlayerStateChange() print "SpringBoard.brs - [OnVideoPlayerStateChange]" if m.Video.state = "error" ' error handling m.Video.visible = false else if m.Video.state = "playing" ' playback handling else if m.Video.state = "finished" m.video.visible = false m.SpringDetails.Visible=true m.LabelList.setFocus(true) end if End Sub sub onContentChange(event as object) print "onContentChange" content = event.getdata() runtime = content.shortdescriptionline2.toInt() minutes = runtime \ 60 seconds = runtime MOD 60 m.Image.uri = content.hdposterurl m.Title.text = content.title m.Details.text = content.description x = m.Details.localBoundingRect() m.RuntimeLabel.text = "Length: " + minutes.toStr() + " minutes " + seconds.toStr() + " seconds" translation = [m.RuntimeLabel.translation[0], m.Details.translation[1] + x.height + 30] m.RuntimeLabel.translation = translation m.CategoryLabel.text = content.categories ContentNode = CreateObject("roSGNode", "ContentNode") ContentNode.streamFormat = content.streamformat ContentNode.url = content.url ContentNode.Title = content.title ContentNode.Description = content.Description ContentNode.ShortDescriptionLine1 = content.title ContentNode.StarRating = 80 ContentNode.Length = 1972 ContentNode.subtitleConfig = {Trackname: "pkg:/source/CraigVenter.srt" } m.Video.content = ContentNode end sub sub onItemSelected(event as object) print "onItemSelected" m.Video.control = "play" if event.getData() <> 0 then m.Video.seek = m.top.seekposition m.SpringDetails.visible = false m.Video.visible = true m.Video.setFocus(true) end sub ' Called when a key on the remote is pressed function onKeyEvent(key as String, press as Boolean) as Boolean print "in SimpleVideoScene.xml onKeyEvent ";key;" "; press if press then if key = "back" print "------ [back pressed] ------" if m.Video.visible m.Video.control = "pause" m.Video.visible = false m.SpringDetails.visible = true position = m.Video.position if position > 0 if m.LabelList.content.getChildCount() > 1 then m.LabelList.content.removeChildIndex(1) minutes = position \ 60 seconds = position MOD 60 contentNode = createObject("roSGNode","ContentNode") contentNode.title = "Resume Video (" + minutes.toStr() + " min " + seconds.toStr() + " sec)" m.LabelList.content.appendChild(contentNode) 'Write position to registry so that re-opening the channel works m.global.registryTask.write = { contentid: m.top.content.episodenumber, position: position.toStr() } m.top.seekposition = position else print "Do nothing" end if m.LabelList.setFocus(true) return true else return false end if else if key = "OK" print "------- [ok pressed] -------" else return false end if end if return false end function
It wont show the ad as it was stuck on the retrieving screen so I checked what's wrong with it and this error popped up
Interface not a member of BrightScript Component (runtime error &hf3) in pkg:/components/SpringBoard.brs(46)
Assuming that line 46 is
m.Details.text = content.description
Then I'm going to suggest you pay attention to my earlier reply. good luck.
I added it on this code
' ********** Copyright 2016 Roku Corp. All Rights Reserved. ********** ' inits details screen ' sets all observers ' configures buttons for Details screen Function Init() ? "[DetailsScreen] init" m.top.observeField("visible", "onVisibleChange") m.top.observeField("focusedChild", "OnFocusedChildChange") m.buttons = m.top.findNode("Buttons") m.Player = m.top.findNode("VideoPlayer") m.poster = m.top.findNode("Poster") m.description = m.top.findNode("Description") m.background = m.top.findNode("Background") ' create buttons result = [] for each button in ["Play"] result.push({title : button}) end for m.buttons.content = ContentList2SimpleNode(result) End Function ' set proper focus to buttons if Details opened and stops Video if Details closed Sub onVisibleChange() ? "[DetailsScreen] onVisibleChange" if m.top.visible = true then m.buttons.jumpToItem = 0 m.buttons.setFocus(true) else m.Player.visible = false m.Player.control = "stop" m.poster.uri="" m.background.uri="" end if End Sub ' set proper focus to Buttons in case if return from Video PLayer Sub OnFocusedChildChange() if m.top.isInFocusChain() and not m.buttons.hasFocus() and not m.Player.hasFocus() then m.buttons.setFocus(true) end if End Sub ' set proper focus on buttons and stops video if return from Playback to details Sub onVideoVisibleChange() if m.Player.visible = false and m.top.visible = true m.buttons.setFocus(true) m.Player.control = "stop" end if End Sub ' event handler of Video player msg Sub OnVideoPlayerStateChange() if m.Player.state = "error" ' error handling m.Player.visible = false else if m.Player.state = "playing" playContent() ' playback handling else if m.Player.state = "finished" m.Player.visible = false end if End Sub sub playContent() content = m.buttons.content if content <> invalid then m.video.content = content m.video.visible = false m.PlayerTask = CreateObject("roSGNode", "PlayerTask") m.PlayerTask.observeField("state", "taskStateChanged") m.PlayerTask.video = m.video m.PlayerTask.control = "RUN" end if end sub ' on Button press handler Sub onItemSelected() ' first button is Play if m.top.itemSelected = 0 m.Player = CreateObject("roSGNode", "Video") m.Player.id="videoPlayer" m.Player.translation="[0, 0]" m.Player.width="1280" m.Player.height="720" m.Player.content = m.top.content 'show video player m.top.AppendChild(m.videoPlayer) m.Player.visible = true m.Player.setFocus(true) m.Player.control = "play" m.Player.observeField("state", "OnVideoPlayerStateChange") m.Player.observeField("visible", "onVideoVisibleChange") end if End Sub ' Content change handler Sub OnContentChange() m.description.content = m.top.content m.description.Description.width = "770" m.Player.content = m.top.content m.top.streamUrl = m.top.content.url m.poster.uri = m.top.content.hdBackgroundImageUrl m.background.uri = m.top.content.hdBackgroundImageUrl End Sub '///////////////////////////////////////////' ' Helper function convert AA to Node Function ContentList2SimpleNode(contentList as Object, nodeType = "ContentNode" as String) as Object result = createObject("roSGNode",nodeType) if result <> invalid for each itemAA in contentList item = createObject("roSGNode", nodeType) item.setFields(itemAA) result.appendChild(item) end for end if return result End Function
I keep geting this error
Current Function: 070: sub playContent() 071: content = m.buttons.content 072: if content <> invalid then 073:* m.video.content = content 074: m.video.visible = false 075: 076: m.PlayerTask = CreateObject("roSGNode", "PlayerTask") 077: m.PlayerTask.observeField("state", "taskStateChanged") Invalid value for left-side of expression. (runtime error &he4) in pkg:/components/screens/DetailsScreen/DetailsScreen.brs(73) 073: m.video.content = content
I fixed that problem by reworking PlayerTask
Library "Roku_Ads.brs" sub init() m.top.functionName = "playContentWithAds" m.top.id = "PlayerTask" end sub sub playContentWithAds() ' `view` is the node under which RAF should display its UI (passed as 3rd argument of showAds()) view = videoPlayer.getParent() RAF = Roku_Ads() 'RAF.clearAdBufferScreenLayers() ' in case it was set earlier 'RAF.enableAdBufferMessaging(true, true) ' could have been cleared by custom screen 'RAF.setAdBufferScreenContent({}) content = video.content RAF.setAdUrl(content.ad_url) ' for generic measurements api RAF.enableAdMeasurements(true) RAF.setContentGenre(content.categories) 'if unset, ContentNode has it as [] RAF.setContentLength(content.length) ' log tracking events ' logObj = { ' log : Function(evtType = invalid as Dynamic, ctx = invalid as Dynamic) ' if GetInterface(evtType, "ifString") <> invalid ' print "*** tracking event " + evtType + " fired." ' if ctx.companion = true then ' print "***** companion = true" ' end if ' if ctx.errMsg <> invalid then print "***** Error message: " + ctx.errMsg ' if ctx.adIndex <> invalid then print "***** Ad Index: " + ctx.adIndex.ToStr() ' if ctx.ad <> invalid and ctx.ad.adTitle <> invalid then print "***** Ad Title: " + ctx.ad.adTitle ' else if ctx <> invalid and ctx.time <> invalid ' print "*** checking tracking events for ad progress: " + ctx.time.ToStr() ' end if ' End Function ' } ' logFunc = Function(obj = Invalid as Dynamic, evtType = invalid as Dynamic, ctx = invalid as Dynamic) ' obj.log(evtType, ctx) ' End Function ' RAF.setTrackingCallback(logFunc, logObj) adPods = RAF.getAds() 'array of ad pods keepPlaying = true 'gets set to `false` when showAds() was exited via Back button ' show the pre-roll ads, if any if adPods <> invalid and adPods.count() > 0 keepPlaying = RAF.showAds(adPods, invalid, view) end if port = CreateObject("roMessagePort") if keepPlaying then videoPlayer.observeField("position", port) videoPlayer.observeField("state", port) videoPlayer.visible = true videoPlayer.control = "play" videoPlayer.setFocus(true) 'so we can handle a Back key interruption end if curPos = 0 adPods = invalid isPlayingPostroll = false while keepPlaying msg = wait(0, port) if type(msg) = "roSGNodeEvent" if msg.GetField() = "position" then ' keep track of where we reached in content curPos = msg.GetData() ' check for mid-roll ads adPods = RAF.getAds(msg) 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 videoPlayer.control = "stop" end if else if msg.GetField() = "state" then curState = msg.GetData() print "PlayerTask: state = "; curState if curState = "stopped" then if adPods = invalid or adPods.count() = 0 then exit while end if print "PlayerTask: playing midroll/postroll ads" keepPlaying = RAF.showAds(adPods, invalid, view) adPods = invalid if isPlayingPostroll then exit while end if if keepPlaying then print "PlayerTask: mid-roll finished, seek to "; stri(curPos) videoPlayer.visible = true videoPlayer.seek = curPos videoPlayer.control = "play" videoPlayer.setFocus(true) 'important: take the focus back (RAF took it above) end if else if curState = "finished" then print "PlayerTask: main content finished" ' render post-roll ads adPods = RAF.getAds(msg) if adPods = invalid or adPods.count() = 0 then exit while end if print "PlayerTask: has postroll ads" isPlayingPostroll = true ' stop the video, the post-roll would show when the state changes to "stopped" (above) videoPlayer.control = "stop" end if end if end if end while print "PlayerTask: exiting playContentWithAds()" end sub
Now I got this problem
016: sub playContentWithAds() 017: 018: 019: ' `view` is the node under which RAF should display its UI (passed as 3rd argument of showAds()) 020:* view = videoPlayer.getParent() 021: 022: RAF = Roku_Ads() 023: 'RAF.clearAdBufferScreenLayers() ' in case it was set earlier 024: 'RAF.enableAdBufferMessaging(true, true) ' could have been cleared by custom screen 'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in pkg:/components/PlayerTask.brs(20) 020: view = videoPlayer.getParent() Backtrace: #0 Function playcontentwithads() As Void file/line: pkg:/components/PlayerTask.brs(20)
We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. Read more here.
Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 19th and you may notice reduced functionality.
In the meantime, for additional assistance, visit our Support Site.
We're sorry for this disruption — we’re excited to share what’s next!