Search code examples
androidchromecastgoogle-cast

Android Cast Dialog - Pause working, play is not


Having trouble with the cast dialog and a custom receiver. Media is cast and playing, the cast dialog shows the pause icon and hitting pause causes the cast framework to send a message to the receiver which comes through to cast.receiver.MediaManager.onPause(). From there I pause my custom player and call MediaManager.broadcastStatus() which results in the sender's cast dialog button switching from the pause icon to the play icon. However, pressing the play button does nothing. Debugging the Android client I see that MediaSessionCompatApi21.onPause() and .onPlay() are called upon pressing the button but only pause is sending anything to the receiver. Any idea why the framework is not causing the cast.receiver.MediaManager.onPlay() function to be called on the receiver?

This happens with support:7.25.2 / play-services:10.2.0 or support:7.24.4 / play-services:9.4.0. I'm clearly not understanding something basic..

Another possibly related thing I noticed somewhat randomly, both on my app and the CastVideos-android app, is that commenting out the mediarouter compile line in the gradle file results in a runnable build but the cast dialog pause function is broken too. Everything else cast related works fine though. Painfully confusing..

UPDATE: I ran CastVideos-android app against my custom receiver (not playing any media but simulating the messaging) and the play/pause works fine. Starting to believe this is a build issue..


Solution

  • Looking more closely at the latest CastVideos-android sample solved the problem. Given a dummy MediaInfo instance X, I was calling
    _remoteMediaClient.load(X);

    Seemed pretty reasonable but it wasn't working for the cast dialog play problem. Using MediaQueueItem (from looking at the latest CastVideos-android version) fixed it...
    MediaQueueItem qi = new MediaQueueItem.Builder(X).setAutoplay(true).setPreloadTime(20).build(); MediaQueueItem[] qa = new MediaQueueItem[]{qi}; _remoteMediaClient.queueLoad(qa,0,MediaStatus.REPEAT_MODE_REPEAT_OFF, null);