com.google.android.gms.cast.MediaStatus

Here are the examples of the java api class com.google.android.gms.cast.MediaStatus taken from open source projects.

1. RemotePSMP#onRemoteMediaPlayerStatusUpdated()

Project: AntennaPod
Source File: RemotePSMP.java
View license
private void onRemoteMediaPlayerStatusUpdated(@NonNull EndPlaybackCall endPlaybackCall) {
    MediaStatus status = castMgr.getMediaStatus();
    if (status == null) {
        Log.d(TAG, "Received null MediaStatus");
        //setPlayerStatus(PlayerStatus.INDETERMINATE, null);
        return;
    } else {
        Log.d(TAG, "Received remote status/media update. New state=" + status.getPlayerState());
    }
    Playable currentMedia = localVersion(status.getMediaInfo());
    boolean updateUI = currentMedia != media;
    if (currentMedia != null) {
        long position = status.getStreamPosition();
        if (position > 0 && currentMedia.getPosition() == 0) {
            currentMedia.setPosition((int) position);
        }
    }
    int state = status.getPlayerState();
    setBuffering(state == MediaStatus.PLAYER_STATE_BUFFERING);
    switch(state) {
        case MediaStatus.PLAYER_STATE_PLAYING:
            setPlayerStatus(PlayerStatus.PLAYING, currentMedia);
            break;
        case MediaStatus.PLAYER_STATE_PAUSED:
            setPlayerStatus(PlayerStatus.PAUSED, currentMedia);
            break;
        case MediaStatus.PLAYER_STATE_BUFFERING:
            setPlayerStatus(playerStatus, currentMedia);
            break;
        case MediaStatus.PLAYER_STATE_IDLE:
            int reason = status.getIdleReason();
            switch(reason) {
                case MediaStatus.IDLE_REASON_CANCELED:
                    // check if we're already loading something else
                    if (!updateUI || media == null) {
                        setPlayerStatus(PlayerStatus.STOPPED, currentMedia);
                    } else {
                        updateUI = false;
                    }
                    break;
                case MediaStatus.IDLE_REASON_INTERRUPTED:
                    // check if we're already loading something else
                    if (!updateUI || media == null) {
                        setPlayerStatus(PlayerStatus.PREPARING, currentMedia);
                    } else {
                        updateUI = false;
                    }
                    break;
                case MediaStatus.IDLE_REASON_NONE:
                    setPlayerStatus(PlayerStatus.INITIALIZED, currentMedia);
                    break;
                case MediaStatus.IDLE_REASON_FINISHED:
                    boolean playing = playerStatus == PlayerStatus.PLAYING;
                    setPlayerStatus(PlayerStatus.INDETERMINATE, currentMedia);
                    endPlaybackCall.endPlayback(currentMedia, playing, false, false);
                    // endPlayback already updates the UI, so no need to trigger it ourselves
                    updateUI = false;
                    break;
                case MediaStatus.IDLE_REASON_ERROR:
                    Log.w(TAG, "Got an error status from the Chromecast. Skipping, if possible, to the next episode...");
                    setPlayerStatus(PlayerStatus.INDETERMINATE, currentMedia);
                    callback.onMediaPlayerInfo(CAST_ERROR_PRIORITY_HIGH, R.string.cast_failed_media_error_skipping);
                    endPlaybackCall.endPlayback(currentMedia, startWhenPrepared.get(), true, false);
                    // endPlayback already updates the UI, so no need to trigger it ourselves
                    updateUI = false;
            }
            break;
        case MediaStatus.PLAYER_STATE_UNKNOWN:
            //is this right?
            setPlayerStatus(PlayerStatus.INDETERMINATE, currentMedia);
            break;
        default:
            Log.e(TAG, "Remote media state undetermined!");
            setPlayerStatus(PlayerStatus.INDETERMINATE, currentMedia);
    }
    if (updateUI) {
        callback.onMediaChanged(true);
    }
}