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

The following examples show how to use com.google.android.gms.cast.MediaStatus#PLAYER_STATE_IDLE . 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: 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 2
Source File: ChromeCastMediaPlayerProfile.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * 再生状態を文字列に変換する.
 * 
 * @param   playState   再生状態
 * @return  再生状態の文字列を返す
 */
public String getPlayStatus(final int playState) {
    switch (playState) {
    case MediaStatus.PLAYER_STATE_BUFFERING:
        return MESSAGE_BUFFERING;
    case MediaStatus.PLAYER_STATE_IDLE:
        return MESSAGE_STOP;
    case MediaStatus.PLAYER_STATE_PAUSED:
        return MESSAGE_PAUSED;
    case MediaStatus.PLAYER_STATE_PLAYING:
        return MESSAGE_PALYING;
    case MediaStatus.PLAYER_STATE_UNKNOWN:
    default:
        return MESSAGE_UNKNOWN;
    }
}
 
Example 3
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 4
Source File: VideoCastManager.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source File: BaseActivity.java    From SkyTube with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSessionResumed(Session session, boolean wasSuspended) {
	mCastSession = CastContext.getSharedInstance(BaseActivity.this).getSessionManager().getCurrentCastSession();
	Runnable r = () -> {
		if(mCastSession.getRemoteMediaClient().getPlayerState() != MediaStatus.PLAYER_STATE_IDLE) {
			chromecastMiniControllerFragment.init(mCastSession.getRemoteMediaClient());
			chromecastControllerFragment.init(mCastSession.getRemoteMediaClient());
			slidingLayout.addPanelSlideListener(getOnPanelDisplayed((int) mCastSession.getRemoteMediaClient().getApproximateStreamPosition(), (int) mCastSession.getRemoteMediaClient().getStreamDuration()));
		} else if(externalPlayIntent != null) {
			// A default Chromecast has been set to handle external intents, and that Chromecast has now been
			// connected to. Play the video (which is stored in externalPlayIntent).
			handleExternalPlayOnChromecast(externalPlayIntent);
			externalPlayIntent = null;
		}
	};
	// Sometimes when we resume a chromecast session, even if media is actually playing, the player state is still idle here.
	// In that case, wait 500ms and check again (above Runnable). But if it's not idle, do the above right away.
	int delay = mCastSession.getRemoteMediaClient().getPlayerState() != MediaStatus.PLAYER_STATE_IDLE ? 0 : 500;
	new Handler().postDelayed(r, delay);

	invalidateOptionsMenu();
	YouTubePlayer.setConnectedToChromecast(true);
	YouTubePlayer.setConnectingToChromecast(false);
}
 
Example 6
Source File: BaseActivity.java    From SkyTube with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onResume() {
       /**
        * When resuming, make sure Google Play Services is installed before trying to resume everything for Chromecast support.
        */
	boolean googlePlayServicesAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS;
	if(googlePlayServicesAvailable) {
		if (mCastSession == null)
			mCastSession = mSessionManager.getCurrentCastSession();
		mSessionManager.addSessionManagerListener(mSessionManagerListener);
		if (mCastSession != null && mCastSession.getRemoteMediaClient() != null) {
			if (mCastSession.getRemoteMediaClient().getPlayerState() != MediaStatus.PLAYER_STATE_IDLE) {
				chromecastMiniControllerFragment.init(mCastSession.getRemoteMediaClient());
				chromecastControllerFragment.init(mCastSession.getRemoteMediaClient());
				showPanel();
			} else
				hidePanel();
		}
		handleNotificationClick(getIntent());
	}
	super.onResume();
}
 
Example 7
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 8
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 9
Source File: GoogleCastDelegate.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@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 10
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 11
Source File: VideoCastControllerActivity.java    From UTubeTV with The Unlicense 5 votes vote down vote up
@Override
public void setPlaybackStatus(int state) {
  switch (state) {
    case MediaStatus.PLAYER_STATE_PLAYING:
      mLoading.setVisibility(View.INVISIBLE);
      mPlayPause.setVisibility(View.VISIBLE);

      if (mStreamType == MediaInfo.STREAM_TYPE_LIVE) {
        mPlayPause.setImageDrawable(mStopDrawable);
      } else {
        mPlayPause.setImageDrawable(mPauseDrawable);
      }

      mLine2.setText(getString(R.string.casting_to_device, mCastManager.getDeviceName()));
      mControllers.setVisibility(View.VISIBLE);
      break;
    case MediaStatus.PLAYER_STATE_PAUSED:
      mControllers.setVisibility(View.VISIBLE);
      mLoading.setVisibility(View.INVISIBLE);
      mPlayPause.setVisibility(View.VISIBLE);
      mPlayPause.setImageDrawable(mPlayDrawable);
      mLine2.setText(getString(R.string.casting_to_device, mCastManager.getDeviceName()));
      break;
    case MediaStatus.PLAYER_STATE_IDLE:
      mLoading.setVisibility(View.INVISIBLE);
      mPlayPause.setImageDrawable(mPlayDrawable);
      mPlayPause.setVisibility(View.VISIBLE);
      mLine2.setText(getString(R.string.casting_to_device, mCastManager.getDeviceName()));
      break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
      mPlayPause.setVisibility(View.INVISIBLE);
      mLoading.setVisibility(View.VISIBLE);
      mLine2.setText(getString(R.string.loading));
      break;
    default:
      break;
  }
}
 
