Closing roimagecanvas on rovideoscreen restarts the Roku box

Hi,

I am trying to overlay text on videos streamed through rovideoscreen.

This is the code:


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]

    'Swap the commented values below to play different video clips...
'    urls = ["http://video.ted.com/talks/podcast/CraigVenter_2008_480.mp4"]
 '   qualities = ["HD"]
  '  StreamFormat = "mp4"
  '  title = "Craig Venter Synthetic Life"
    srt = "" '"file://pkg:/source/craigventer.srt"

    'urls = ["http://video.ted.com/talks/podcast/DanGilbert_2004_480.mp4"]
    'qualities = ["HD"]
    'StreamFormat = "mp4"
    'title = "Dan Gilbert asks, Why are we happy?"

     'Apple's HLS test stream
   ' urls = ["http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]
    'qualities = ["SD"]
    'streamformat = "hls"
    'title = "Apple BipBop Test Stream"

    ' Big Buck Bunny test stream from Wowza
    urls = ["http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"]
    qualities = ["SD"]
    streamformat = "hls"
    title = "Big Buck Bunny"

    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

    m.canvas = CreateObject("roImageCanvas")
    m.canvas.SetMessagePort(p)
    'm.canvas.SetLayer(0, { Color: "#000000" })

    m.paused = false

'Resolution-specific settings:
    mode = CreateObject("roDeviceInfo").GetDisplayMode()
    if mode = "720p"
        m.layout = {
            full:   m.canvas.GetCanvasRect()
            top:    { x:   0, y:   0, w:1280, h: 130 }
            left:   { x: 249, y: 177, w: 391, h: 291 }
            right:  { x: 700, y: 177, w: 350, h: 291 }
            bottom: { x: 249, y: 500, w: 780, h: 300 }
        }
    else
        m.layout = {
            full:   m.canvas.GetCanvasRect()
            top:    { x:   0, y:   0, w: 720, h:  80 }
            left:   { x: 100, y: 100, w: 280, h: 210 }
            right:  { x: 400, y: 100, w: 220, h: 210 }
            bottom: { x: 100, y: 340, w: 520, h: 140 }
        }
    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 msg.isRemoteKeyPressed()
                index = msg.GetIndex()
        print "Remote button pressed: " + index.tostr()
        if index = 13  or index = 6'<PAUSE/PLAY>
                    if m.paused
                        m.canvas.close()
                        video.Resume()
                        m.paused = false
                        else video.Pause()
                    end if
                end if
        end if
        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 if msg.isPaused()
                m.paused = true
                list = []
                color = "#80000000" 'semi-transparent black
                list.Push({
                Text: "Paused"
                TextAttrs: { font: "huge" }
                TargetRect: m.layout.full
        })
        '        m.canvas.SetLayer(0, { Color: color, CompositionMode: "Source" })
                 m.canvas.SetLayer(1, list)
                 m.canvas.show()

        else
                print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
            endif
        end if
    end while
    print "Not working - Sara";
End Function

When I try to close the canvas and use normally the inbuilt controls of rovideoscreen.It shows “Paused” on paused and then when we Resume, it shows the progress bar of rovideoscreen and then restarts the roku box.

Basically I want to create a roimagecanvas to overlay text but not programmatically code the remote key events after that. So i want to destroy it, and then continue with the inbuilt controls, and then again create a roimagecanvas to overlay again some text at some later point of time. I am just trying out this for the first time, so your pointers would be well appreciated. How else do I change this code to do what I want?