Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jvalero
Visitor

Custom Remote Commands w/ roImageCanvas

I've had mixed success trying to setup custom remote actions using isRemoteKeyPressed() on my roImageCanvas object that is running underneath my roVideoPlayer object. I am able to successfully register remote key presses, I've been able to set <LEFT> to restart from the beginning of the video using

position = 0
player.Seek(position)


However, I'm having trouble with the other three actions I am trying to setup.

For <RIGHT> I want to skip to the next item in the Video Player playlist. As I haven't been able to find a built in function to do this for me, I've tried the following:

position = playList[currentIndex].Length.toInt()
player.Seek(position * 1000)


This does seem to jump forward, but for some reason it won't jump to the end of the video like I want it to. And I've checked to make sure the values are lining up by printing them to the console.

See the following log snippet:

Playlist #:  0
Current Position: 0
Current Video Length: 25
msg = | index = 1
Playlist #: 0
Current Position: 1
Current Video Length: 25
Remote button pressed: 5
Button Length: 25


Current Length = The length in seconds that the current video playing is.
Button Length = The value in seconds that the the forward press should be using to determine Seek() position e.g. player.Seek(25 * 1000)

As you can see these values are the same, but for some reason it does not jump to the end. It seemingly jumps to a random position on each video, but jumps to the same position if I press more than once on same video.

For the <FFWD> and <REV> I have the following:

Else If index = 8  '// <REV>

position = m.position - 5
player.Seek(position * 1000)

Else If index = 9 '// <FWD>

position = m.position + 5
player.Seek(position * 1000)


As you can see I am trying to increment + or - 5 seconds for each push. However, <REV> starts from the beginning of the video and <FFWD> again jumps to random position for each video.

For clarity sake here is my entire Event Loop

'// Listen For Events On Message Port
While True

msg = wait(0, messagePort)

'// Image Canvas Events
If Type(msg) = "roImageCanvasEvent" Then

'// Listen For Remote Keys
If msg.isRemoteKeyPressed()

index = msg.GetIndex()

Print "Remote button pressed: " + index.toStr()

If index = 4 '// <LEFT>

'// Jump To Start Of Video
m.position = 0
player.Seek(m.position)

Else If index = 5 '// <RIGHT>

Print "Button Length: "; m.playList[m.currentIndex].Length
'// Jump To Next Video
position = m.playList[m.currentIndex].Length.toInt()
player.Seek((position - 1) * 1000)

Else If index = 8 '// <REV>

position = m.position - 5
player.Seek(position * 1000)

Else If index = 9 '// <FWD>

position = m.position + 5
player.Seek(position * 1000)

End If

End If

End If

'// Video Player Events
If Type(msg) = "roVideoPlayerEvent" Then

'// Output Status Message
Print "msg = "; msg.GetMessage() " | index = "; msg.GetIndex()
Print "Playlist #: "; m.currentIndex

If msg.isStreamStarted()

Print "Stream Started"

Else If msg.isScreenClosed()

'// Output Message And Exit Loop
Print "Screen Closed"
Exit While

Else If msg.isRequestFailed()

Print "Video request failure: "; msg.GetIndex(); " " msg.GetData()

Else If msg.isStatusMessage()

Print "Video status: "; msg.GetIndex(); " " msg.GetData()

Else If msg.isPlaybackPosition() Then

m.position = msg.GetIndex()
checkPosition = m.position

Print "Current Position: "; m.position
Print "Current Video Length: "; m.playList[m.currentIndex].Length

If checkPosition.toStr() = m.playList[m.currentIndex].Length

m.currentIndex = m.currentIndex + 1
playAd(m.acudeoPolicyId)

End If

Else

Print "Unexpected event type: "; msg.GetType()

End If

End If

End While
0 Kudos
2 REPLIES 2
TheEndless
Channel Surfer

Re: Custom Remote Commands w/ roImageCanvas

To jump to the next video, you should be able to call SetNext(nextIndex) followed by Play(). You can get the nextIndex by tracking the IsListItemSelected() event, which I don't think is documented for the roVideoPlayer, but it's the same as for roAudioPlayer.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
jvalero
Visitor

Re: Custom Remote Commands w/ roImageCanvas

Thanks, that did the trick. I had a feeling there was some undocumented items with some of the components. Appreciate all of the help. 🙂
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.