问题
I'm developing an app for Android that streams content to a Chromecast device. I did not find the documentation about the way to change the volume of the remote media player when the app is in the background.
回答1:
Look at the method setUpRemoteControl()
in VideoCastManager
class, in CCL; it is mostly done there.
回答2:
It was enough to call:
mediaRouter.addRemoteControlClient(mRemoteControlClient);
where:
mMediaRouter = MediaRouter.getInstance(context);
回答3:
Per the CastCompanionLibrary detailed documentation:
CCL can provide default lock screen controllers based on the RemoteControlClient. If desired, this feature needs to be enabled at the initialization time of the VideoCastManager. When this feature is enabled, a Play/Pause button will be shown on Android devices running Jelly Bean or above. On KitKat devices, the layout of the lock screen controllers is different and uses a full-screen album art while on Jelly Bean it is a small version of the album art.
In addition, when this feature is enabled, CCL provides the ability for users to control the Cast device’s system’s volume even if the application is in the background. On KitKat devices, it provides that capability even if the screen is off
For the CastVideos-android sample, they do that in CastApplication immediately after intialization of VideoCastManager
:
mCastMgr.enableFeatures(
VideoCastManager.FEATURE_NOTIFICATION |
VideoCastManager.FEATURE_LOCKSCREEN |
VideoCastManager.FEATURE_DEBUGGING);
来源:https://stackoverflow.com/questions/24330912/set-volume-with-chromecast-when-android-app-is-in-the-background