Java Code Examples for com.google.android.gms.cast.MediaStatus#IDLE_REASON_CANCELED

The following examples show how to use com.google.android.gms.cast.MediaStatus#IDLE_REASON_CANCELED . 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 vote down vote up
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 vote down vote up
/**
 * A helper method to determine if, given a player state and an idle reason (if the state is
 * idle) will warrant having a UI for remote presentation of the remote content.
 *
 * @param state
 * @param idleReason
 * @return
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
public boolean shouldRemoteUiBeVisible(int state, int idleReason)
        throws TransientNetworkDisconnectionException,
        NoConnectionException {
    switch (state) {
        case MediaStatus.PLAYER_STATE_PLAYING:
        case MediaStatus.PLAYER_STATE_PAUSED:
        case MediaStatus.PLAYER_STATE_BUFFERING:
            return true;
        case MediaStatus.PLAYER_STATE_IDLE:
            if (!isRemoteStreamLive()) {
                return false;
            }
            return idleReason == MediaStatus.IDLE_REASON_CANCELED;
        default:
            break;
    }
    return false;
}
 
Example 3
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * A helper method to determine if, given a player state and an idle reason (if the state is
 * idle) will warrant having a UI for remote presentation of the remote content.
 *
 * @param state
 * @param idleReason
 * @return
 * @throws TransientNetworkDisconnectionException
 * @throws NoConnectionException
 */
public boolean shouldRemoteUiBeVisible(int state, int idleReason) throws TransientNetworkDisconnectionException, NoConnectionException {
  switch (state) {
    case MediaStatus.PLAYER_STATE_PLAYING:
    case MediaStatus.PLAYER_STATE_PAUSED:
    case MediaStatus.PLAYER_STATE_BUFFERING:
      return true;
    case MediaStatus.PLAYER_STATE_IDLE:
      if (!isRemoteStreamLive()) {
        return false;
      }
      return idleReason == MediaStatus.IDLE_REASON_CANCELED;
    default:
      break;
  }
  return false;
}
 
Example 4
Source File: VideoCastControllerFragment.java    From UTubeTV with The Unlicense 6 votes vote down vote up
private void togglePlayback() throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
  switch (mPlaybackState) {
    case MediaStatus.PLAYER_STATE_PAUSED:
      mCastManager.play();
      mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
      restartTrickplayTimer();
      break;
    case MediaStatus.PLAYER_STATE_PLAYING:
      mCastManager.pause();
      mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
      break;
    case MediaStatus.PLAYER_STATE_IDLE:
      if ((mSelectedMedia.getStreamType() == MediaInfo.STREAM_TYPE_LIVE) && (mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_CANCELED)) {
        mCastManager.play();
      } else {
        mCastManager.loadMedia(mSelectedMedia, true, 0);
      }
      mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
      restartTrickplayTimer();
      break;
    default:
      break;
  }
  mCastController.setPlaybackStatus(mPlaybackState);
}
 
Example 5
Source File: VideoCastControllerFragment.java    From android with Apache License 2.0 5 votes vote down vote up
private void togglePlayback() throws CastException, TransientNetworkDisconnectionException,
        NoConnectionException {
    switch (mPlaybackState) {
        case MediaStatus.PLAYER_STATE_PAUSED:
            mCastManager.play();
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            restartTrickplayTimer();
            break;
        case MediaStatus.PLAYER_STATE_PLAYING:
            mCastManager.pause();
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            break;
        case MediaStatus.PLAYER_STATE_IDLE:
            if ((mSelectedMedia.getStreamType() == MediaInfo.STREAM_TYPE_LIVE)
                    && (mCastManager.getIdleReason() == MediaStatus.IDLE_REASON_CANCELED)) {
                mCastManager.play();
            } else {
                mCastManager.loadMedia(mSelectedMedia, true, 0);
            }
            mPlaybackState = MediaStatus.PLAYER_STATE_BUFFERING;
            restartTrickplayTimer();
            break;
        default:
            break;
    }
    mCastController.setPlaybackStatus(mPlaybackState);
}
 
