Pre/Post Roll Ads?

hi guys,

I’m new to the roku SDK and I’ve built a app/channel based on the videoplayer example in the SDK. I also built a db/php backend for the XML.

Anyways I’d like to implement pre roll and post roll clips for the movies, and I was wondering if anyone had done that or if anyone had some examples???

thanks!

Not that I have a lot of experience with it yet, but if you use HLS, you could just tack on the videos to the beginning and end of the playlist. From my understanding, you could even put them in the middle, if you computed the timestamps all correctly.

“olav” wrote:
hi guys,

I’m new to the roku SDK and I’ve built a app/channel based on the videoplayer example in the SDK. I also built a db/php backend for the XML.

Anyways I’d like to implement pre roll and post roll clips for the movies, and I was wondering if anyone had done that or if anyone had some examples???

thanks!

You can do it with the roVideoPlayer, but you’ll need to wire up all the transport controls yourself and will get rebuffers between videos, if that’s acceptable.

Patrick how would we do this?

would you add this in the showfeed section ?

Given 2 video URLs, one to an ad and one to your content, you can just make 2 serial calls to showVideoScreen() in appDetailScreen.brs. The downside of that approach is that users will easily be able to skip the ads. That’s where roVideoPlayer comes in handy as Patrick mentioned. It gives you the ability to customize interaction with the remote control, disable FF, etc. To see how it works, take a look at section 5.8 of the Component Reference and the “Custom Video Player” sample included with the 2.6 SDK

chris i have been trying by doing this and similar, and no go


if msg.GetIndex() = 2
                    showVideoScreen([Stream: url: "http://ia301529.us.archive.org/0/items/wonder_bread/wonder_bread_512kb.mp4" StreamFormat: "mp4"])
                    showList[showIndex].PlayStart = 0
                    showVideoScreen(showList[showIndex])
                endif

and boy does it not like that!!

i have read over all the examples even the simple video, can you share how to do this correctly

The problem is syntactical. In BrightScript, brackets designate a roArray while braces {} designate a roAssociativeArray. ShowVideoScreen() expects a roAssociatveArray as an argument, but you’re trying to give it a roArray. It’s also important to note that when you define multiple key/value pairs on the same line of a roAssociativeArray definition, they must be separated by commas. This is not the case if they are on separate lines.

Incorrect:

[Stream: url: "http://ia301529.us.archive.org/0/items/wonder_bread/wonder_bread_512kb.mp4" StreamFormat: "mp4"]

Correct (multiple attributes on one line with commas):

{Stream: {url: "http://ia301529.us.archive.org/0/items/wonder_bread/wonder_bread_512kb.mp4"}, StreamFormat: "mp4"}

Also correct (attributes on individual lines without commas):

{Stream: {url: "http://ia301529.us.archive.org/0/items/wonder_bread/wonder_bread_512kb.mp4"}
 StreamFormat: "mp4"}

ok with that said i did this


 preRoll = {Stream: {url: "http://ia301529.us.archive.org/0/items/wonder_bread/wonder_bread_512kb.mp4"}, StreamFormat: "mp4"} 
                    showVideoScreen(preRoll) 
	              showList[showIndex].PlayStart = 0
                    showVideoScreen(showList[showIndex])

and about 250 other combinations and nothing is working!! this is the only that will semi work and not throw a bunch of errors.

what is wrong with this? what do i need to do to get to work together, please while i still have a hair on my head!!

If you haven’t already (and in a recent post to a separate thread you indicated you haven’t), you should read through both the BrightScript Reference Manual and the Roku Component Reference in their entirety. I would easily equate an extra 15 minutes reading the reference docs to saving 3-5 hours debugging later on.

I suggest paying particular attention to any code examples in the docs, and trying to make sure you understand everything they are doing. If you don’t understand an example, spending the time to figure it out, or asking why it’s explained to do something different than you would expect is a great way to really get to know what’s going on. It’s also easier for anyone you ask to reply authoritatively, since they will have the example in it’s entirety.

@ kbenson I have read them over and over and you show me one place there is a reference to my question of playing a preroll with the video player example!!

So no one is gonna respond?

I understand its a holiday weekend and also the last day of the contest but come on guys, help someone out here, i have added my code so you know im trying to learn here!

just tell me what is wrong with it to make it work, please!

so any development on how this works?

Sorry, the devs are all snoring gently in their beds, with visions of thousands of dollars dancing through their heads…

