Roku: Fix for live video delay
The first time you implement live video playback in your Roku app and then go to try it out, you invariably find that the video is starting from some other point than the current live position. This one trips a lot of folks up (see here, here, here, and here), but luckily it has an easy solution.
The trick is to set the PlayStart
field of the ContentNode
that you pass to video.content
. Roku's docs say that "PlayStart defines the start position of the content, in seconds." Ok - but what is the start position of a live stream? There are ways to actually calculate it, but most folks find that it is easier to simply set it to "a sufficiently large number". What constitutes a sufficiently large number? Many folks use 99999 or something like that, but since PlayStart
is an int
, the largest possibly value it can take it is 2147483647, so that is what I use - just to be safe 😎
content = CreateObject("roSGNode", "ContentNode")
content.setFields({
streamformat: "hls"
url: "http://your.video.url"
live: true
playstart: 2147483647
})
video.content = content