Java Code Examples for com.google.android.gms.cast.MediaStatus#IDLE_REASON_FINISHED
The following examples show how to use
com.google.android.gms.cast.MediaStatus#IDLE_REASON_FINISHED .
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: CastPlayback.java From klingar with Apache License 2.0 | 6 votes |
private static String getIdleReason(int idleReason) { switch (idleReason) { case MediaStatus.IDLE_REASON_NONE: return "IDLE_REASON_NONE"; case MediaStatus.IDLE_REASON_FINISHED: return "IDLE_REASON_FINISHED"; case MediaStatus.IDLE_REASON_CANCELED: return "IDLE_REASON_CANCELED"; case MediaStatus.IDLE_REASON_INTERRUPTED: return "IDLE_REASON_INTERRUPTED"; case MediaStatus.IDLE_REASON_ERROR: return "IDLE_REASON_ERROR"; default: return "UNKNOWN"; } }
Example 2
Source File: VideoCastManager.java From android with Apache License 2.0 | 6 votes |
/** * Toggles the playback of the movie. * * @throws CastException * @throws NoConnectionException * @throws TransientNetworkDisconnectionException */ public void togglePlayback() throws CastException, TransientNetworkDisconnectionException, NoConnectionException { checkConnectivity(); boolean isPlaying = isRemoteMoviePlaying(); if (isPlaying) { pause(); } else { if (mState == MediaStatus.PLAYER_STATE_IDLE && mIdleReason == MediaStatus.IDLE_REASON_FINISHED) { loadMedia(getRemoteMediaInformation(), true, 0); } else { play(); } } }
Example 3
Source File: VideoCastControllerFragment.java From android with Apache License 2.0 | 6 votes |
@Override public void onResume() { LOGD(TAG, "onResume() was called"); try { mCastManager = VideoCastManager.getInstance(getActivity()); boolean shouldFinish = !mCastManager.isConnected() || (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_IDLE && mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED && !mIsFresh); if (shouldFinish) { mCastController.closeActivity(); } mCastManager.addVideoCastConsumer(mCastConsumer); mCastManager.incrementUiCounter(); if (!mIsFresh) updatePlayerStatus(); } catch (CastException e) { // logged already } super.onResume(); }
Example 4
Source File: VideoCastControllerFragment.java From UTubeTV with The Unlicense | 6 votes |
@Override public void onResume() { CastUtils.LOGD(TAG, "onResume() was called"); try { mCastManager = VideoCastManager.getInstance(getActivity()); boolean shouldFinish = !mCastManager.isConnected() || (mCastManager.getPlaybackStatus() == MediaStatus.PLAYER_STATE_IDLE && mCastManager .getIdleReason() == MediaStatus.IDLE_REASON_FINISHED && !mIsFresh); if (shouldFinish) { mCastController.closeActivity(); } mCastManager.addVideoCastConsumer(mCastConsumer); updatePlayerStatus(); mIsFresh = false; mCastManager.incrementUiCounter(); } catch (CastException e) { // logged already } super.onResume(); }
Example 5
Source File: ChromecastBaseControllerFragment.java From SkyTube with GNU General Public License v3.0 | 5 votes |
@Override public void onStatusUpdated() { MediaStatus status = remoteMediaClient.getMediaStatus(); if(status == null) return; int oldState = currentPlayerState; currentPlayerState = status.getPlayerState(); /** If the new playback state is idle and it is because playback finished or was stopped, let the activity * know that playback has stopped. */ if(status.getPlayerState() == MediaStatus.PLAYER_STATE_IDLE && (status.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED || status.getIdleReason() == MediaStatus.IDLE_REASON_CANCELED)) { if(oldState != MediaStatus.PLAYER_STATE_IDLE) { onPlayStopped(); } return; } updateButtons(); if(didSeek) { didSeek = false; chromecastPlaybackProgressBar.setProgress((int)remoteMediaClient.getApproximateStreamPosition()); if(otherControllerFragment != null) otherControllerFragment.setProgress((int)remoteMediaClient.getApproximateStreamPosition()); } /** If the previous playback state of the Chromecast was idle, and it is no longer idle, let the activity * know that playback has started. */ if (oldState == MediaStatus.PLAYER_STATE_IDLE && currentPlayerState != MediaStatus.PLAYER_STATE_IDLE) { currentPlayingMedia = remoteMediaClient.getMediaInfo(); /** * Reset the ProgressBar with the new media, and add a progress listener to update the progress bar. * If the video is under 100 seconds long, it will update every second. If the video is over 16.6 minutes * long, it will update every 10 seconds. Inbetween those, it will update in exactly 100 steps. */ setProgressBarUpdater(); onPlayStarted(); } }
Example 6
Source File: GoogleCastDelegate.java From edx-app-android with Apache License 2.0 | 5 votes |
public void loadRemoteMedia(@NonNull Activity activity, @NonNull DownloadEntry videoEntry, long position, boolean autoPlay) { if (castSession == null || !castSession.isConnected()) { return; } final String videoUrl = videoEntry.getBestEncodingUrl(activity); final RemoteMediaClient remoteMediaClient = castSession.getRemoteMediaClient(); // If remote media player is not idle and playing the same video, don't do anything if (remoteMediaClient == null || (remoteMediaClient.getIdleReason() != MediaStatus.IDLE_REASON_FINISHED && remoteMediaClient.getMediaInfo() != null && remoteMediaClient.getMediaInfo().getContentId().equals(videoUrl))) { return; } // open expanded controls when start the video casting. remoteMediaClient.registerCallback(new RemoteMediaClient.Callback() { @Override public void onStatusUpdated() { final Intent intent = new Intent(activity, ExpandedControlsActivity.class); activity.startActivity(intent); remoteMediaClient.unregisterCallback(this); // Track video is casted on casting device. double currentTime = position / AppConstants.MILLISECONDS_PER_SECOND; analyticsRegistry.trackVideoPlaying(videoEntry.videoId, currentTime, videoEntry.eid, videoEntry.lmsUrl, Analytics.Values.GOOGLE_CAST); } }); // load video media on remote client / media player. remoteMediaClient.load(buildMediaInfo(videoEntry, videoUrl), new MediaLoadOptions.Builder() .setAutoplay(autoPlay) .setPlayPosition(position).build()); }
Example 7
Source File: GoogleCastDelegate.java From edx-app-android with Apache License 2.0 | 5 votes |
@Override public void onStatusUpdated() { super.onStatusUpdated(); if (sessionListener != null && castSession != null) { final RemoteMediaClient remoteMediaPlayer = castSession.getRemoteMediaClient(); if (remoteMediaPlayer != null) { if (remoteMediaPlayer.getPlayerState() == MediaStatus.PLAYER_STATE_IDLE && remoteMediaPlayer.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) { sessionListener.onVideoComplete(); } else if (remoteMediaPlayer.getPlayerState() == MediaStatus.PLAYER_STATE_PLAYING) { sessionListener.onVideoPlaying(); } } } }
Example 8
Source File: VideoCastManager.java From UTubeTV with The Unlicense | 5 votes |
/** * Toggles the playback of the movie. */ public void togglePlayback() throws CastException, TransientNetworkDisconnectionException, NoConnectionException { checkConnectivity(); boolean isPlaying = isRemoteMoviePlaying(); if (isPlaying) { pause(); } else { if (mState == MediaStatus.PLAYER_STATE_IDLE && mIdleReason == MediaStatus.IDLE_REASON_FINISHED) { loadMedia(getRemoteMediaInformation(), true, 0); } else { play(); } } }
Example 9
Source File: CastPlayback.java From klingar with Apache License 2.0 | 4 votes |
private void updatePlaybackState() { int newPlayerState = remoteMediaClient.getPlayerState(); int idleReason = remoteMediaClient.getIdleReason(); Timber.d("updatePlaybackState %s %s", getPlayerState(playerState), getIdleReason(idleReason)); if (newPlayerState == playerState) { return; } playerState = newPlayerState; switch (playerState) { case MediaStatus.PLAYER_STATE_IDLE: if (idleReason == MediaStatus.IDLE_REASON_FINISHED) { if (callback != null) { currentPosition = 0; callback.onCompletion(); } } break; case MediaStatus.PLAYER_STATE_BUFFERING: state = PlaybackStateCompat.STATE_BUFFERING; if (callback != null) { callback.onPlaybackStatusChanged(); } break; case MediaStatus.PLAYER_STATE_PLAYING: state = PlaybackStateCompat.STATE_PLAYING; setMetadataFromRemote(); if (callback != null) { callback.onPlaybackStatusChanged(); } break; case MediaStatus.PLAYER_STATE_PAUSED: state = PlaybackStateCompat.STATE_PAUSED; setMetadataFromRemote(); if (callback != null) { callback.onPlaybackStatusChanged(); } break; default: } }
Example 10
Source File: VideoMediaRouteControllerDialog.java From android with Apache License 2.0 | 4 votes |
private void updatePlayPauseState(int state) { if (null != mPausePlay) { switch (state) { case MediaStatus.PLAYER_STATE_PLAYING: mPausePlay.setImageDrawable(getPauseStopButton()); adjustControlsVisibility(true); break; case MediaStatus.PLAYER_STATE_PAUSED: mPausePlay.setImageDrawable(mPlayDrawable); adjustControlsVisibility(true); break; case MediaStatus.PLAYER_STATE_IDLE: mPausePlay.setVisibility(View.INVISIBLE); setLoadingVisibility(false); if (mState == MediaStatus.PLAYER_STATE_IDLE && mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) { hideControls(true, R.string.no_media_info); } else { switch (mStreamType) { case MediaInfo.STREAM_TYPE_BUFFERED: mPausePlay.setVisibility(View.INVISIBLE); setLoadingVisibility(false); break; case MediaInfo.STREAM_TYPE_LIVE: int idleReason = mCastManager.getIdleReason(); if (idleReason == MediaStatus.IDLE_REASON_CANCELED) { mPausePlay.setImageDrawable(mPlayDrawable); adjustControlsVisibility(true); } else { mPausePlay.setVisibility(View.INVISIBLE); setLoadingVisibility(false); } break; } } break; case MediaStatus.PLAYER_STATE_BUFFERING: adjustControlsVisibility(false); break; default: mPausePlay.setVisibility(View.INVISIBLE); setLoadingVisibility(false); } } }
Example 11
Source File: VideoMediaRouteControllerDialog.java From UTubeTV with The Unlicense | 4 votes |
private void updatePlayPauseState(int state) { if (null != mPausePlay) { switch (state) { case MediaStatus.PLAYER_STATE_PLAYING: mPausePlay.setVisibility(View.VISIBLE); mPausePlay.setImageDrawable(getPauseStopButton()); setLoadingVisibility(false); break; case MediaStatus.PLAYER_STATE_PAUSED: mPausePlay.setVisibility(View.VISIBLE); mPausePlay.setImageDrawable(mPlayDrawable); setLoadingVisibility(false); break; case MediaStatus.PLAYER_STATE_IDLE: mPausePlay.setVisibility(View.INVISIBLE); setLoadingVisibility(false); if (mState == MediaStatus.PLAYER_STATE_IDLE && mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_FINISHED) { hideControls(true, R.string.no_media_info); } else { switch (mStreamType) { case MediaInfo.STREAM_TYPE_BUFFERED: mPausePlay.setVisibility(View.INVISIBLE); setLoadingVisibility(false); break; case MediaInfo.STREAM_TYPE_LIVE: int idleReason = mCastManager.getIdleReason(); if (idleReason == MediaStatus.IDLE_REASON_CANCELED) { mPausePlay.setVisibility(View.VISIBLE); mPausePlay.setImageDrawable(mPlayDrawable); setLoadingVisibility(false); } else { mPausePlay.setVisibility(View.INVISIBLE); setLoadingVisibility(false); } break; } } break; case MediaStatus.PLAYER_STATE_BUFFERING: mPausePlay.setVisibility(View.INVISIBLE); setLoadingVisibility(true); break; default: mPausePlay.setVisibility(View.INVISIBLE); setLoadingVisibility(false); } } }