Example 12
Source File: VideoCastManager.java    From UTubeTV with The Unlicense 5 votes vote down vote up
@Override
public void onPlayPauseClicked(View v) throws CastException, TransientNetworkDisconnectionException, NoConnectionException {
  checkConnectivity();
  if (mState == MediaStatus.PLAYER_STATE_PLAYING) {
    pause();
  } else {
    boolean isLive = isRemoteStreamLive();
    if ((mState == MediaStatus.PLAYER_STATE_PAUSED && !isLive) || (mState == MediaStatus.PLAYER_STATE_IDLE && isLive)) {
      play();
    }
  }
}
 
Example 13
Source File: VideoCastManager.java    From android with Apache License 2.0 5 votes vote down vote up
@Override
public void onDisconnected() {
    super.onDisconnected();
    updateMiniControllersVisibility(false);
    stopNotificationService();
    removeRemoteControlClient();
    mState = MediaStatus.PLAYER_STATE_IDLE;
}
 
Example 14
Source File: VideoCastManager.java    From android with Apache License 2.0 5 votes vote down vote up
@Override
void onDeviceUnselected() {
    stopNotificationService();
    detachMediaChannel();
    removeDataChannel();
    mState = MediaStatus.PLAYER_STATE_IDLE;
}
 
Example 15
Source File: VideoCastManager.java    From android with Apache License 2.0 5 votes vote down vote up
@Override
public void onPlayPauseClicked(View v) throws CastException,
        TransientNetworkDisconnectionException, NoConnectionException {
    checkConnectivity();
    if (mState == MediaStatus.PLAYER_STATE_PLAYING) {
        pause();
    } else {
        boolean isLive = isRemoteStreamLive();
        if ((mState == MediaStatus.PLAYER_STATE_PAUSED && !isLive)
                || (mState == MediaStatus.PLAYER_STATE_IDLE && isLive)) {
            play();
        }
    }
}
 
Example 16
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 17
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;
  }
}
 
Example 18
Source File: VideoCastControllerActivity.java    From android with Apache License 2.0 4 votes vote down vote up
@Override
public void setPlaybackStatus(int state) {
    LOGD(TAG, "setPlaybackStatus(): state = " + state);
    switch (state) {
        case MediaStatus.PLAYER_STATE_PLAYING:
            mLoading.setVisibility(View.INVISIBLE);
            mPlayPause.setVisibility(View.VISIBLE);

            if (mStreamType == MediaInfo.STREAM_TYPE_LIVE) {
                mPlayPause.setImageDrawable(mStopDrawable);
            } else {
                mPlayPause.setImageDrawable(mPauseDrawable);
            }

            mLine2.setText(getString(R.string.casting_to_device,
                    mCastManager.getDeviceName()));
            mControllers.setVisibility(View.VISIBLE);
            break;
        case MediaStatus.PLAYER_STATE_PAUSED:
            mControllers.setVisibility(View.VISIBLE);
            mLoading.setVisibility(View.INVISIBLE);
            mPlayPause.setVisibility(View.VISIBLE);
            mPlayPause.setImageDrawable(mPlayDrawable);
            mLine2.setText(getString(R.string.casting_to_device,
                    mCastManager.getDeviceName()));
            break;
        case MediaStatus.PLAYER_STATE_IDLE:
            mLoading.setVisibility(View.INVISIBLE);
            mPlayPause.setImageDrawable(mPlayDrawable);
            mPlayPause.setVisibility(View.VISIBLE);
            mLine2.setText(getString(R.string.casting_to_device,
                    mCastManager.getDeviceName()));
            break;
        case MediaStatus.PLAYER_STATE_BUFFERING:
            mPlayPause.setVisibility(View.INVISIBLE);
            mLoading.setVisibility(View.VISIBLE);
            mLine2.setText(getString(R.string.loading));
            break;
        default:
            break;
    }
}
 
Example 19
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 20
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);
    }
  }
}