android - 默认情况下,音量按钮不使用 cast-sdk v3 从 android 发件人应用程序控制投射设备音量
问题描述
我在我的 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
设置为活动状态,就会发生这种情况。投射或远程播放时,应使其处于非活动状态。
推荐阅读
- reflex - 前端类型的 Monadwidget
- r - Str_Extract 问题:缺少模式
- c++ - 如何使用抽象对象数组?无效的抽象类型错误
- android - Facebook connect Android - 生成无过期令牌
- php - 如何编写基于用户角色的重定向?
- swift - Swift:无法释放内存
- java - 我们期望 Ignite 什么时候触发 EVT_CACHE_ENTRY_CREATED 和 EVT_CACHE_OBJECT_PUT 事件
- css - 在悬停和聚焦时更改 Mat Expansion 中内容的颜色
- android - 代号一键盘封面图片
- ruby - 如何使用带有 RSpec 模拟的冰糕类型检查?