我在我的android sender应用程序中使用cast SDK v3,它运行良好,但音量控制按钮默认不会控制播放设备的音量。我必须展开音量控制弹出窗口并调整铸造设备的音量。当播放会话恢复时,它直接控制设备的音量。但一旦播放状态改变,它就会失去焦点。
private class CastSessionManagerListener implements SessionManagerListener<CastSession> {
@Override
public void onSessionStarting(CastSession session) {
}
@Override
public void onSessionStarted(CastSession session, String sessionId) {
// In case we are casting, send the device name as an extra on MediaSession metadata.
// Now we can switch to CastPlayback
EventHelper.eventFeatureClicked(EventHelper.FEATURE_CHROME_CAST);
Playback playback = new CastPlayback(MusicService.this);
mMediaRouter.setMediaSessionCompat(mSession);
mPlaybackManager.switchToPlayback(playback, true);
}
@Override
public void onSessionStartFailed(CastSession session, int error) {
}
@Override
public void onSessionEnding(CastSession session) {
// This is our final chance to update the underlying stream position
// In onSessionEnded(), the underlying CastPlayback#mRemoteMediaClient
// is disconnected and hence we update our local value of stream position
// to the latest position.
mPlaybackManager.getPlayback().updateLastKnownStreamPosition();
}
@Override
public void onSessionEnded(CastSession session, int error) {
Playback playback = new LocalPlayback(MusicService.this);
mMediaRouter.setMediaSessionCompat(null);
mPlaybackManager.switchToPlayback(playback, true);
}
@Override
public void onSessionResuming(CastSession session, String sessionId) {
}
@Override
public void onSessionResumed(CastSession session, boolean wasSuspended) {
EventHelper.eventFeatureClicked(EventHelper.FEATURE_CHROME_CAST);
Playback playback = new CastPlayback(MusicService.this);
mMediaRouter.setMediaSessionCompat(mSession);
mPlaybackManager.switchToPlayback(playback, true);
}
@Override
public void onSessionResumeFailed(CastSession session, int error) {
}
@Override
public void onSessionSuspended(CastSession session, int reason) {
}
}
我相信如果您的MediaSession
或MediaSessionCompat
设置为活动,就会发生这种情况。当播放或远程播放时,应使其处于非活动状态。