2016-11-10 5 views
0

VASTビデオプレロール広告をSThree sample Roku SDK projectに追加しようとしています(「ビデオと詳細ページ(.zip)付きのシンプルグリッド」バージョン)。RokuでVidプレロール広告を再生できない

私はそれがmain.brsに次のコードを置くことで、アプリの起動時に動作するように取得することができます。

library "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/gampad/ads?slotname=/82114269/Video/fallbacktest&sz=1920x1080&url=[http://roku.com&unviewed_position_start=1&output=vast&impl=s&env=vp&gdfp_req=1&ad_rule=0&description_url=http%3A%2F%2Fapps.roku.com&vad_type=linear&sdkv=roku&min_ad_duration=0&max_ad_duration=60000&rdid=ROKU_ADS_TRACKING_ID&is_lat=ROKU_ADS_LIMIT_TRACKING&idtype=rida&correlator=ROKU_ADS_TIMESTAMP&scor=ROKU_ADS_TIMESTAMP&pod=POD_NUM&ppos=POD_POSITION&cust_params=genre%3DROKU_ADS_CONTENT_GENRE%26ua%3DROKU_ADS_USER_AGENT%26ai%3DROKU_ADS_APP_ID]http://roku.com&unviewed_position_start=1&output=vast&impl=s&env=vp&gdfp_req=1&ad_rule=0&description_url=http%3A%2F%2Fapps.roku.com&vad_type=linear&sdkv=roku&min_ad_duration=0&max_ad_duration=60000&rdid=ROKU_ADS_TRACKING_ID&is_lat=ROKU_ADS_LIMIT_TRACKING&idtype=rida&correlator=ROKU_ADS_TIMESTAMP&scor=ROKU_ADS_TIMESTAMP&pod=POD_NUM&ppos=POD_POSITION&cust_params=genre%3DROKU_ADS_CONTENT_GENRE%26ua%3DROKU_ADS_USER_AGENT%26ai%3DROKU_ADS_APP_ID") 
    adPods = raf.getAds() 
    shouldPlayContent = raf.showAds(adPods) 

は、しかし私は、起動時に広告を再生したくない、私は動画の前に広告を再生したいです遊びます。だから私は、私はちょうど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/gampad/ads?slotname=/82114269/Video/fallbacktest&sz=1920x1080&url=[http://roku.com&unviewed_position_start=1&output=vast&impl=s&env=vp&gdfp_req=1&ad_rule=0&description_url=http%3A%2F%2Fapps.roku.com&vad_type=linear&sdkv=roku&min_ad_duration=0&max_ad_duration=60000&rdid=ROKU_ADS_TRACKING_ID&is_lat=ROKU_ADS_LIMIT_TRACKING&idtype=rida&correlator=ROKU_ADS_TIMESTAMP&scor=ROKU_ADS_TIMESTAMP&pod=POD_NUM&ppos=POD_POSITION&cust_params=genre%3DROKU_ADS_CONTENT_GENRE%26ua%3DROKU_ADS_USER_AGENT%26ai%3DROKU_ADS_APP_ID]http://roku.com&unviewed_position_start=1&output=vast&impl=s&env=vp&gdfp_req=1&ad_rule=0&description_url=http%3A%2F%2Fapps.roku.com&vad_type=linear&sdkv=roku&min_ad_duration=0&max_ad_duration=60000&rdid=ROKU_ADS_TRACKING_ID&is_lat=ROKU_ADS_LIMIT_TRACKING&idtype=rida&correlator=ROKU_ADS_TIMESTAMP&scor=ROKU_ADS_TIMESTAMP&pod=POD_NUM&ppos=POD_POSITION&cust_params=genre%3DROKU_ADS_CONTENT_GENRE%26ua%3DROKU_ADS_USER_AGENT%26ai%3DROKU_ADS_APP_ID") 
     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 

私はこれを実行すると、私はエラーを取得する:

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) 

は、私はここで間違って何をしているのですか? component.xmlのonChange="onItemSelected"からメソッドが呼び出されたときに広告を再生できませんか?

更新

scene graph threadseventshandling application eventsを読む:ユージンのanswer belowはここで、正しいことは、私はこの問題を解決する方法です。それが完了したら、this postをレンダリングスレッドとメインスレッドの間で渡してください。 scene graph data scopingを理解する必要があります。

基本的にあなたがcomponents/screens/DetailsScreen/DetailsScreen.xmlitemSelected場を守ってください。

m.DetailsScreen = scene.findNode("DetailsScreen") 
m.DetailsScreen.observeField("itemSelected", m.port) 

次にあなたがroSGNodeEventを扱うあなたのメインスレッドのイベントループに:

while true 
    msg = wait(0, m.port)   
    msgType = type(msg) 

    ? ">>>Main Thread Msg: ";msgType 

    if msgType = "roSGScreenEvent" 
     if msg.isScreenClosed() then return 
    else if msgType = "roSGNodeEvent" 
     fieldName = msg.getField() 
     fieldData = msg.getData() 
     ? "> node: "; msg.getNode() 
     ? "> field name: "; fieldName 
     ? "> data: "; fieldData 

     if (fieldName = "itemSelected" and fieldData = 0) 'User pressed play 
      'wait for 0.5 second before proceeding to RAF 
      sleep(500) 
      PlayAd() 
     endif 
    end if 
end while 

PlayAd()セットm.DetailsScreen.videoPlayerVisible = true何の広告や広告場合はなかったのIF演奏を終えた。これによりonVideoVisibleChangeが呼び出されますcomponents/screens/DetailsScreen/DetailsScreen.brs

答えて

1

レンダリングスレッドでRAFを使用することはできません。メインスレッドにイベントを送信し、そこに広告を表示する必要があります。 RAF統合のサンプルは、シーングラフhereにあります。シーングラフのスレッドの詳細については、hereを参照してください。

+0

おかげさまで@ eugene-smoliy、それは理にかなっており、あなたがリンクしているスレッドの高レベルのドキュメントもそうです。メッセージの受け渡しに関するドキュメントはどこにありますか? FullRAFSceneGraphSampleを見てみると、イベントループのメインスレッド待機のように見えます。私は試行錯誤を経て問題を理解することができますが、トピックに関するドキュメントを読むことになります。これは問題が見つかっていません。 – rynop

+0

私はそれを見つけました。https://sdkdocs.roku.com/display/sdkdoc/Handling+Application+イベント私はこれを更新して、SThreeサンプルに追加する必要があるものを更新して、広告を再生してから動作させます – rynop

関連する問題