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

Time Update of Canvas Layer List

Another questions about Canvas updates.

I setup the canvas and do a url call to json data. I would like to then call the json every 10 seconds to update the layer text.

This question also applies to updating the associate ScreenSaver info.

Here is the Setup of the canvas


Function SetupFramedCanvas()
m.canvas.AllowUpdates(true)
m.canvas.Clear()
m.canvas.SetLayer(0, [
{ 'Background:
Url: m.background
CompositionMode: "Source"
},

])
m.paint()
End Function



Here is my original call:


Function PaintFramedCanvas()
jsonRequest = CreateObject("roUrlTransfer")
jsonRequest.SetURL("http://URLTOJSON")
guide = ParseJson(jsonRequest.GetToString())
print "Album art: "+guide.album_art.src
print guide

list = []
mode = CreateObject("roDeviceInfo").GetDisplayMode()
' print "m.streamPlaying: "+m.streamPlaying
print m.progress
if m.progress < 95
list.Push({
Color: "#000000"
TargetRect: { x: 75, y: 475, w: 200, h: 100 }
})
list.Push({
Text: "Loading..." + m.progress.tostr() + "%"
TargetRect: { x: 75, y: 475, w: 200, h: 100 }
})
else 'Audio is currently playing
if m.paused
list.Push({
Color: "#ffffff"
TargetRect: { x: 75, y: 475, w: 200, h: 100 }
CompositionMode: "Source"
})
if mode = "720p"
list.Push({
url: "pkg:/images/pause_icon_small.png"
TargetRect: { x: 75, y: 475, w: 100, h: 50 }
})
else
list.Push({
url: "pkg:/images/pause_icon_small.png"
TargetRect: { x: 75, y: 475, w: 100, h: 50 }
})
end if
else if m.overlay
list.Push({
Color: "#ffffff"
TargetRect: { x: 75, y: 475, w: 200, h: 100 }
CompositionMode: "Source"
})
else 'not paused
list.Push({
Color: "#ffffff"
TargetRect: { x: 75, y: 475, w: 200, h: 100 }
CompositionMode: "Source"
})
end if

if guide.album_art.src = ""
imageUrl = ""
imageRect = ""
else
imageUrl = "http://URLTOSTREAMARTWORK?u="+guide.album_art.src+""
imageRect = { x: 55, y: 256, w: 180, h: 180 }
end if
'****MetaData
if mode = "720p"
list.Push({
url: imageUrl
TargetRect: imageRect
})
list.Push({
Text: "Title: "+guide.title
TargetRect: { x: 350, y: 225, w: 430, h: 90 }
TextAttrs: { font: "small", halign: "left", valign: "center", color: m.textcolor }
})
list.Push({
Text: "Album: "+guide.album
TargetRect: { x: 350, y: 325, w: 430, h: 80 }
TextAttrs: { font: "small", halign: "left", valign: "center", color: m.textcolor }
})
list.Push({
Text: "Artist: "+guide.artist
TargetRect: { x: 350, y: 425, w: 430, h: 80 }
TextAttrs: { font: "small", halign: "left", valign: "center", color: m.textcolor }
})

else
list.Push({
Text: "Nu"
TargetRect: { x: 443, y: 132, w: 50, h: 55 }
TextAttrs: { font: "s", halign: "right", valign: "center", color: m.textcolor }
})
list.Push({
Text: guide.title
TargetRect: { x: 499, y: 132, w: 193, h: 55 }
TextAttrs: { font: "s", halign: "left", valign: "center", color: m.textcolor }
})
list.Push({
Text: guide.artist
TargetRect: { x: 443, y: 193, w: 50, h: 55 }
TextAttrs: { font: "s", halign: "right", valign: "center", color: m.textcolor }
})
list.Push({
Text: guide.album
TargetRect: { x: 499, y: 193, w: 193, h: 55 }
TextAttrs: { font: "s", halign: "left", valign: "center", color: m.textcolor }
})

end if
end if
m.canvas.SetLayer(1, list)

End Function


Here is the Function to update the Canvas Layer Text


Function UpdateCanvas()

print "Updating 60 seconds"
list = []
mode = CreateObject("roDeviceInfo").GetDisplayMode()

jsonRequest = CreateObject("roUrlTransfer")
jsonRequest.SetURL("http://URLTOJSON")
guide = ParseJson(jsonRequest.GetToString())
print "Album art: "+guide.album_art.src
print guide
print "Update Canvas Request"

if guide.album_art.src = ""
imageUrl = ""
imageRect = ""
else
imageUrl = "http://URLTOARTWORK?u="+guide.album_art.src+""
imageRect = { x: 55, y: 256, w: 180, h: 180 }
end if
'****MetaData
if mode = "720p"
list.Push({
url: imageUrl
TargetRect: imageRect
})
list.Push({
Text: "Title: "+guide.title
TargetRect: { x: 350, y: 225, w: 430, h: 90 }
TextAttrs: { font: "small", halign: "left", valign: "center", color: m.textcolor }
})
list.Push({
Text: "Album: "+guide.album
TargetRect: { x: 350, y: 325, w: 430, h: 80 }
TextAttrs: { font: "small", halign: "left", valign: "center", color: m.textcolor }
})
list.Push({
Text: "Artist: "+guide.artist
TargetRect: { x: 350, y: 425, w: 430, h: 80 }
TextAttrs: { font: "small", halign: "left", valign: "center", color: m.textcolor }
})

