简体   繁体   中英

How to show preroll and midroll ads according to adBreaks using Roku RAF?

I am currently using Roku Advertising Framework (RAF) to show Ads. I used example and successfully connected with VAST server but at this moment I have Preroll ads only.

How can I modify or what are possibilities to read adBreaks and trigger player to show Ads in that certain moment?

sub PlayContentWithAds()
 parentNode = m.top.GetParent()
 content = m.top.content

 m.top.lastIndex = m.top.startIndex

 RAF = Roku_Ads()
 RAF.enableAdMeasurements(true)

 adServer = "https://example.adserver.com/vast.xml"

 RAF.SetAdUrl(adServer)

 keepPlay = true
 index = m.top.startIndex - 1
 itemsCount = items.Count()

 adBreaks = ["00:00:00", "00:01:00", "00:02:00"]

 while keepPlay
    ' check if playlist isn't complete
    if itemsCount - 1 > index
        parentNode.SetFocus(true)
        index ++
        item = items[index] ' contentNode of the video which should be played next
        RAF.SetContentId(item.id)

        if item.categories <> invalid
            RAF.SetContentGenre("Lifestyle")
        end if

        RAF.SetContentLength(int(item.length)) ' in seconds
        RAF.SetDebugOutput(false) 'for debug purpose

        adPods = RAF.GetAds() ' ads retrieving
        m.top.lastIndex = index ' save the index of last played item to navigate to appropriate detailsScreen
        csasStream = RAF.constructStitchedStream(item, adPods)
        keepPlay = RAF.renderStitchedStream(csasStream, parentNode)
    else
        keepPlay = false
    end if
 end while

end sub

If not mistaken, once you grab adPods using RAF.GetAds() but prior to RAF.constructStitchedStream(item, adPods) you could do something like this:

for each adPod in adPods
 adPod.renderSequence = "midroll" 
 adPod.renderTime = 5 'position where adPod/adBreak should start
end for

Best would be to configure the ad server to return response in VMAP format - which provides a list of ad pods (breaks at multiple positions) - presumably passing adBreaks in the URL query, it's more flexible that way, some ad campaigns have specific requirements like "run only in [preroll|midroll|postroll]"

Alternatively, you can construct own adPods structure, format here https://developer.roku.com/docs/developer-program/advertising/integrating-roku-advertising-framework.md#ad-structure

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM