Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
gsarath
Visitor

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:
https://sdkdocs.roku.com/display/sdkdoc ... leChannels
https://sdkdocs.roku.com/download/attac ... 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()
    playVideo()
End Sub

Function playVideo()
    screen = CreateObject("roSGScreen")
    m.port = CreateObject("roMessagePort")
    screen.setMessagePort(m.port)
    scene = screen.CreateScene("videobannerScene")
    screen.show()
    while(true)
        msg = wait(0, m.port)
        msgType = type(msg)
        if msgType = "roSGScreenEvent"
            if msg.isScreenClosed()
                exit while
            endif
        endif
    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" >
<![CDATA[

sub init()
    initializeTask()
   setVideo()
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 = "https://roku.s.cpl.delvenetworks.com/media/59021fabe3b645968e382ac726cd6c7b/60b4a471ffb74809beb2f7d5a15b3193/roku_ep_111_segment_1_final-cc_mix_033015-a7ec8a288c4bcec001c118181c668de321108861.m3u8"
   videoContent.title = "Closed Captions in Scene Graph"
   videoContent.streamformat = "hls"

   m.video = m.top.findNode("musicvideos")
   m.video.content = videoContent
   m.video.notificationinterval = 1

   m.video.setFocus(true)
   m.video.control = "play"
end function

]]>
</script>

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


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

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

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:
https://sdkdocs.roku.com/display/sdkdoc ... plications
0 Kudos
1 REPLY 1
TheEndless
Channel Surfer

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: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.