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.