Search code examples
androidchromecast

How to determine media completion in VideoCastControllerActivity?


In my app, I am using the CastCompanionLibrary to cast videos to a chromecast device. I want to perform some action when the video has finished playing. How do I determine as to when the video has completed playing? I did not find any suitable callback for this.


Solution

    1. Register a VideoCastConsumer that implements onRemoteMediaPlayerStatusUpdated(). This will inform you when the playback status changes.
    2. In that callback, get the mediaStatus = mCastManager.getMediaStatus(); this will give you the updated status.
    3. If mediaStatus == MediaStatus.PLAYER_STATE_IDLE and mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED, then it means the currently playing item is just finished.

    Note that a version of this is already being done in the associated fragment so please tell us what you are doing exactly; what I suggested allows you to generically find out when the playback of a single media items reaches its end.