Example 6
Source File: ChromecastBaseControllerFragment.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
@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 7
Source File: VideoMediaRouteControllerDialog.java    From android with Apache License 2.0 4 votes vote down vote up
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 8
Source File: MiniController.java    From android with Apache License 2.0 4 votes vote down vote up
@Override
public void setPlaybackStatus(int state, int idleReason) {
    switch (state) {
        case MediaStatus.PLAYER_STATE_PLAYING:
            mPlayPause.setVisibility(View.VISIBLE);
            mPlayPause.setImageDrawable(getPauseStopButton());
            setLoadingVisibility(false);
            break;
        case MediaStatus.PLAYER_STATE_PAUSED:
            mPlayPause.setVisibility(View.VISIBLE);
            mPlayPause.setImageDrawable(mPlayDrawable);
            setLoadingVisibility(false);
            break;
        case MediaStatus.PLAYER_STATE_IDLE:
            switch (mStreamType) {
                case MediaInfo.STREAM_TYPE_BUFFERED:
                    mPlayPause.setVisibility(View.INVISIBLE);
                    setLoadingVisibility(false);
                    break;
                case MediaInfo.STREAM_TYPE_LIVE:
                    if (idleReason == MediaStatus.IDLE_REASON_CANCELED) {
                        mPlayPause.setVisibility(View.VISIBLE);
                        mPlayPause.setImageDrawable(mPlayDrawable);
                        setLoadingVisibility(false);
                    } else {
                        mPlayPause.setVisibility(View.INVISIBLE);
                        setLoadingVisibility(false);
                    }
                    break;
            }
            break;
        case MediaStatus.PLAYER_STATE_BUFFERING:
            mPlayPause.setVisibility(View.INVISIBLE);
            setLoadingVisibility(true);
            break;
        default:
            mPlayPause.setVisibility(View.INVISIBLE);
            setLoadingVisibility(false);
            break;
    }
}
 
Example 9
Source File: VideoMediaRouteControllerDialog.java    From UTubeTV with The Unlicense 4 votes vote down vote up
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);
    }
  }
}
 
Example 10
Source File: MiniController.java    From UTubeTV with The Unlicense 4 votes vote down vote up
@Override
public void setPlaybackStatus(int state, int idleReason) {
  switch (state) {
    case MediaStatus.PLAYER_STATE_PLAYING:
      mPlayPause.setVisibility(View.VISIBLE);
      mPlayPause.setImageDrawable(getPauseStopButton());
      setLoadingVisibility(false);
      break;
    case MediaStatus.PLAYER_STATE_PAUSED:
      mPlayPause.setVisibility(View.VISIBLE);
      mPlayPause.setImageDrawable(mPlayDrawable);
      setLoadingVisibility(false);
      break;
    case MediaStatus.PLAYER_STATE_IDLE:
      switch (mStreamType) {
        case MediaInfo.STREAM_TYPE_BUFFERED:
          mPlayPause.setVisibility(View.INVISIBLE);
          setLoadingVisibility(false);
          break;
        case MediaInfo.STREAM_TYPE_LIVE:
          if (idleReason == MediaStatus.IDLE_REASON_CANCELED) {
            mPlayPause.setVisibility(View.VISIBLE);
            mPlayPause.setImageDrawable(mPlayDrawable);
            setLoadingVisibility(false);
          } else {
            mPlayPause.setVisibility(View.INVISIBLE);
            setLoadingVisibility(false);
          }
          break;
      }
      break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
      mPlayPause.setVisibility(View.INVISIBLE);
      setLoadingVisibility(true);
      break;
    default:
      mPlayPause.setVisibility(View.INVISIBLE);
      setLoadingVisibility(false);
      break;
  }
}