在Roku中播放vid前置广告时出现问题 [英] Trouble playing vid pre-roll ad in Roku

查看:118
本文介绍了在Roku中播放vid前置广告时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将VAST视频前置广告添加到

通过将以下代码放入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"调用方法时,您不能播放广告吗?

更新:以下是Eugene的答案是正确的,这是我解决问题的方法:

了解有关场景图线程处理应用程序事件.完成此操作后,请阅读这篇文章在渲染"线程和主线程之间传递数据时.您将需要了解场景图数据范围.

基本上,您会观察components/screens/DetailsScreen/DetailsScreen.xml中的itemSelected字段:

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.这导致onVideoVisibleChangecomponents/screens/DetailsScreen/DetailsScreen.brs

中被调用

解决方案

您不能在Render线程中使用RAF.您必须将事件发送到主线程并在其中显示广告.您可以在场景图的此处中找到RAF集成的示例.可以在此处找到有关场景图中线程的更多信息.. >

I'm trying to add VAST video pre-roll ads to the SThree sample Roku SDK project (the "Simple Grid with Video and Details page (.zip)" version).

I can get it to work on app start by putting the following code into 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)

I however don't want to play an ad on startup, I want to play an ad before a video play. So I figure I can just add the lines above to 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

When I run this I get an error:

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)

What am I doing wrong here? Can you not play an ad when a method is called from a onChange="onItemSelected" in the component.xml?

Update: Eugene's answer below is correct, Here is how I solved the problem:

Read about scene graph threads, events and handling application events. Once that is done read this post on passing data between the Render thread and main thread. You will need to understand scene graph data scoping.

Essentially you observe the itemSelected field in components/screens/DetailsScreen/DetailsScreen.xml:

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

Then in your main threads event loop you handle the 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() sets m.DetailsScreen.videoPlayerVisible = true IF there was no ad or if ad finished playing. This causes onVideoVisibleChange to be invoked in components/screens/DetailsScreen/DetailsScreen.brs

解决方案

You can't use RAF in Render thread. You have to send event to the Main thread and and show ads there. You can find samples of RAF integration in Scene Graph here. More info on threads in Scene Graph can be found here.

这篇关于在Roku中播放vid前置广告时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