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

Video keeps looping ads

I had gotten this code

' ********** Copyright 2016 Roku Corp.  All Rights Reserved. **********
Library "Roku_Ads.brs"
'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.
'videoContent [AA] object that has valid data for playing video with roVideoScreen.
Sub PlayContentWithFullRAFIntegration(episode 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(episode.contentId)
    RAF.SetContentGenre(episode.contentGenre)
   
    'Nielsen content params
    RAF.enableNielsenDAR(true)
    RAF.setContentLength(episode.contentLength)
    RAF.setNielsenProgramId(episode.nielsenProgramId)
    RAF.setNielsenGenre(episode.nielsenGenre)
    RAF.setNielsenAppId(episode.nielsenAppId)
    '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)
  

    'Returns available ad pod(s) scheduled for rendering or invalid, if none are available.
    adPods = RAF.getAds()
    playContent = RAF.showAds(adPods)
'show preroll ad pod (if any)
    curPos = 0
    if playContent
        videoScreen = showVideoScreen(episode)
    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
                    episode.PlayStart = curPos
                    videoScreen = showVideoScreen(episode)
                end if
            end if '!closingContentScreen
        end if 'roVideoScreenEvent
    end while
    if type(videoScreen) = "roVideoScreen" then videoScreen.Close()
End Sub


To play ads on this code

'**********************************************************
'** Video Player Example Application - Video Playback
'** November 2009
'** Copyright (c) 2009 Roku Inc. All Rights Reserved.
'**********************************************************
 
'***********************************************************
'** Create and show the video screen. The video screen is
'** a special full screen video playback component. It
'** handles most of the keypresses automatically and our
'** job is primarily to make sure it has the correct data
'** at startup. We will receive event back on progress and
'** error conditions so it's important to monitor these to
'** understand what's going on, especially in the case of errors
'***********************************************************
Function showVideoScreen(episode As Object)
 
if type(episode) <> "roAssociativeArray" then
print "invalid data passed to showVideoScreen"
return -1
endif
 
port = CreateObject("roMessagePort")
screen = CreateObject("roVideoScreen")
screen.SetMessagePort(port)
 
screen.SetPositionNotificationPeriod(30)
screen.SetContent(episode)
screen.Show()
 
PlayContentWithFullRAFIntegration(episode)
 
'Uncomment his line to dump the contents of the episode to be played
'PrintAA(episode)
 
while true
msg = wait(0, port)
 
if type(msg) = "roVideoScreenEvent" then
print "showHomeScreen | msg = "; msg.getMessage() " | index = "; msg.GetIndex()
if msg.isScreenClosed()
print "Screen closed"
exit while
elseif msg.isRequestFailed()
print "Video request failure: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isStatusMessage()
print "Video status: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
RegWrite(episode.ContentId, nowpos.toStr())
else
print "Unexpected event type: "; msg.GetType()
end if
else
print "Unexpected message class: "; type(msg)
end if
end while
 
End Function

 
 The problem is that the ad keeps looping instead of playing the intended video
 
0 Kudos