Tell you guys what, if you haven’t gotten a response or resolved it somehow within 3-4 days, I’ll personally throw something together just to test and figure it out (I haven’t done anything video related yet, so it will be good for me as well). But, as it is now, I’m not planning to look at BrightScript for a few days. This last weekend was grueling.

P.S. I know 3-4 days isn’t exactly what you would want to hear, but at least you have some sort of resolution coming. Hopefully something will develop before then and you won’t need to wait.

thanks !!

I modified the customVideoPlayer smaple app to demonstrate playing streams back to back. Note that currently, this can only be done with a buffering between the streams. Soon, HLS will support seamlist playback of playlists without buffering between the discontinuities.

Try this example:


Sub RunUserInterface()
    o = Setup()
    o.setup()
    o.paint()
    o.eventloop()
End Sub

Sub Setup() As Object
    this = {
        port:      CreateObject("roMessagePort")
        progress:  0 'buffering progress
        position:  0 'playback position (in seconds)
        paused:    false 'is the video currently paused?
        fonts:     CreateObject("roFontRegistry") 'global font registry
        canvas:    CreateObject("roImageCanvas") 'user interface
        player:    CreateObject("roVideoPlayer")
        setup:     SetupFramedCanvas
        paint:     PaintFramedCanvas
        eventloop: EventLoop
    }

    'Static help text:
    this.help = "Press the right or left arrow buttons on the remote control "
    this.help = this.help + "to seek forward or back through the video at "
    this.help = this.help + "approximately one minute intervals.  Press down "
    this.help = this.help + "to toggle fullscreen."

    'Register available fonts:
    this.fonts.Register("pkg:/fonts/caps.otf")
    this.textcolor = "#406040"

    'Setup image canvas:
    this.canvas.SetMessagePort(this.port)
    this.canvas.SetLayer(0, { Color: "#000000" })
    this.canvas.Show()

    'Resolution-specific settings:
    mode = CreateObject("roDeviceInfo").GetDisplayMode()
    if mode = "720p"
        this.layout = {
            full:   this.canvas.GetCanvasRect()
            top:    { x:   0, y:   0, w:1280, h: 130 }
            left:   { x: 249, y: 177, w: 391, h: 291 }
            right:  { x: 700, y: 177, w: 350, h: 291 }
            bottom: { x: 249, y: 500, w: 780, h: 300 }
        }
        this.background = "pkg:/images/back-hd.jpg"
        this.headerfont = this.fonts.get("lmroman10 caps", 50, 50, false)
    else
        this.layout = {
            full:   this.canvas.GetCanvasRect()
            top:    { x:   0, y:   0, w: 720, h:  80 }
            left:   { x: 100, y: 100, w: 280, h: 210 }
            right:  { x: 400, y: 100, w: 220, h: 210 }
            bottom: { x: 100, y: 340, w: 520, h: 140 }
        }
        this.background = "pkg:/images/back-sd.jpg"
        this.headerfont = this.fonts.get("lmroman10 caps", 30, 50, false)
    end if

    this.player = CreateObject("roVideoPlayer")
    this.player.SetMessagePort(this.port)
    this.player.SetLoop(false)
    this.player.SetPositionNotificationPeriod(1)
    this.player.SetDestinationRect(this.layout.left)
    this.player.SetContentList([
        {
        Stream: { url: "http://video.ted.com/talks/podcast/DanGilbert_2004_480.mp4" }
        StreamFormat: "mp4"
        },
        {
        Stream: { url: "http://video.ted.com/talks/podcast/SethGodin_2003_480.mp4" }
        StreamFormat: "mp4"
        }
        ])
    this.player.Play()

    return this
End Sub

