Here is code for playContent() method :
Function PlayVideoContent(content as Object) as Object
' roVideoScreen just closes if you try to resume or seek after
' returning from ad playback... TODO: is there a way to make
' this work without resetting the screen object?
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
And this entire contents of the main.brs file:
Library "Roku_Ads.brs"
sub Main(params)
' lengthy (20+ min.) TED talk to allow time for testing multiple ad pods
videoContent = { streamFormat : "mp4" }
videoContent.stream = { url: "http://video.ted.com/talks/podcast/DavidKelley_2002_480.mp4",
bitrate: 800,
quality: false
}
PlayContentWithAds(videoContent)
end sub
Function PlayVideoContent(content as Object) as Object
' roVideoScreen just closes if you try to resume or seek after
' returning from ad playback... TODO: is there a way to make
' this work without resetting the screen object?
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
Sub PlayContentWithAds(videoContent as Object)
canvas = CreateObject("roImageCanvas")
canvas.SetLayer(1, {color: "#000000"})
canvas.SetLayer(2, {text: "Loading..."})
canvas.Show()
adIface = Roku_Ads()
print "Roku_Ads library version: " + adIface.getLibVersion()
' Normally, would set publisher's ad URL here. Otherwise uses default Roku ad server (with single preroll placeholder ad)
adIface.setAdUrl("http://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&impl=s&gdfp_req=1&env=vp&output=vmap&unviewed_position_start=1&cust_params=deployment%3Ddevsite%26sample_ar%3Dpremidpost&cmsid=496&vid=short_onecue&correlator=")
adPods = adIface.getAds()
print "printing adpods count here.."
print adPods.count()
playContent = adIface.showAds(adPods) ' show preroll ad pod (if any)
curPos = 0
if playContent
videoScreen = PlayVideoContent(videoContent)
end if
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
'check for midroll/postroll ad pods
adPods = adIface.getAds(videoMsg)
if adPods <> invalid and adPods.Count() > 0
' stop video playback to prepare for midroll ad render
videoScreen.Close()
playContent = adIface.showAds(adPods)
if playContent
' resume video playback after midroll ads
videoContent.PlayStart = curPos
videoScreen = PlayVideoContent(videoContent)
end if
' if !playContent, User exited ad view, returning to content selection
end if ' adPods <> invalid
if videoMsg.isFullResult() or videoMsg.isRequestFailed() or videoMsg.isPartialResult() or videoMsg.isScreenClosed()
playContent = false
end if
end if ' roVideoScreenEvent
end while
if type(videoScreen) = "roVideoScreen" then videoScreen.Close()
End Sub