我试图在播放视频时在roku视频播放器上显示图像,但它不起作用。这是我的代码:
function player(video_id as String,stream as String,streamTitle as String,subtitle_url as String,position as String)
print "play: "+stream
p = CreateObject("roMessagePort")
video = CreateObject("roVideoScreen")
video.setMessagePort(p)
videoclip = CreateObject("roAssociativeArray")
videoclip.StreamBitrates = [0]
videoclip.StreamUrls = [stream]
di = CreateObject("roDeviceInfo")
if di.GetDisplayType() = "HDTV" then
videoclip.streamqualities=["HD"]
else
videoclip.streamqualities=["SD"]
end if
videoclip.PlayStart=position.toint()
videoclip.StreamFormat = "hls"
videoclip.switchingstrategy="full-adaptation"
videoclip.Title = streamTitle
if subtitle_url<>invalid
videoclip.SubtitleUrl = subtitle_url
end if
lastSavedPos = 0
statusInterval = 10
nowpos=0
video.SetPositionNotificationPeriod(10)
video.SetContent(videoclip)
video.show()
showImageCanvas()
while true
msg = wait(0, video.GetMessagePort())
if type(msg) = "roVideoScreenEvent"
if msg.isScreenClosed() then 'ScreenClosed event
return "incomplete"
exit while
else if msg.isFullResult()
SetXtraData(video_id,"0")
return "completed"
else if msg.isResumed()
SetXtraData(video_id,nowpos.tostr())
else if msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
if nowpos > 120
if abs(nowpos - lastSavedPos) > statusInterval
lastSavedPos = nowpos
SetXtraData(video_id,nowpos.tostr())
end if
end if
else if msg.isRequestFailed()
showMessage("Information","Something went wrong while we tried to play the video")
else
print "Unknown event: "; msg.GetType(); " msg: "; msg.GetMessage()
showImageCanvas()
endif
end if
end while
end function
Sub showImageCanvas()
canvasItems = [
{
url:"http://www.rd.com/wp-content/uploads/sites/2/2016/04/01-cat-wants-to-tell-you-laptop.jpg"
TargetRect:{x:189,y:300,w:100,h:100}
}
]
canvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
canvas.SetMessagePort(port)
'Set opaque background
'canvas.SetLayer(0, {Color:"#FF000000", CompositionMode:"Source"})
canvas.SetRequireAllImagesToDraw(true)
canvas.SetLayer(1, canvasItems)
canvas.Show()
while(true)
msg = wait(0,port)
if type(msg) = "roImageCanvasEvent" then
if (msg.isRemoteKeyPressed()) then
i = msg.GetIndex()
print "Key Pressed - " ; msg.GetIndex()
if (i = 2) then
' Up - Close the screen.
canvas.close()
end if
else if (msg.isScreenClosed()) then
print "Closed"
return
end if
end if
end while
End Sub
我一直把这个showImageCanvas()
放在任何地方试图让它工作,但它不起作用。请帮忙。