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

Live feed error

I'm making an live feed with ads yet theres Syntax Error on this code

' ********************************************************************

' ** Sample PlayVideo App

' ** Copyright (c) 2009 Roku Inc. All Rights Reserved.

' ********************************************************************

Function ShowLiveFeed() as integer

' 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

 

 

preroll = {

streamFormat: "mp4"

stream: {

url: "http://www.archive.org/download/kelloggs_variety_pak/kelloggs_variety_pak_512kb.mp4"

}

}

content ={

title: "TEDTalks : David Brooks: The social animal"

sdPosterURL: "https://images.ted.com/images/ted/78e8d94d1d2a81cd182e0626dc8e96a43c88d760_132x99.jpg"

hdPosterURL: "https://images.ted.com/images/ted/78e8d94d1d2a81cd182e0626dc8e96a43c88d760_132x99.jpg"

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: "http://video.ted.com/talks/podcast/DavidBrooks_2011.mp4"

}

}

 

playContent = true

while playContent

msg = Wait(0, videoPlayer.GetMessagePort())

currentAd = adIface.stitchedAdHandledEvent(msg, videoPlayer)



if currentAd <> Invalid and currentAd.evtHandled

' ad handled event, take no further action

if currentAd.adExited

' user exited, return to content selection

playContent = false

end if

else

' if no current ad or ad did not handle event, fall through to default event handling here

' ... Your application's usual event-handling code here ...

end if

end while

 

' close the blank canvas and return the user to the previous UI screen

canvas.Close()

End Function

sub ShowVideoScreen(video)

port = CreateObject("roMessagePort")

screen = CreateObject("roVideoScreen")

screen.SetMessagePort(port)

screen.SetContent(video)

screen.Show()

while true

msg = wait(0, port)

if type(msg) = "roVideoScreenEvent"

if msg.isScreenClosed()

exit while

end if

end if

end while

screen.Close()

End Function

function ShowPreRoll(video)

' a true result indicates that playback finished without user intervention

' a false result indicates that the user pressed UP or BACK to terminate playback

result = true

canvas = CreateObject("roImageCanvas")

player = CreateObject("roVideoPlayer")

port = CreateObject("roMessagePort")

canvas.SetMessagePort(port)

' build a very simple buffer screen for our preroll video

canvas.SetLayer(0, { text: "Your program will begin after this message" })

canvas.Show()

' be sure to use the same message port for both the canvas and the player

' so we can receive events from both

player.SetMessagePort(port)

player.SetDestinationRect(canvas.GetCanvasRect())

player.AddContent(video)

player.Play()

' start our event loop

while true

' wait for an event

msg = wait(0, canvas.GetMessagePort())

if type(msg) = "roVideoPlayerEvent"

if msg.isFullResult()

' the video played to the end without user intervention

exit while

else if isRequestFailed()

' something went wrong with playback, but the user did not intervene

exit while

else if msg.isStatusMessage()

if msg.GetMessage() = "start of play"

' once the video starts, clear out the canvas so it doesn't cover the video

canvas.SetLayer(0, { color: "#00000000", CompositionMode: "Source" })

canvas.Show()

end if

end if

else if type(msg) = "roImageCanvasEvent"

if msg.isRemoteKeyPressed()

index = msg.GetIndex()

if index = 0 or index = 2

' the user pressed UP or BACK to terminate playback

result = false

exit while

end if

end if

end if

end while

player.Stop()

canvas.Close()

return result

end function


How do I fix this?
0 Kudos
14 REPLIES 14
joetesta
Roku Guru

Re: Live feed error

When you define your Associative Arrays using {}, you need to put commas between the elements;
aa = { one : 1, two : 2, three : 3 }

https://sdkdocs.roku.com/display/sdkdoc/roAssociativeArray

There may be other issues, when you side load, the debugger should tell you the first line where it sees a Syntax Error.
aspiring
0 Kudos
belltown
Roku Guru

Re: Live feed error

"joetesta" wrote:
When you define your Associative Arrays using {}, you need to put commas between the elements

Not if you're using the multi-line form, as he is.
0 Kudos
EnTerr
Roku Guru

Re: Live feed error

"Blackhawk" wrote:
I'm making an live feed with ads yet theres Syntax Error on this code
[...]
How do I fix this?

The exact error message tends to tell you the line# where that is - look there. If that does not help outright, apply "wolf fencing" - comment parts of the code and look for changes till you corner that wolf.
0 Kudos
Blackhawk
Roku Guru

Re: Live feed error

I managed to change the code

' ********** Copyright 2016 Roku Corp. All Rights Reserved. ********** 
 
 
'Creation and configuration of list screen menu.
Function Main()

'AA for base video, ad and Nielsen configuration.
'For additional information please see official RAF documentation.
videoContent = {
streamFormat : "mp4",
'Lengthy (17 min.) TED talk to allow time for testing ad pods
stream: {
url: "http://xhamster.com/movies/4476879/party_russian_girls_in_sauna.html",
bitrate: 800,
quality: false
}
}
PlayContentWithFullRAFIntegration(videoContent)

