Search code examples
androidchromecastvolumegoogle-cast

Chromecast SDK 3.0, Custom Receiver, Volume


Have migrated from cast sdk2 to 3 but now not sure how to handle cast volume with a custom receiver. Can send messages to adjust the receiver volume ok by catching hardware volume key events, but this occurs without visual volume slider feedback on the sender. If I don't catch events and don't send messages the hardware volume buttons just control the ringer volume (with visual feedback). Anyone figured this out?


Solution

  • For a truely custom receiver, create a cast.receiver.media.Player object on the receiver (implement all the cast.receiver.media.Player functions) and pass it to the instance of cast.receiver.MediaManager. From the sender, bind to this with CastSession.getRemoteMediaClient(). Now call RemoteMediaClient.load/play in addition to my custom messaging load/plays and this fools the sender into behaving correctly. Now the cast framework controls volume, notifications etc as with the CastVideos-android app. You'll also have to have the receiver provide the necessary state on the server in the cast.receiver.media.Player.getState() function (ie. return "PLAYING | "PAUSED" | "IDLE" | "BUFFERING")