1
votes

Based on the CastVideos sample for Android (https://github.com/googlecast/CastVideos-android), I am developing a video library app that will casts videos to a styled receiver on my Chromecast.

I want to implement a loop functionality. When the user clicks on a button, it activates video looping when it's casting. Is there a way to make that possible ? Any listener in the Cast SDK that I haven't found and that can make me able to play the video when it finishes ?

1

1 Answers

1
votes

You have a few options. If you want to stick to a Styled receiver, then you have at least the following two options:

  • Listen for media playback to finish and then restart the same video (you can seek to the beginning and start playback again). To find out if the media playback has reached the end or not, you can listen for MediaStatus by registering a RemoteMediaClient.Listener. The onStatusUpdate() should inform you when the Media Status has changed and you can obtain the status and if it is IDLE with reason FINISHED, that is your hint.
  • A second option is to form a queue, of one element, and load the queue by calling queueLoad and set the repeatMode to, say, REPEAT_MODE_REPEAT_SINGLE. That then handles repeating the same item when it reaches the end by the framework without you doing anything additional.

If you can write a custom receiver (say, start with the reference player that is on our GitHub repo), then you can set the loop property on the media element yourself.

I believe all of the above solutions produce a bit of a pause when the media reaches the end and before it starts from the beginning. If you truly want a looping solution without such brief pause, you would then need to do some more work and use some approach based on Media Source Extension but that can get a bit tricky.