2016-11-10 92 views
0

我試圖將VAST視頻前貼片廣告添加到SThree sample Roku SDK project(「帶視頻和詳細信息頁面(.zip)」的簡單網格)版本。在Roku中播放視頻前貼片廣告時遇到問題

我可以得到它通過把下面的代碼放在應用程序開始工作到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"調用某個方法時,您不能播放廣告嗎?

更新:尤金的answer below是正確的,這是我如何解決了這個問題:

閱讀scene graph threadseventshandling application events。完成之後,讀取this post在Render線程和主線程之間傳遞數據。您需要了解scene graph data scoping

基本上你觀察itemSelected領域components/screens/DetailsScreen/DetailsScreen.xml

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如果沒有廣告或者廣告完成比賽。這會導致onVideoVisibleChange被調用components/screens/DetailsScreen/DetailsScreen.brs

回答

1

您不能在Render線程中使用RAF。您必須將活動發送到主線程並在其中展示廣告。您可以在場景圖here中找到RAF集成的樣本。更多關於場景圖線程的信息請參見here

+0

謝謝@ eugene-smoliy,這是有道理的,高級別文檔在鏈接到的線程上也是如此。我在哪裏可以找到關於消息傳遞的文檔?從查看FullRAFSceneGraphSample看起來,主線程在事件循環中等待它們。我可以通過反覆試驗找出問題,但寧願閱讀有關主題的文檔 - 我很難找到... – rynop

+0

我發現它,https://sdkdocs.roku.com/display/sdkdoc/Handling+Application+活動我會更新這些內容,包括需要添加到SThree樣本中的內容,以便讓廣告在我運行後即可播放 – rynop

相關問題