本文介绍了音量按钮默认情况下无法使用Cast-SDK v3从android sender应用控制投射设备的音量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的android发送器应用程序中使用了Cast SDK v3,它运行良好,但是默认情况下,音量控制按钮不控制投射设备的音量.我必须扩大音量控件弹出窗口并调整投射设备的音量.投射会话恢复时,它直接控制设备的音量.但是一旦更改了播放状态,它就会失去焦点.

I am using cast SDK v3 in my android sender app it is working good but the volume controls button doesn't control the casting device's volume by default. I have to expand the volume controls popup and adjust the casting device volume. It is directly controlling the device's volume when cast session resumes. But it loses focus once playback state is changed.

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) {
    }
}

推荐答案

我相信,如果将MediaSessionMediaSessionCompat设置为活动状态,则会发生这种情况.投射时或在远程播放时,应使其处于非活动状态.

I believe this happens if your MediaSession or MediaSessionCompat is set to active. When casting or when playback is remote, it should be made inactive.

这篇关于音量按钮默认情况下无法使用Cast-SDK v3从android sender应用控制投射设备的音量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 20:42