The next time notification period loop in many instances might be to late. it wont be until the current notification period will it know that it's got 6 seconds, or 2 seconds left...
I have a Wowza Linux server receiving and broadcasting a stream from a windows server using VLC. VLC is playing two hour video files that is made up of different clips. There's a SQL server elsewhere that has recorded what clips start when in that two hour file down to the second.
The Roku box is hitting the Windows to see where it is in it's play duration, hits the SQL server to see what that content is in that particular time, and what the video overlay should be and how long it should be displayed, among other features.
I'll go ahead and post the majority of the code for a short time so you can see what I"m trying to do. I'm not sure that there's any other way to do what I want other than to sleep.
while true
msg = wait(0, port)
if msg <> invalid
'*******************************
'Playback progress (in seconds):
else if msg.isPlaybackPosition() then
if not isSleeping
nowpos = msg.GetIndex()
print "Event type: "; msg.GetType()
print "Playback position: " + nowpos.toStr()
list.clear()
device.clear()
xml.clear()
if (device.overlay <> "") and (device.nextoverlay <> device.overlay) and ((device.timeleft < url.PositionNotificationPeriod) or (device.timeleft - 5 < url.PositionNotificationPeriod)) then
if device.overlayfontcolor <> ""
fadelevel = CreateObject("roByteArray")
fadelevel.fromhexstring(device.overlayfontcolor)
end if
'printaa(device)
overlaytimer = CreateObject("roTimespan")
overlaytimer.Mark()
while true
if overlaytimer.totalseconds() <= device.timeleft then
'********************
'***** Fade Out *****
'********************
if overlaytimer.totalseconds() > 4 then
tempRect = {x: device.overlayX, y: device.overlayY, w: device.overlayW, h:device.overlayH}
tempitems = {
CompositionMode: "Source"
Color: device.overlaycolor
Text: device.overlaytext
TextAttrs: { font: device.overlayfontsize, color: "#" + device.overlayfontcolor, HAlign : device.overlayfontHAlign, VAlign : device.overlayfontVAlign}
TargetRect: tempRect
}
tempcanvas.SetLayer(0, { url: device.overlayurl, Color: "#" + device.overlaycolor, CompositionMode: "Source" })
tempcanvas.SetLayer(1, tempitems)
tempcanvas.show()
'Print "Time left is " + device.timeleft.tostr()
sleep(1000)
elseif overlaytimer.totalseconds()<= 4 then
while fadelevel[0] > 10
'print "Fade level**********"
'print fadelevel[0]
'print "#" + fadelevel.tohexstring()
tempRect = {x: device.overlayX, y: device.overlayY, w: device.overlayW, h:device.overlayH}
tempitems = {
CompositionMode: "Source"
Color: "#" + fadelevel.tohexstring()
Text: device.overlaytext
TextAttrs: { font: device.overlayfontsize, color: "#" + fadelevel.tohexstring(), HAlign : device.overlayfontHAlign, VAlign : device.overlayfontVAlign}
TargetRect: tempRect
}
tempcanvas.SetLayer(0, { url: device.overlayurl, Color: "#" + device.overlaycolor, CompositionMode: "Source" })
tempcanvas.SetLayer(1, tempitems)
tempcanvas.show()
fadelevel[0] = fadelevel[0] - 4
'Print "Time left is " + device.timeleft.tostr()
sleep(39)
end while
sleep(1000)
'exit while
canvas.show()
sleep(device.timeleft + 8 * 1000)
end if
else
'********************
'***** Fade In *****
'********************
print overlaytimer.totalseconds().tostr()
if device.nextoverlay = ""
exit while
else 'if overlaytimer.totalseconds() >= device.timeleft + 3 then
fadelevel = CreateObject("roByteArray")
fadelevel.fromhexstring(device.nextoverlayfontcolor)
i = fadelevel[0]
fadelevel[0] = 0
while fadelevel[0] < (i - 2)
tempRect = {x: device.nextoverlayX, y: device.nextoverlayY, w: device.nextoverlayW, h:device.nextoverlayH}
tempitems = {
CompositionMode: "Source"
Color: device.nextoverlaycolor
Text: device.nextoverlaytext
TextAttrs: { font: device.nextoverlayfontsize, color: "#" + fadelevel.tohexstring(), HAlign : device.nextoverlayfontHAlign, VAlign : device.nextoverlayfontVAlign}
TargetRect: tempRect
}
tempcanvas.SetLayer(0, { url: device.nextoverlayurl, Color: device.nextoverlaycolor, CompositionMode: "Source" })
tempcanvas.SetLayer(1, tempitems)
tempcanvas.show()
fadelevel[0] = fadelevel[0] + 2
'i = i + 2
sleep(39)
end while
exit while
end if
end if
end while
elseif device.overlay <> "" then
tempRect = {x: device.overlayX, y: device.overlayY, w: device.overlayW, h:device.overlayH}
tempitems = {
CompositionMode: "Source"
Color: device.overlaycolor
Text: device.overlaytext
TextAttrs: { font: device.overlayfontsize, color: "#" + device.overlayfontcolor, HAlign : device.overlayfontHAlign, VAlign : device.overlayfontVAlign}
TargetRect: tempRect
}
tempcanvas.SetLayer(0, { url: device.overlayurl, Color: device.overlaycolor, CompositionMode: "Source" })
tempcanvas.SetLayer(1, tempitems)
tempcanvas.show()
else
tempcanvas.Clear()
canvas.Show()
end if
if device.status <> "OK"
Print "Status not OK. Stoping."
viewpost = "...."
http = NewHttp(viewpost)
http.PostFromStringWithTimeout(viewpost, 10)
'sleep(1000)
result = false
exit while
end if
end if
end if
end if
endif
end while