Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Blackhawk
Roku Guru

Playing a video with preroll and midroll ads

I had made a code that I wanted to make an easier way to play videos with preroll and midroll ads

​' create and display a blank roImageCanvas to prevent the
' underlying UI from flickering between videos
canvas = CreateObject("roImageCanvas")
canvas.SetLayer(0, "#000000")
canvas.Show()
' play the preroll video with trick play disabled
if ShowPreroll(preroll)
  ' only play the main content if the preroll completed without user intervention
  ShowVideoScreen(content)
end if

shouldPlayContent = true
adBreakIndex = 0
while shouldPlayContent
  videoMsg = wait(0, contentVideoScreen.GetMessagePort())
  if videoMsg.isPlaybackPosition()
    curPos = videoMsg.GetIndex()
    nextPod = scheduledPods[adBreakIndex]
    if curPos > nextPod.renderTime and not nextPod.viewed
      contentVideoScreen.Close() ' stop playback of content
      shouldPlayContent = adIface.showAds(nextPod) ' render next ad pod
      adBreakIndex = adBreakIndex + 1
      if shouldPlayContent
        ' *** Insert client app’s resume-playback code here
      end if
    end if
  end if
  ' *** Insert client app’s video event handler code here
preroll = {
    streamFormat: "mp4"
    stream: {
      url:  "[url=http://www.archive.org/download/kelloggs_variety_pak/kelloggs_variety_pak_512kb.mp4]http://www.archive.org/download/kelloggs_variety_pak/kelloggs_variety_pak_512kb.mp4[/url]"
    }
  }
content ={
    title:        "TEDTalks : David Brooks: The social animal"
    sdPosterURL:  "[url=https://images.ted.com/images/ted/78e8d94d1d2a81cd182e0626dc8e96a43c88d760_132x99.jpg]https://images.ted.com/images/ted/78e8d94d1d2a81cd182e0626dc8e96a43c88d760_132x99.jpg[/url]"
    hdPosterURL:  "[url=https://images.ted.com/images/ted/78e8d94d1d2a81cd182e0626dc8e96a43c88d760_132x99.jpg]https://images.ted.com/images/ted/78e8d94d1d2a81cd182e0626dc8e96a43c88d760_132x99.jpg[/url]"
    description:  "Tapping into the findings of his latest book, NYTimes columnist David Brooks unpacks new insights into human nature from the cognitive sciences -- insights with massive implications for economics and politics as well as our own self-knowledge. In a talk full of humor, he shows how you can't hope to understand humans as separate individuals making choices based on their conscious awareness."
    contentType:  "episode"
    streamFormat: "mp4"
    stream: {
      url:  "[url=http://video.ted.com/talks/podcast/DavidBrooks_2011.mp4]http://video.ted.com/talks/podcast/DavidBrooks_2011.mp4[/url]"
    }
  }
end while

' close the blank canvas and return the user to the previous UI screen
canvas.Close()

 
 should I set up the code like this?
0 Kudos