0

I'm running into an issue where, when two devices are connected to the same cast session and when BaseCastManager.setDeviceMute() is called from device 1, device 2 does not receive a MediaCallback.onRouteVolumeChanged()

What's the proper way to do this? Is there perhaps a different callback?

Here's what eventually gets called.

/**
 * Mutes or un-mutes the device volume.
 *
 * @throws CastException
 * @throws NoConnectionException
 * @throws TransientNetworkDisconnectionException
 */
public final void setDeviceMute(boolean mute) throws CastException,
        TransientNetworkDisconnectionException, NoConnectionException {
    checkConnectivity();
    try {
        Cast.CastApi.setMute(mApiClient, mute);
    } catch (IOException e) {
        throw new CastException("setDeviceMute", e);
    } catch (IllegalStateException e) {
        throw new NoConnectionException("setDeviceMute()", e);
    }
}

Here's my listener:

private class MediaCallBack extends android.support.v7.media.MediaRouter.Callback {
        @Override
        public void onRouteVolumeChanged(MediaRouter router,
                                         RouteInfo route) {
            super.onRouteVolumeChanged(router, route);
            onVolumeChanged(route.getVolume());
        }


    }
Nelson Ramirez
  • 7,864
  • 7
  • 28
  • 34

2 Answers2

2

You need to listen to the callback onVolumeChanged of Cast.Listener:

public void onVolumeChanged ()

Called when the device's volume or mute state has changed.

Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
1

Since you are using Cast Companion Library, you can use the callback VideoCastConsumer#onVolumeChanged(double value, boolean isMute) by extending VideoCastConsumerImpl, overriding that method and registering it with the VideoCastManager(and unregister it when not needed anymore):

VideoCastConsumer myConsumer = new VideoCastConsumerImpl() {
   void onVolumeChanged(double value, boolean isMute) {
       // do as you wish here
   }
}

VideoCastManager.getInstance().addVideoCastConsumer(myConsumer);
Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28
  • this is what I'm currently doing but onVolumeChanged does not get triggered when we mute the receiver. – Nelson Ramirez May 09 '16 at 16:55
  • From what you have posted, you are not doing that; you are listening on MediaRouter.Callback and not Cast.Listener (or using CCL, which amounts to the same thing). One more thng: if you are using CCL, don't try to register to Cast events directly, use CCL's callbacks and APIs – Ali Naddaf May 09 '16 at 17:27