End Function
'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.
'@param videoContent [AA] object that has valid data for playing video with roVideoScreen.
Sub PlayContentWithFullRAFIntegration(videoContent as Object)
'Main facade creation.
canvas = CreateObject("roImageCanvas")
canvas.SetLayer(1, {color: "#000000"})
canvas.SetLayer(2, {text: "Loading..."})
canvas.Show()
adIface = Roku_Ads() 'RAF initialize
print "Roku_Ads library version: " + adIface.getLibVersion()
adIface.setDebugOutput(true) 'for debug pupropse
'RAF content params
adIface.setContentId(videoContent.contentId)
adIface.SetContentGenre(videoContent.contentGenre)

'Nielsen content params
adIface.enableNielsenDAR(true)
adIface.setContentLength(videoContent.conntentLength)
adIface.setNielsenProgramId(videoContent.nielsenProgramId)
adIface.setNielsenGenre(videoContent.nielsenGenre)
adIface.setNielsenAppId(videoContent.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.
adIface.setAdPrefs(true, 2)

'Normally, would set publisher's ad URL here.
'Otherwise uses default Roku ad server (with single preroll placeholder ad)
adIface.setAdUrl(videoContent.adUrl)
'Returns available ad pod(s) scheduled for rendering or invalid, if none are available.
adPods = adIface.getAds()
playContent = adIface.showAds(adPods) 'show preroll ad pod (if any)
curPos = 0
if playContent
videoScreen = PlayVideoContent(videoContent)
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 = adIface.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 = adIface.showAds(adPods)
playContent = playContent and not contentDone
if playContent
'resume video playback after midroll ads
videoContent.PlayStart = curPos
videoScreen = PlayVideoContent(videoContent)
end if
end if '!closingContentScreen
end if 'roVideoScreenEvent
end while
if type(videoScreen) = "roVideoScreen" then videoScreen.Close()
End Sub
'Creation and configuration of video screen.
'@param content [AA] object that has valid data for playing video with roVideoScreen
'@returns [roVideoScreen] video screen object
Function PlayVideoContent(content as Object) as Object
' roVideoScreen just closes if you try to resume or seek after ad playback,
' so just create a new instance of the screen...
videoScreen = CreateObject("roVideoScreen")
videoScreen.SetContent(content)
' need a reasonable notification period set if midroll/postroll ads are to be
' rendered at an appropriate time
videoScreen.SetPositionNotificationPeriod(1)
videoScreen.SetMessagePort(CreateObject("roMessagePort"))
videoScreen.Show()
return videoScreen
End Function

Yet theres errors:
Function Call Operator ( ) attempted on non-function. (runtime error &he0) in pkg:/source/main.brs(41)
041:     adIface = Roku_Ads() 'RAF initialize
Backtrace:
#1  Function playcontentwithfullrafintegration(videocontent As Object) As Void
   file/line: pkg:/source/main.brs(41)
#0  Function main() As Dynamic
   file/line: pkg:/source/main.brs(21)
0 Kudos
EnTerr
Roku Guru

Re: Live feed error

"Blackhawk" wrote:
Yet theres errors:
Function Call Operator ( ) attempted on non-function. (runtime error &he0) in pkg:/source/main.brs(41)
041:     adIface = Roku_Ads() 'RAF initialize

Read the first half of "Getting Started" with RAF - specifically the bs_libs_required and Library incantations.
0 Kudos
Blackhawk
Roku Guru

Re: Live feed error

 I set up the feed like this
Library "Roku_Ads.brs"

Function CreateLiveFeed() as integer



'AA for base video, ad and Nielsen configuration.

'For additional information please see official RAF documentation.

videoContent = {

streamFormat : "hls",

'Lengthy (17 min.) TED talk to allow time for testing ad pods

stream: {

url: "https://livestream.com/accounts/16944724/DetroitAutoShow.hls",

bitrate: 800,

quality: false

}

}

PlayContentWithFullRAFIntegration(videoContent)



End Function

 

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

'@param videoContent [AA] object that has valid data for playing video with roVideoScreen.

Sub PlayContentWithFullRAFIntegration(videoContent as Object)

'Main facade creation.

canvas = CreateObject("roImageCanvas")

canvas.SetLayer(1, {color: "#000000"})

canvas.SetLayer(2, {text: "Loading..."})

canvas.Show()

adIface = Roku_Ads() 'RAF initialize

print "Roku_Ads library version: " + adIface.getLibVersion()

adIface.setDebugOutput(true) 'for debug pupropse

'RAF content params

adIface.setContentId(videoContent.contentId)

adIface.SetContentGenre(videoContent.contentGenre)



'Nielsen content params

adIface.enableNielsenDAR(true)

adIface.setContentLength(videoContent.conntentLength)

adIface.setNielsenProgramId(videoContent.nielsenProgramId)

adIface.setNielsenGenre(videoContent.nielsenGenre)

adIface.setNielsenAppId(videoContent.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.

adIface.setAdPrefs(true, 2)



'Normally, would set publisher's ad URL here.

'Otherwise uses default Roku ad server (with single preroll placeholder ad)

adIface.setAdUrl(videoContent.adUrl)

'Returns available ad pod(s) scheduled for rendering or invalid, if none are available.

adPods = adIface.getAds()

playContent = adIface.showAds(adPods) 'show preroll ad pod (if any)

curPos = 0

if playContent

videoScreen = PlayVideoContent(videoContent)

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 = adIface.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 = adIface.showAds(adPods)

playContent = playContent and not contentDone

if playContent

'resume video playback after midroll ads

videoContent.PlayStart = curPos

videoScreen = PlayVideoContent(videoContent)

end if

end if '!closingContentScreen

end if 'roVideoScreenEvent

end while

if type(videoScreen) = "roVideoScreen" then videoScreen.Close()

End Sub

'Creation and configuration of video screen.

'@param content [AA] object that has valid data for playing video with roVideoScreen

'@returns [roVideoScreen] video screen object

Function PlayVideoContent(content as Object) as Object

' roVideoScreen just closes if you try to resume or seek after ad playback,

' so just create a new instance of the screen...

videoScreen = CreateObject("roVideoScreen")

videoScreen.SetContent(content)

' need a reasonable notification period set if midroll/postroll ads are to be

' rendered at an appropriate time

videoScreen.SetPositionNotificationPeriod(1)

videoScreen.SetMessagePort(CreateObject("roMessagePort"))

videoScreen.Show()

return videoScreen

End Function




Now its not playing the ad
Type Mismatch. (runtime error &h18) in roku_ads_lib:/Roku_Ads.brs(3608)
3608: ??
Backtrace:
#3  Function roku_ads_configurecontentid(id_ As String) As Void
   file/line: roku_ads_lib:/Roku_Ads.brs(3609)
#2  Function playcontentwithfullrafintegration(videocontent As Object) As Void
   file/line: pkg:/source/lunchMenu - Copy - Copy.brs(26)
#1  Function createlivefeed() As Integer
   file/line: pkg:/source/lunchMenu - Copy.brs(17)
#0  Function main() As Void
   file/line: pkg:/source/main.brs(20)
Local Variables:
No variable info.
0 Kudos
belltown
Roku Guru

Re: Live feed error

Do you have a valid ad url here:
adIface.setAdUrl(videoContent.adUrl)


Try this instead and see if the error goes away:
adIface.setAdUrl()
0 Kudos
EnTerr
Roku Guru

Re: Live feed error

"belltown" wrote:
Try this instead and see if the error goes away:
adIface.setAdUrl()


Rather, do NOT call setAdUrl() at all and let RAF do its job.
"No custom URL" is the simplest and default case - start with that. Most apps never use custom URL.
It's in the "Getting Started" section - yeah, right there - written between the lines. Smiley LOL
0 Kudos
Blackhawk
Roku Guru

Re: Live feed error

 Like this?


'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.
'@param videoContent [AA] object that has valid data for playing video with roVideoScreen.
Sub PlayContentWithFullRAFIntegration(videoContent as Object)
'Main facade creation.
canvas = CreateObject("roImageCanvas")
canvas.SetLayer(1, {color: "#000000"})
canvas.SetLayer(2, {text: "Loading..."})
canvas.Show()
adIface = Roku_Ads() 'RAF initialize
print "Roku_Ads library version: " + adIface.getLibVersion()
adIface.setDebugOutput(true) 'for debug pupropse
'RAF content params
adIface.setContentId(videoContent.contentId)
adIface.SetContentGenre(videoContent.contentGenre)

'Nielsen content params
adIface.enableNielsenDAR(true)
adIface.setContentLength(videoContent.conntentLength)
adIface.setNielsenProgramId(videoContent.nielsenProgramId)
adIface.setNielsenGenre(videoContent.nielsenGenre)
adIface.setNielsenAppId(videoContent.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.
adIface.setAdPrefs(true, 2)
'Returns available ad pod(s) scheduled for rendering or invalid, if none are available.
adPods = adIface.getAds()
playContent = adIface.showAds(adPods) 'show preroll ad pod (if any)
curPos = 0
if playContent
videoScreen = PlayVideoContent(videoContent)
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 = adIface.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 = adIface.showAds(adPods)
playContent = playContent and not contentDone
if playContent
'resume video playback after midroll ads
videoContent.PlayStart = curPos
videoScreen = PlayVideoContent(videoContent)
end if
end if '!closingContentScreen
end if 'roVideoScreenEvent
end while
if type(videoScreen) = "roVideoScreen" then videoScreen.Close()
End Sub
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.