"Blackhawk" wrote:
Like this?
RAF = Roku_Ads()
adPods = RAF.getAds()
is_finished_ok = RAF.showAds(adPods)
Library "Roku_Ads.brs"
Function CreateLiveFeed() as integer
'AA for base video, ad and Nielsen configuration.
'For additional information please see official RAF documentation.
videoContent = {
streamFormat : "hls",
'Lengthy (17 min.) TED talk to allow time for testing ad pods
stream: {
url: "https://livestream.com/accounts/16944724/DetroitAutoShow.hls",
bitrate: 800,
quality: false
}
}
PlayContentWithFullRAFIntegration(videoContent)
End Function
'A full RAF integration Example:
' - Include RAF.
' - setAdURL to set the ad URL.
' - Examples of RAF MACROS being passed in the ad call.
' - getAds() for VAST parsing.
' - showAds for rendering.
' - Enable Nielsen.
' - Pass all parameters to Nielsen beacons with examples of genre, program id and content.
'@param videoContent [AA] object that has valid data for playing video with roVideoScreen.
Sub PlayContentWithFullRAFIntegration(videoContent as Object)
'Main facade creation.
canvas = CreateObject("roImageCanvas")
canvas.SetLayer(1, {color: "#000000"})
canvas.SetLayer(2, {text: "Loading..."})
canvas.Show()
RAF = Roku_Ads()'RAF initialize
print "Roku_Ads library version: " + RAF.getLibVersion()
RAF.setDebugOutput(true) 'for debug pupropse
'RAF content params
RAF.setContentId(videoContent.contentId)
RAF.SetContentGenre(videoContent.contentGenre)
'Indicates whether the default Roku backfill ad service URL
'should be used in case the client-configured URL fails (2 retries)
'to return any renderable ads.
RAF.setAdPrefs(true, 2)
adPods = RAF.getAds()
is_finished_ok = RAF.showAds(adPods)
curPos = 0
if playContent
videoScreen = PlayVideoContent(videoContent)
end if
closingContentScreen = false
contentDone = false
while playContent
videoMsg = wait(0, videoScreen.GetMessagePort())
if type(videoMsg) = "roVideoScreenEvent"
if videoMsg.isStreamStarted()
canvas.ClearLayer(2)
end if
if videoMsg.isPlaybackPosition()
'cache current playback position for resume after midroll ads
curPos = videoMsg.GetIndex()
end if
if not closingContentScreen 'don't check for any more ads while waiting for screen close
if videoMsg.isScreenClosed() 'roVideoScreen sends this message last for all exit conditions
playContent = false
else if videoMsg.isFullResult()
contentDone = true 'don't want to resume playback after postroll ads
end if
'check for midroll/postroll ad pods
adPods = RAF.getAds(videoMsg)
if adPods <> invalid and adPods.Count() > 0
'must completely close content screen before showing ads
'for some Roku platforms (e.g., RokuTV), calling Close() will not synchronously
'close the media player and may prevent a new media player from being created
'until the screen is fully closed (app has received the isScreenClosed() event)
videoScreen.Close()
closingContentScreen = true
end if
else if videoMsg.isScreenClosed()
closingContentScreen = false 'now safe to render ads
end if 'closingContentScreen
if not closingContentScreen and adPods <> invalid and adPods.Count() > 0
'now safe to render midroll/postroll ads
playContent = RAF.showAds(adPods)
playContent = playContent and not contentDone
if playContent
'resume video playback after midroll ads
videoContent.PlayStart = curPos
videoScreen = PlayVideoContent(videoContent)
end if
end if '!closingContentScreen
end if 'roVideoScreenEvent
end while
if type(videoScreen) = "roVideoScreen" then videoScreen.Close()
End Sub
'Creation and configuration of video screen.
'@param content [AA] object that has valid data for playing video with roVideoScreen
'@returns [roVideoScreen] video screen object
Function PlayVideoContent(content as Object) as Object
' roVideoScreen just closes if you try to resume or seek after ad playback,
' so just create a new instance of the screen...
videoScreen = CreateObject("roVideoScreen")
videoScreen.SetContent(content)
' need a reasonable notification period set if midroll/postroll ads are to be
' rendered at an appropriate time
videoScreen.SetPositionNotificationPeriod(1)
videoScreen.SetMessagePort(CreateObject("roMessagePort"))
videoScreen.Show()
return videoScreen
End Function
Library "Roku_Ads.brs"
Function CreateLiveFeed() as integer
'AA for base video, ad and Nielsen configuration.
'For additional information please see official RAF documentation.
videoContent = {
streamFormat : "mp4",
'Lengthy (17 min.) TED talk to allow time for testing ad pods
stream: {
url: "https://archive.org/download/MuhammadAliVsSonnyListon/MuhammadAliVsSonnyListon_512kb.mp4",
bitrate: 800,
quality: false
}
streamFormat : "hls",
'Lengthy (17 min.) TED talk to allow time for testing ad pods
stream: {
url: "https://livestream.com/accounts/16944724/events/6910212/videos/147348826",
bitrate: 800,
quality: false
}
}
PlayContentWithFullRAFIntegration(videoContent)
End Function