I’m working on a simple custom video player for live video. All it will do is present a buffering screen with a semi-transparent black screen with white text, and otherwise just show the video. I used much of the sample code from the SDK. Here’s some of what I have:
Function ShowPlayer(video)
port = CreateObject("roMessagePort")
canvas = CreateObject("roImageCanvas")
canvas.AllowUpdates(false)
canvas.SetMessagePort(port)
canvas.SetLayer(0, { Color: "#000000"})
canvas.AllowUpdates(true)
canvas.Show()
player = CreateObject("roVideoPlayer")
player.SetMessagePort(port)
player.SetPositionNotificationPeriod(1)
player.SetContentList([video])
player.Play()
' Tracks startup progress
progress = 0
'Number of seconds of actual video playback
totalPlaybackTime = CreateObject("roInt")
totalPlaybackTime.setInt(0)
while true
msg = wait(0, port)
if type(msg) = "roVideoPlayerEvent"
if msg.isStatusMessage()
if msg.GetMessage() = "startup progress"
curProgress% = msg.getIndex() / 10
if progress <> curProgress%
progress = curProgress%
PaintFullscreenCanvas(canvas, progress)
end if
end if
end if
end if
end while
End Function
Sub PaintFullscreenCanvas(canvas, progress)
list = []
if progress < 100
color = "#CC000000" ' Overlay on the existing video
list.Push({
Text: "Buffering: " + progress.tostr() + "%"
TextAttrs: { font: "Medium" }
TargetRect: canvas.GetCanvasRect()
})
else
color = "#00000000" 'fully transparent
end if
canvas.AllowUpdates(false)
canvas.SetLayer(0, { Color: color, CompositionMode: "Source" })
canvas.SetLayer(1, list)
canvas.AllowUpdates(true)
End Sub
Note I removed a bunch of irrelevant code that handles other events on the video port.
So, when the screen first comes up, it seems to flicker a bit as it displays the all black canvas. It loads from top to bottom and there’s almost always a noticeable flicker as it seems to render half of it or so and then the other half. The same thing happens when the “buffering” screen is removed as the canvas goes back to fully transparent.
On the latest Roku it’s not really noticeable at all, but on an older Roku LT it’s very noticeable. In fact on that one, the video starts playing before the canvas screen clears to transparent.
Any tips or ideas on how to remove all that flicker and have it all render at once?
