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

Need help with ad support

I have made a code for an ad supported series




Function CreateHomeworkHelperzMenu() as integer
screen = CreateObject("roGridScreen")
port = CreateObject("roMessagePort")
screen.SetMessagePort(port)

screen.SetBreadcrumbText("Lunch", "Full Menu")
screen.SetupLists(2)
screen.SetListNames(["2016"])

screen.SetContentList(0, GetHomeworkHelperzMenuOptions_2016())

screen.show()

while (true)
msg = wait(0, port)
if type(msg) = "roGridScreenEvent"
if (msg.isScreenClosed())
return -1
else if (msg.isListItemSelected())
showSpringboardScreen( msg.GetIndex() )
showSpringboardScreen(videoContent)

endif
endif
end while
End Function

'*************************************************************
'** displayVideo()
'*************************************************************

Function displayVideo(args As Dynamic)
print "Displaying video: "
p = CreateObject("roMessagePort")
video = CreateObject("roVideoScreen")
video.setMessagePort(p)

'bitrates = [0] ' 0 = no dots, adaptive bitrate
'bitrates = [348] ' <500 Kbps = 1 dot
'bitrates = [664] ' <800 Kbps = 2 dots
'bitrates = [996] ' <1.1Mbps = 3 dots
'bitrates = [2048] ' >=1.1Mbps = 4 dots
bitrates = [0]

' 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)

if type(args) = "roAssociativeArray"
if type(args.url) = "roString" and args.url <> "" then
urls[0] = args.url
end if
if type(args.StreamFormat) = "roString" and args.StreamFormat <> "" then
StreamFormat = args.StreamFormat
end if
if type(args.title) = "roString" and args.title <> "" then
title = args.title
else
title = ""
end if
if type(args.srt) = "roString" and args.srt <> "" then
srt = args.StreamFormat
else
srt = ""
end if
end if

videoclip = CreateObject("roAssociativeArray")
videoclip.StreamBitrates = bitrates
videoclip.StreamUrls = urls
videoclip.StreamQualities = qualities
videoclip.StreamFormat = StreamFormat
videoclip.Title = title
print "srt = ";srt
if srt <> invalid and srt <> "" then
videoclip.SubtitleUrl = srt
end if

video.SetContent(videoclip)
video.show()

lastSavedPos = 0
statusInterval = 10 'position must change by more than this number of seconds before saving

while true
msg = wait(0, video.GetMessagePort())
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed() then 'ScreenClosed event
print "Closing video screen"
exit while
else if msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
if nowpos > 10000

end if
if nowpos > 0
if abs(nowpos - lastSavedPos) > statusInterval
lastSavedPos = nowpos
end if
end if
else if msg.isRequestFailed()
print "play failed: "; msg.GetMessage()
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
endif
end if
end while
End Function


When I play the series the show gets stuck on the loading screen
0 Kudos
4 REPLIES 4
squirreltown
Roku Guru

Re: Need help with ad support

Function displayVideo(args As Dynamic)


Shouldn't "as dynamic" be outside the parentheses ?
Kinetics Screensavers
0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: Need help with ad support

"squirreltown" wrote:
Function displayVideo(args As Dynamic)

Shouldn't "as dynamic" be outside the parentheses ?


That definition is perfectly valid. If you don't declare the return type for a function, it is implicitly "As Dynamic".

Though the actual function implementation above doesn't seem to be returning anything, so declaring it "As Void" might make it more clear.
0 Kudos
squirreltown
Roku Guru

Re: Need help with ad support

"RokuKC" wrote:
"squirreltown" wrote:
Function displayVideo(args As Dynamic)

Shouldn't "as dynamic" be outside the parentheses ?


That definition is perfectly valid. If you don't declare the return type for a function, it is implicitly "As Dynamic".

Though the actual function implementation above doesn't seem to be returning anything, so declaring it "As Void" might make it more clear.



Yea, I don't know what I was thinking. Maybe I'm so used to looking at syntax highlighting it looked odd.
Kinetics Screensavers
0 Kudos
Blackhawk
Roku Guru

Re: Need help with ad support

Is there any way to fix this problem?
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.