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: 
uarlive
Visitor

advertisement countdown

I am trying to get the duration of the ad to count down on the screen. Below is the code that I have working so far. The number of seconds is currently static and should be dymanic. Thanks in advance.


function ShowPreRoll(canvas, ad)
result = true

player = CreateObject("roVideoPlayer")
' be sure to use the same message port for both the canvas and the player
player.SetMessagePort(canvas.GetMessagePort())
player.SetDestinationRect(canvas.GetCanvasRect())
player.SetPositionNotificationPeriod(1)
timer = CreateObject("roTimespan")
timer.mark()
--> Problem area ad_duration = ad.length - timer

' set up some messaging to display while the pre-roll buffers

deviceInfo = CreateObject( "roDeviceInfo" )
displaySize = deviceInfo.GetDisplaySize()



overlay = {
TargetRect: {
x: Int( displaySize.w / 2 ) - Int( 336 / 2 ),
y: Int( displaySize.h / 2 ) - Int( 375 / 2 ),
w: 336,
h: 210
}
}

loadingText = {
--> Problem area Text: "Your video will begin after this message" + ad_duration.ToStr() + " seconds",
TextAttrs: {
Font: "Medium",
VAlign: "Bottom",
Color: "#FFFFFF",
},
TargetRect: {
x: Int( displaySize.w / 2 ) - Int( 1180 / 2 ),
y: Int( displaySize.h / 2 ) - Int( -600 / 2 ),
w: 575,
h: 30
}
}
canvas.Show()


Type Mismatch. (runtime error &h18) in ...:/source/VAST_VideoScreen.brs(52)

052: ad_duration = ad.length - timer
Backtrace:
0 Kudos
2 REPLIES 2
destruk
Streaming Star

Re: advertisement countdown

"timer" is an object, you are trying to subtract it as an integer, but it isn't an integer.

Integer TotalSeconds(Void)
• Returns the total number of seconds from the “Mark” point.

You should be subtracting timer.totalseconds() which returns as an integer.

Even using that though, you'll want to loop it or nest it inside a routine so it will constantly repeat the subtraction and display until it reaches 0.
0 Kudos
uarlive
Visitor

Re: advertisement countdown

Thanks. That pointed me in the right direction.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.