else
list.Push({
Text: guide.title
TargetRect: { x: 499, y: 132, w: 193, h: 55 }
TextAttrs: { font: "s", halign: "left", valign: "center", color: m.textcolor }
})
list.Push({
Text: guide.artist
TargetRect: { x: 443, y: 193, w: 50, h: 55 }
TextAttrs: { font: "s", halign: "right", valign: "center", color: m.textcolor }
})
list.Push({
Text: guide.album
TargetRect: { x: 499, y: 193, w: 193, h: 55 }
TextAttrs: { font: "s", halign: "left", valign: "center", color: m.textcolor }
})

end if
m.canvas.SetLayer(1, list)

End Function


Here is my Event Loop


Function EventLoop()
timer=createobject("rotimespan")
timer.mark()

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()
print m.progress
end if


else if timer.totalseconds() > 3
'result=UpdateCanvas()
'print result
UpdateCanvas()




'Playback progress (in seconds):

'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 = 4 '<left>
return -1

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()
if msg.GetInfo() <> invalid print msg.GetInfo();
end if



end while
End Function


Any direction for correcting my code is appreciated.
0 Kudos
4 REPLIES 4
RokuMarkn
Visitor

Re: Time Update of Canvas Layer List

Well, the wait(0) should have a nonzero timeout, so that your code has a chance to check the timer even if no events arrive. Also, the check for the timer should not be inside the "msg <> invalid" block, since the message WILL be invalid when the wait returns due to a timeout.

--Mark
0 Kudos
Biggytv
Visitor

Re: Time Update of Canvas Layer List

Thanks Mark.

My update call is being made on the timer without issue. The error message when I try to update the Layer refers to m.canvas.SetLayer(1, list) in the UpdateCanvas().

The error message is: Interface not a member of BrightScript Component

So I am not clear why the error when my initial PaintedFrameCanvas() worked fine.
0 Kudos
Biggytv
Visitor

Re: Time Update of Canvas Layer List

So my timespan is working in my eventloop and I am getting the new calls to json on a timed basis I can see the new information in debug, but I can't seem to figure out how to push the updates to the Canvas Layer with the new Json information.

What am I missing regarding updating the Canvas Layer? :x :?:

Here is my code:


Function UpdateCanvas()

jsonRequest = CreateObject("roUrlTransfer")
jsonRequest.SetURL("http://ltr.streamon.fm/card")
guide = ParseJson(jsonRequest.GetToString())
print "Album art: "+guide.album_art.src
print guide

m.canvas.Clear()
m.canvas.SetLayer(0, [
{ 'Background:
Url: m.background
CompositionMode: "Source"
},

])
m.paint()

list = []
mode = CreateObject("roDeviceInfo").GetDisplayMode()


if guide.album_art.src = ""
imageUrl = ""
imageRect = ""
else
imageUrl = "http://www.streamon.fm/player/getAlbumArt.php?u="+guide.album_art.src+""
imageRect = { x: 55, y: 256, w: 180, h: 180 }
end if
'****MetaData

if mode = "720p"
list.Push({
url: imageUrl
TargetRect: imageRect
})
list.Push({
Text: "Title: "+guide.title
TargetRect: { x: 350, y: 225, w: 430, h: 90 }
TextAttrs: { font: "small", halign: "left", valign: "center", color: m.textcolor }
})
list.Push({
Text: "Album: "+guide.album
TargetRect: { x: 350, y: 325, w: 430, h: 80 }
TextAttrs: { font: "small", halign: "left", valign: "center", color: m.textcolor }
})
list.Push({
Text: "Artist: "+guide.artist
TargetRect: { x: 350, y: 425, w: 430, h: 80 }
TextAttrs: { font: "small", halign: "left", valign: "center", color: m.textcolor }
})

else
list.Push({
Text: guide.title
TargetRect: { x: 499, y: 132, w: 193, h: 55 }
TextAttrs: { font: "s", halign: "left", valign: "center", color: m.textcolor }
})
list.Push({
Text: guide.artist
TargetRect: { x: 443, y: 193, w: 50, h: 55 }
TextAttrs: { font: "s", halign: "right", valign: "center", color: m.textcolor }
})
list.Push({
Text: guide.album
TargetRect: { x: 499, y: 193, w: 193, h: 55 }
TextAttrs: { font: "s", halign: "left", valign: "center", color: m.textcolor }
})

end if

m.canvas.SetLayer(1, list)

End Function
0 Kudos
Biggytv
Visitor

Re: Time Update of Canvas Layer List

I moved the refresh to the EventLoop and it is work now.

Thanks!
0 Kudos