com.google.android.gms.cast.framework.SessionManagerListener Java Examples

The following examples show how to use com.google.android.gms.cast.framework.SessionManagerListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalPlayerActivity.java    From CastVideos-android with Apache License 2.0 4 votes vote down vote up
private void setupCastListener() {
    mSessionManagerListener = new SessionManagerListener<CastSession>() {

        @Override
        public void onSessionEnded(CastSession session, int error) {
            onApplicationDisconnected();
        }

        @Override
        public void onSessionResumed(CastSession session, boolean wasSuspended) {
            onApplicationConnected(session);
        }

        @Override
        public void onSessionResumeFailed(CastSession session, int error) {
            onApplicationDisconnected();
        }

        @Override
        public void onSessionStarted(CastSession session, String sessionId) {
            onApplicationConnected(session);
        }

        @Override
        public void onSessionStartFailed(CastSession session, int error) {
            onApplicationDisconnected();
        }

        @Override
        public void onSessionStarting(CastSession session) {
        }

        @Override
        public void onSessionEnding(CastSession session) {
        }

        @Override
        public void onSessionResuming(CastSession session, String sessionId) {
        }

        @Override
        public void onSessionSuspended(CastSession session, int reason) {
        }

        private void onApplicationConnected(CastSession castSession) {
            mCastSession = castSession;
            if (null != mSelectedMedia) {

                if (mPlaybackState == PlaybackState.PLAYING) {
                    mVideoView.pause();
                    loadRemoteMedia(mSeekbar.getProgress(), true);
                    return;
                } else {
                    mPlaybackState = PlaybackState.IDLE;
                    updatePlaybackLocation(PlaybackLocation.REMOTE);
                }
            }
            updatePlayButton(mPlaybackState);
            invalidateOptionsMenu();
        }

        private void onApplicationDisconnected() {
            updatePlaybackLocation(PlaybackLocation.LOCAL);
            mPlaybackState = PlaybackState.IDLE;
            mLocation = PlaybackLocation.LOCAL;
            updatePlayButton(mPlaybackState);
            invalidateOptionsMenu();
        }
    };
}
 
Example #2
Source File: LocalPlayerActivity.java    From cast-videos-android with Apache License 2.0 4 votes vote down vote up
private void setupCastListener() {
    mSessionManagerListener = new SessionManagerListener<CastSession>() {

        @Override
        public void onSessionEnded(CastSession session, int error) {
            onApplicationDisconnected();
        }

        @Override
        public void onSessionResumed(CastSession session, boolean wasSuspended) {
            onApplicationConnected(session);
        }

        @Override
        public void onSessionResumeFailed(CastSession session, int error) {
            onApplicationDisconnected();
        }

        @Override
        public void onSessionStarted(CastSession session, String sessionId) {
            onApplicationConnected(session);
        }

        @Override
        public void onSessionStartFailed(CastSession session, int error) {
            onApplicationDisconnected();
        }

        @Override
        public void onSessionStarting(CastSession session) {
        }

        @Override
        public void onSessionEnding(CastSession session) {
        }

        @Override
        public void onSessionResuming(CastSession session, String sessionId) {
        }

        @Override
        public void onSessionSuspended(CastSession session, int reason) {
        }

        private void onApplicationConnected(CastSession castSession) {
            mCastSession = castSession;
            if (null != mSelectedMedia) {

                if (mPlaybackState == PlaybackState.PLAYING) {
                    mVideoView.pause();
                    loadRemoteMedia(mSeekbar.getProgress(), true);
                    return;
                } else {
                    mPlaybackState = PlaybackState.IDLE;
                    updatePlaybackLocation(PlaybackLocation.REMOTE);
                }
            }
            updatePlayButton(mPlaybackState);
            invalidateOptionsMenu();
        }

        private void onApplicationDisconnected() {
            updatePlaybackLocation(PlaybackLocation.LOCAL);
            mPlaybackState = PlaybackState.IDLE;
            mLocation = PlaybackLocation.LOCAL;
            updatePlayButton(mPlaybackState);
            invalidateOptionsMenu();
        }
    };
}
 
Example #3
Source File: VideoDetailsFragment.java    From Loop with Apache License 2.0 4 votes vote down vote up
private void setupCastListener() {
        sessionManagerListener = new SessionManagerListener<CastSession>() {

            @Override
            public void onSessionEnded(CastSession session, int error) {
                onApplicationDisconnected();
            }

            @Override
            public void onSessionResumed(CastSession session, boolean wasSuspended) {
                onApplicationConnected(session);
            }

            @Override
            public void onSessionResumeFailed(CastSession session, int error) {
                onApplicationDisconnected();
            }

            @Override
            public void onSessionStarted(CastSession session, String sessionId) {
                onApplicationConnected(session);
            }

            @Override
            public void onSessionStartFailed(CastSession session, int error) {
                onApplicationDisconnected();
            }

            @Override
            public void onSessionStarting(CastSession session) {
            }

            @Override
            public void onSessionEnding(CastSession session) {
            }

            @Override
            public void onSessionResuming(CastSession session, String sessionId) {
            }

            @Override
            public void onSessionSuspended(CastSession session, int reason) {
            }

            private void onApplicationConnected(CastSession session) {
                castSession = session;
//                castSession.getRemoteMediaClient().addListener(remoteMediaClientListener);

                location = PlaybackLocation.REMOTE;

                pauseLocalVideo();
                thumbnailImageView.animate().alpha(1.0f).setDuration(1000);
                castInfoTextView.setText(getString(R.string.connecting_to_receiver));
                castInfoTextView.setVisibility(View.VISIBLE);

                if(!TextUtils.isEmpty(videoUrl)){
                    if (playbackState == PlaybackState.PLAYING) {
                        loadRemoteMedia(exoPlayer.getCurrentPosition(), true);
                    } else if(playbackState == PlaybackState.PAUSED){
                        loadRemoteMedia(exoPlayer.getCurrentPosition(), false);
                    }
//                else {
//                    playbackState = PlaybackState.IDLE;
//                }
                }

            }

            private void onApplicationDisconnected() {
                castSession = null;

                location = PlaybackLocation.LOCAL;
//                playbackState = PlaybackState.IDLE;
                thumbnailImageView.animate().alpha(0.0f).setDuration(1000);
                castInfoTextView.setVisibility(View.GONE);

                updateLocalVideoVolume(1.0f);
            }
        };
    }