Sub EventLoop()
    while true
        msg = wait(0, m.port)
        if msg <> invalid
            'If this is a startup progress status message, record progress
            'and update the UI accordingly:
            if msg.isStatusMessage() and msg.GetMessage() = "startup progress"
                m.paused = false
                progress% = msg.GetIndex() / 10
                if m.progress <> progress%
                    m.progress = progress%
                    m.paint()
                end if

            'Playback progress (in seconds):
            else if msg.isPlaybackPosition()
                m.position = msg.GetIndex()
                m.paint()

            'If the <UP> key is pressed, jump out of this context:
            else if msg.isRemoteKeyPressed()
                index = msg.GetIndex()
                print "Remote button pressed: " + index.tostr()
                if index = 2  '<UP>
                    return
                else if index = 3 '<DOWN> (toggle fullscreen)
                    if m.paint = PaintFullscreenCanvas
                        m.setup = SetupFramedCanvas
                        m.paint = PaintFramedCanvas
                        rect = m.layout.left
                    else
                        m.setup = SetupFullscreenCanvas
                        m.paint = PaintFullscreenCanvas
                        rect = { x:0, y:0, w:0, h:0 } 'fullscreen
                        m.player.SetDestinationRect(0, 0, 0, 0) 'fullscreen
                    end if
                    m.setup()
                    m.player.SetDestinationRect(rect)
                else if index = 4 or index = 8  '<LEFT> or <REV>
                    m.position = m.position - 60
                    m.player.Seek(m.position * 1000)
                else if index = 5 or index = 9  '<RIGHT> or <FWD>
                    m.position = m.position + 60
                    m.player.Seek(m.position * 1000)
                else if index = 13  '<PAUSE/PLAY>
                    if m.paused m.player.Resume() else m.player.Pause()
                end if

            else if msg.isPaused()
                m.paused = true
                m.paint()

            else if msg.isResumed()
                m.paused = false
                m.paint()

            end if
            'Output events for debug
            print msg.GetType(); ","; msg.GetIndex(); ": "; msg.GetMessage()
        end if
    end while
End Sub

Sub SetupFullscreenCanvas()
    m.canvas.AllowUpdates(false)
    m.paint()
    m.canvas.AllowUpdates(true)
End Sub

Sub PaintFullscreenCanvas()
    list = []

    if m.progress < 100
        color = "#000000" 'opaque black
        list.Push({
            Text: "Loading..." + m.progress.tostr() + "%"
            TextAttrs: { font: "huge" }
            TargetRect: m.layout.full
        })
    else if m.paused
        color = "#80000000" 'semi-transparent black
        list.Push({
            Text: "Paused"
            TextAttrs: { font: "huge" }
            TargetRect: m.layout.full
        })
    else
        color = "#00000000" 'fully transparent
    end if

    m.canvas.SetLayer(0, { Color: color, CompositionMode: "Source" })
    m.canvas.SetLayer(1, list)
End Sub

Sub SetupFramedCanvas()
    m.canvas.AllowUpdates(false)
    m.canvas.Clear()
    m.canvas.SetLayer(0, [
        { 'Background:
            Url: m.background
            CompositionMode: "Source"
        },
        { 'The title:
            Text: "Custom Video Player"
            TargetRect: m.layout.top
            TextAttrs: { valign: "bottom", font: m.headerfont, color: m.textcolor }
        },
        { 'Help text:
            Text: m.help
            TargetRect: m.layout.right
            TextAttrs: { halign: "left", valign: "top", color: m.textcolor }
        }
    ])
    m.paint()
    m.canvas.AllowUpdates(true)
End Sub

Sub PaintFramedCanvas()
    list = []
    if m.progress < 100  'Video is currently buffering
        list.Push({
            Color: "#80000000"
            TargetRect: m.layout.left
        })
        list.Push({
            Text: "Loading..." + m.progress.tostr() + "%"
            TargetRect: m.layout.left
        })
    else  'Video is currently playing
        if m.paused
            list.Push({
                Color: "#80000000"
                TargetRect: m.layout.left
                CompositionMode: "Source"
            })
            list.Push({
                Text: "Paused"
                TargetRect: m.layout.left
            })
        else  'not paused
            list.Push({
                Color: "#00000000"
                TargetRect: m.layout.left
                CompositionMode: "Source"
            })
        end if
        list.Push({
            Text: "Current position: " + m.position.tostr() + " seconds"
            TargetRect: m.layout.bottom
            TextAttrs: { halign: "left", valign: "top", color: m.textcolor }
        })
    end if
    m.canvas.SetLayer(1, list)
End Sub

–Kevin

Kevin,

Is m.position clip specific or does it take into account all clips being played?

THX

Thanks but is it possible to show an example in the Video player example??

the issue is getting it set up to work with the category list item, because we can not hard code it as your example

“EngoTom” wrote:
Kevin,

Is m.position clip specific or does it take into account all clips being played?

THX
Since m.position is set to msg.GetIndex(), I’d say it’s relative to the current clip. You’d need to keep track of it separately, if you wanted it to be relative to all clips.

Yes. m.position is relative to the current clip.

–Kevin

again how do we get it working with the video player example which uses a whole different coding scheme from the custom video example…

i think more people use that example more anyways with such options it has