Volume button not controlling casting device volume from android sender app using cast-sdk v3 by default

做~自己de王妃 提交于 2019-12-08 07:29:07

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/53500578/volume-button-not-controlling-casting-device-volume-from-android-sender-app-usin

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