从 Chromecast 接收器获取静音事件的正确回调是什么?
What is the correct callback to get mute events from the Chromecast Receiver?
我 运行 遇到一个问题,当两个设备连接到同一个投射会话并且从设备 1 调用 BaseCastManager.setDeviceMute()
时,设备 2 没有收到 MediaCallback.onRouteVolumeChanged()
正确的做法是什么?是否有不同的回调?
这是最终调用的内容。
/**
* 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);
}
}
这是我的听众:
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());
}
}
您需要监听回调onVolumeChanged
of Cast.Listener
:
public void onVolumeChanged ()
Called when the device's volume or mute state has changed.
由于您使用的是 Cast Companion Library,因此您可以通过扩展 VideoCastConsumerImpl
来使用回调 VideoCastConsumer#onVolumeChanged(double value, boolean isMute)
,覆盖该方法并将其注册到 VideoCastManager
(并在未注册时取消注册不再需要):
VideoCastConsumer myConsumer = new VideoCastConsumerImpl() {
void onVolumeChanged(double value, boolean isMute) {
// do as you wish here
}
}
VideoCastManager.getInstance().addVideoCastConsumer(myConsumer);
我 运行 遇到一个问题,当两个设备连接到同一个投射会话并且从设备 1 调用 BaseCastManager.setDeviceMute()
时,设备 2 没有收到 MediaCallback.onRouteVolumeChanged()
正确的做法是什么?是否有不同的回调?
这是最终调用的内容。
/**
* 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);
}
}
这是我的听众:
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());
}
}
您需要监听回调onVolumeChanged
of Cast.Listener
:
public void onVolumeChanged ()
Called when the device's volume or mute state has changed.
由于您使用的是 Cast Companion Library,因此您可以通过扩展 VideoCastConsumerImpl
来使用回调 VideoCastConsumer#onVolumeChanged(double value, boolean isMute)
,覆盖该方法并将其注册到 VideoCastManager
(并在未注册时取消注册不再需要):
VideoCastConsumer myConsumer = new VideoCastConsumerImpl() {
void onVolumeChanged(double value, boolean isMute) {
// do as you wish here
}
}
VideoCastManager.getInstance().addVideoCastConsumer(myConsumer);