Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 7

Integrating Ad Framework for Scene Graph in Components

Need confirmation/information from anyone whether we can "Integrate ads in Scene Graph Complements instead of Bright Script?"

The example shared in Roku Documentation covers only integrating ads in Brightscript Main Thread: ... leChannels ... 119&api=v2

I figured that showAds() cannot be used inside Screen Graph Rendered Thread or Task Node Thread as I have observed error in both the scenarios:
roImageCanvas: class PLUGIN on thread RENDER|MARKUP: roku_ads_lib:/Roku_Ads.brs(2614)

Below mentioned is the code of the Sample Application - appMain.brs, VideoScene.xml and AdTask.xml:
Sub Main()
End Sub

Function playVideo()
    screen = CreateObject("roSGScreen")
    m.port = CreateObject("roMessagePort")
    scene = screen.CreateScene("videobannerScene")
        msg = wait(0, m.port)
        msgType = type(msg)
        if msgType = "roSGScreenEvent"
            if msg.isScreenClosed()
                exit while
    end while
End Function

<?xml version="1.0" encoding="utf-8" ?> 

<!--********** Copyright 2015 Roku Corp.  All Rights Reserved. **********-->

<component name="videobannerScene" extends="Scene" >

<script type="text/brightscript" >

sub init()
end sub

function initializeTask()
    m.adTask = CreateObject("roSGNode", "AdTask")
    m.adTask.control = "RUN"    
end function

function setVideo() as void    
   videoContent = createObject("RoSGNode", "ContentNode")
   videoContent.url = ""
   videoContent.title = "Closed Captions in Scene Graph"
   videoContent.streamformat = "hls" ="musicvideos") = videoContent = 1 = "play"
end function


    <Video id="musicvideos" width="1280" height="720" translation="[0,0]" />

<?xml version="1.0" encoding="utf-8" ?> 
<component name="AdTask" extends="Task" >
<script type="text/brightscript" >
Library "Roku_Ads.brs"
sub init() = "initAds"
end sub

function initAds()
   adIface = Roku_Ads()
   adUrl = "file://pkg:/images/ads.xml"
   ads = adIface.getAds()
    if ads <> invalid and ads.count() > 0
        For Each adPod In ads
           if adPod["rendersequence"] = "preroll"
           end if
       End For
   end if 
end function

FYI: I am able view traces of Brightscript Main Thread in 8085, Render Scene Graph Thread in 8089 and Task Node Thread in 8090 as mentioned in the post: ... plications
0 Kudos
1 REPLY 1\
Level 10

Re: Integrating Ad Framework for Scene Graph in Components

Unfortunately, as the examples indicate, RAF can only integrate with SceneGraph via the main B/S thread, if you want to use the default ad renderer.  You could potentially write your own custom ad renderer that uses native SceneGraph components for video playback, but I'm not sure if it's worth the effort.  Hopefully Roku is working on a native SceneGraph RAF component, particularly since they're requiring its use and are heavily pushing SceneGraph development.
My Channels: - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos