How to update the volume indicator provided by the MinimalMediaRouteProvider

独自空忆成欢 提交于 2019-12-23 10:53:14

问题


When registering the MinimalMediaRouteProvider/MediaRouteButton from Androids Chromecast SDK, we get a standard dialog for connecting to existing Cromecast Devices. Once connected to the device, same dialog also provides a way to set the volume using a draggable seek bar. I am having trouble synchronizing the position of this volume seek bar with the actual volume that is already set in the Chromecast device.

As part of registering the MinimalMediaRouteProvider we provide a com.google.cast.MediaRouteAdapter implementation. The onSetVolume(volume) of this interface is called when the user drags the volume seekBar above. This gives us a god way to update the volume level of the connected chromecast channel by using messageStream.setVolume(volume).

The problem is that once we update the volume, there is no way to tell back the MinimalMediaRouteProvider UI that the volume has changed so it can position itself accordingly - currently it always shows the volume as 0.

What is the proper way to notify the MinimalMediaRouteProvider about the current volume level so it can update its volume UI?

Looking at the MediaRoute sample included with support library 7, there seem to be a way to create MediaRouteDescriptor, update the volume there and thus communicate this back to the MediaRouteProvider, but but it is not very clear how to do this in the content of Chromecast/MinimalMediaRouteProvider.


回答1:


You can call MediaRouteStateListener.onVolumeChanged() to update the volume seekbar.

I have a more detailed answer here: https://stackoverflow.com/a/18867128/1334870




回答2:


To get volume immediately from VideoCastManager:

mVolume = (int) (mCastManager.getVolume() * 100) // cast volume is double

To receive system-based volume changes in the receiver (i.e. the on-screen volume slider pop-up, other connected devices changing the volume), you'll need to add a cast consumer in your controller activity:

private VideoCastConsumerImpl mCastConsumer = new VideoCastConsumerImpl() {

    public void onVolumeChanged(double volume, boolean isMute)
    {
        mVolumeSeekBar.setProgress((int) (volume *100));
    }
};

For more details:

Android Sender App Development (Aug '14)



来源:https://stackoverflow.com/questions/18323387/how-to-update-the-volume-indicator-provided-by-the-minimalmediarouteprovider

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!