' ********** Copyright 2016 Roku Corp. All Rights Reserved. **********
' inits details screen
' sets all observers
' configures buttons for Details screen
Function Init()
? "[DetailsScreen] init"
m.top.observeField("visible", "onVisibleChange")
m.top.observeField("focusedChild", "OnFocusedChildChange")
m.buttons = m.top.findNode("Buttons")
m.poster = m.top.findNode("Poster")
m.description = m.top.findNode("Description")
m.background = m.top.findNode("Background")
' create buttons
result = []
for each button in ["Play", "Second button"]
result.push({title : button})
end for
m.buttons.content = ContentList2SimpleNode(result)
End Function
' set proper focus to buttons if Details opened and stops Video if Details closed
Sub onVisibleChange()
? "[DetailsScreen] onVisibleChange"
if m.top.visible = true then
m.buttons.jumpToItem = 0
m.buttons.setFocus(true)
else
m.Player.visible = false
m.Player.control = "stop"
m.poster.uri=""
m.background.uri=""
end if
End Sub
' set proper focus to Buttons in case if return from Video PLayer
Sub OnFocusedChildChange()
if m.top.isInFocusChain() and not m.buttons.hasFocus() and not m.Player.hasFocus() then
m.buttons.setFocus(true)
end if
End Sub
' set proper focus on buttons and stops video if return from Playback to details
Sub onVideoVisibleChange()
if m.Player.visible = false and m.top.visible = true
m.buttons.setFocus(true)
m.Player.control = "stop"
end if
End Sub
sub PlayerStateChanged()
print "EntryScene: PlayerStateChanged(), state = "; m.Player.state
if m.Player.state = "done" or m.Player.state = "stop"
m.Player.visible = false
m.list.setFocus(true) 'NB. the player took the focus away, so get it back
end if
end sub
' on Button press handler
Sub onItemSelected()
' compile into a VideoContent node
content = CreateObject("roSGNode", "VideoContent")
content.setFields(videoContent)
' first button is Play
if m.top.itemSelected = 0
if m.Player = invalid:
m.Player = m.top.CreateChild("Player")
m.Player.observeField("state", "PlayerStateChanged")
end if
'start the player
m.Player.content = content
m.Player.visible = true
m.Player.control = "play"
end if
End Sub
' Content change handler
Sub OnContentChange()
m.description.content = m.top.content
m.description.Description.width = "770"
m.Player.content = m.top.content
m.top.streamUrl = m.top.content.url
m.poster.uri = m.top.content.hdBackgroundImageUrl
m.background.uri = m.top.content.hdBackgroundImageUrl
End Sub
'///////////////////////////////////////////'
' Helper function convert AA to Node
Function ContentList2SimpleNode(contentList as Object, nodeType = "ContentNode" as String) as Object
result = createObject("roSGNode",nodeType)
if result <> invalid
for each itemAA in contentList
item = createObject("roSGNode", nodeType)
item.setFields(itemAA)
result.appendChild(item)
end for
end if
return result
End Function
and I got this error
Invalid value for left-side of expression. (runtime error &he4) in pkg:/components/screens/DetailsScreen/DetailsScreen.brs(32)~
Invalid value for left-side of expression. (runtime error &he4) in pkg:/components/screens/DetailsScreen/DetailsScreen.brs(32)
032: m.Player.visible = false
Backtrace: #0 Function onvisiblechange() As Void
file/line: pkg:/components/screens/DetailsScreen/DetailsScreen.brs(33)
I looks like you’ll have to make sure there is definitely an m.Player at that point. You can test it by printing to console above it, put it a line
? "m.Player = " m.Player
and see what it says, such as “invalid” or a component or something
' ********** Copyright 2016 Roku Corp. All Rights Reserved. **********
' inits details screen
' sets all observers
' configures buttons for Details screen
Function Init()
print "DetailsScreen.brs - [init]"
m.top.observeField("visible", "onVisibleChange")
m.top.observeField("focusedChild", "OnFocusedChildChange")
m.buttons = m.top.findNode("Buttons")
m.poster = m.top.findNode("Poster")
m.description = m.top.findNode("Description")
m.background = m.top.findNode("Background")
m.fadeIn = m.top.findNode("fadeinAnimation")
m.fadeOut = m.top.findNode("fadeoutAnimation")
' create buttons
result = []
for each button in ["Play", "Second button"]
result.push({title : button})
end for
m.buttons.content = ContentList2SimpleNode(result)
End Function
' set proper focus to buttons if Details opened and stops Video if Details closed
Sub onVisibleChange()
print "DetailsScreen.brs - [onVisibleChange]"
if m.top.visible
m.fadeIn.control="start"
m.buttons.jumpToItem = 0
m.buttons.setFocus(true)
else
m.fadeOut.control="start"
m.Player.visible = false
m.Player.control = "stop"
m.poster.url=""
m.background.url=""
end if
End Sub
sub PlayerStateChanged()
print "EntryScene: PlayerStateChanged(), state = "; m.Player.state
if m.Player.state = "done" or m.Player.state = "stop"
m.Player.visible = false
m.list.setFocus(true) 'NB. the player took the focus away, so get it back
end if
end sub
' set proper focus to Buttons in case if return from Video PLayer
Sub OnFocusedChildChange()
print "DetailsScreen.brs - [OnFocusedChildChange]"
if m.top.isInFocusChain() and not m.buttons.hasFocus() and not m.videoPlayer.hasFocus() then
m.buttons.setFocus(true)
end if
End Sub
' on Button press handler
Sub onItemSelected()
print "DetailsScreen.brs - [onItemSelected]"
content = CreateObject("roSGNode", "VideoContent")
content.setFields(videoContent)
if m.Player = invalid:
m.Player = m.top.CreateChild("Player")
m.Player.observeField("state", "PlayerStateChanged")
end if
' first button is Play
if m.top.itemSelected = 0
'start the player
m.Player.content = content
m.Player.visible = true
m.Player.control = "play"
end if
End Sub
' Content change handler
Sub OnContentChange()
print "DetailsScreen.brs - [OnContentChange]"
m.description.content = m.top.content
m.description.Description.width = "1120"
m.Player.content = m.top.content
m.top.streamUrl = m.top.content.url
m.poster.url = m.top.content.hdBackgroundImageUrl
m.background.url = m.top.content.hdBackgroundImageUrl
End Sub
'///////////////////////////////////////////'
' Helper function convert AA to Node
Function ContentList2SimpleNode(contentList as Object, nodeType = "ContentNode" as String) as Object
print "DetailsScreen.brs - [ContentList2SimpleNode]"
result = createObject("roSGNode", nodeType)
if result <> invalid
for each itemAA in contentList
item = createObject("roSGNode", nodeType)
item.setFields(itemAA)
result.appendChild(item)
end for
end if
return result
End Function
Yet I keep getting this error:
Invalid value for left-side of expression. (runtime error &he4) in pkg:/components/DetailsScreen/DetailsScreen.brs(35)
035: m.Player.visible = false
Backtrace: #0 Function onvisiblechange() As Void
file/line: pkg:/components/DetailsScreen/DetailsScreen.brs(36)
I probably wouldn’t even stick that line in the OnVisibleChange routine. You are setting it visible in the OnItemSelected, and you are setting visibility to false when the video state is stopped or done. You might want to add some error conditions for streams that fail to play to tidy up the possible exits from the playback routine. If you want it to be visible=false on init then you can set that in the init function or in the xml.
' ********** Copyright 2016 Roku Corp. All Rights Reserved. **********
' inits details screen
' sets all observers
' configures buttons for Details screen
Function Init()
print "DetailsScreen.brs - [init]"
m.top.observeField("focusedChild", "OnFocusedChildChange")
m.buttons = m.top.findNode("Buttons")
m.poster = m.top.findNode("Poster")
m.description = m.top.findNode("Description")
m.background = m.top.findNode("Background")
m.fadeIn = m.top.findNode("fadeinAnimation")
m.fadeOut = m.top.findNode("fadeoutAnimation")
' create buttons
result = []
for each button in ["Play", "Second button"]
result.push({title : button})
end for
m.buttons.content = ContentList2SimpleNode(result)
End Function
sub PlayerStateChanged()
print "EntryScene: PlayerStateChanged(), state = "; m.Player.state
if m.Player.state = "done" or m.Player.state = "stop"
m.Player.visible = false
m.list.setFocus(true) 'NB. the player took the focus away, so get it back
end if
end sub
' set proper focus to Buttons in case if return from Video PLayer
Sub OnFocusedChildChange()
print "DetailsScreen.brs - [OnFocusedChildChange]"
if m.top.isInFocusChain() and not m.buttons.hasFocus() and not m.videoPlayer.hasFocus() then
m.buttons.setFocus(true)
end if
End Sub
' on Button press handler
Sub onItemSelected()
print "DetailsScreen.brs - [onItemSelected]"
content = CreateObject("roSGNode", "VideoContent")
content.setFields(videoContent)
if m.Player = invalid:
m.Player = m.top.CreateChild("Player")
m.Player.observeField("state", "PlayerStateChanged")
end if
' first button is Play
if m.top.itemSelected = 0
'start the player
m.Player.content = content
m.Player.visible = true
m.Player.control = "play"
end if
End Sub
' Content change handler
Sub OnContentChange()
print "DetailsScreen.brs - [OnContentChange]"
m.description.content = m.top.content
m.description.Description.width = "1120"
m.Player.content = m.top.content
m.top.streamUrl = m.top.content.url
m.poster.url = m.top.content.hdBackgroundImageUrl
m.background.url = m.top.content.hdBackgroundImageUrl
End Sub
'///////////////////////////////////////////'
' Helper function convert AA to Node
Function ContentList2SimpleNode(contentList as Object, nodeType = "ContentNode" as String) as Object
print "DetailsScreen.brs - [ContentList2SimpleNode]"
result = createObject("roSGNode", nodeType)
if result <> invalid
for each itemAA in contentList
item = createObject("roSGNode", nodeType)
item.setFields(itemAA)
result.appendChild(item)
end for
end if
return result
End Function
Now I got this error:
Invalid value for left-side of expression. (runtime error &he4) in pkg:/components/DetailsScreen/DetailsScreen.brs(65)
065: m.Player.content = m.top.content
Backtrace: #0 Function oncontentchange() As Void
file/line: pkg:/components/DetailsScreen/DetailsScreen.brs(66)
Local Variables:
global Interface:ifGlobal
m roAssociativeArray refcnt=2 count:8
Threads:
ID Location Source Code
0 pkg:/source/main.brs(44) msg = wait(0, m.port)
1* …tailsScreen/DetailsScreen.brs(65) m.Player.content = m.top.content
2 …onents/Content/UriHandler.brs(87) msg = wait(0, m.port)
*selected
' on Button press handler
Sub onItemSelected()
print "DetailsScreen.brs - [onItemSelected]"
content = CreateObject("roSGNode", "VideoContent")
content.setFields(videoContent)
if m.Player = invalid:
m.Player = m.top.CreateChild("Player")
m.Player.observeField("state", "PlayerStateChanged")
else
m.Player = m.top.CreateChild("Player")
end if
' first button is Play
if m.top.itemSelected = 0
'start the player
m.Player.content = content
m.Player.visible = true
m.Player.control = "play"
end if
End Sub
I still get this error
Invalid value for left-side of expression. (runtime error &he4) in pkg:/components/DetailsScreen/DetailsScreen.brs(65)