Example usage for android.support.v4.media.session PlaybackStateCompat STATE_PAUSED

List of usage examples for android.support.v4.media.session PlaybackStateCompat STATE_PAUSED

Introduction

In this page you can find the example usage for android.support.v4.media.session PlaybackStateCompat STATE_PAUSED.

Prototype

int STATE_PAUSED

To view the source code for android.support.v4.media.session PlaybackStateCompat STATE_PAUSED.

Click Source Link

Document

State indicating this item is currently paused.

Usage

From source file:com.bayapps.android.robophish.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*  w ww.  j ava 2  s. c o m*/
    }
    mLastPlaybackState = state;
    if (getSupportMediaController() != null && getSupportMediaController().getExtras() != null) {
        String castName = getSupportMediaController().getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine5.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine5.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:com.torrenttunes.android.ui.FullScreenPlayerActivity.java

private void updateProgress() {
    if (mLastPlaybackState == null) {
        return;//from  w  w  w  .j  a va2s. c om
    }
    long currentPosition = mLastPlaybackState.getPosition();
    if (mLastPlaybackState.getState() != PlaybackStateCompat.STATE_PAUSED) {
        // Calculate the elapsed time between the last position update and now and unless
        // paused, we can assume (delta * speed) + current position is approximately the
        // latest position. This ensure that we do not repeatedly call the getPlaybackState()
        // on MediaController.
        long timeDelta = SystemClock.elapsedRealtime() - mLastPlaybackState.getLastPositionUpdateTime();
        currentPosition += (int) timeDelta * mLastPlaybackState.getPlaybackSpeed();
    }
    mSeekbar.setProgress((int) currentPosition);
}

From source file:com.murati.oszk.audiobook.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from w  w  w  .  jav  a  2 s  .  co  m
    }

    //TODO: Fix Time for current state

    mLastPlaybackState = state;
    MediaControllerCompat controllerCompat = MediaControllerCompat
            .getMediaController(FullScreenPlayerActivity.this);
    if (controllerCompat != null && controllerCompat.getExtras() != null) {
        String castName = controllerCompat.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine3.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine3.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:com.phearom.um.ui.FullScreenPlayerActivity.java

private void updateProgress() {
    if (mLastPlaybackState == null) {
        return;//  ww  w.j  a v a 2  s .  c o  m
    }
    long currentPosition = mLastPlaybackState.getPosition();
    if (mLastPlaybackState.getState() != PlaybackStateCompat.STATE_PAUSED) {
        long timeDelta = SystemClock.elapsedRealtime() - mLastPlaybackState.getLastPositionUpdateTime();
        currentPosition += (int) timeDelta * mLastPlaybackState.getPlaybackSpeed();
    }
    mSeekbar.setProgress((int) currentPosition);
}

From source file:com.scooter1556.sms.android.activity.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*from  w ww  . j  a va 2  s. com*/
    }

    lastPlaybackState = state;
    if (mediaController != null && mediaController.getExtras() != null) {
        String castName = mediaController.getExtras().getString(MediaService.EXTRA_CONNECTED_CAST);
        String extraInfo = castName == null ? "" : getResources().getString(R.string.cast_to_device, castName);
        extra.setText(extraInfo);
    }

    switch (state.getState()) {

    case PlaybackStateCompat.STATE_PLAYING:
        loading.setVisibility(INVISIBLE);
        playPause.setVisibility(VISIBLE);
        playPause.setImageDrawable(pauseDrawable);
        controllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;

    case PlaybackStateCompat.STATE_PAUSED:
        controllers.setVisibility(VISIBLE);
        loading.setVisibility(INVISIBLE);
        playPause.setVisibility(VISIBLE);
        playPause.setImageDrawable(playDrawable);
        stopSeekbarUpdate();
        break;

    case PlaybackStateCompat.STATE_NONE:

    case PlaybackStateCompat.STATE_STOPPED:
        loading.setVisibility(INVISIBLE);
        playPause.setVisibility(VISIBLE);
        playPause.setImageDrawable(playDrawable);
        stopSeekbarUpdate();
        break;

    case PlaybackStateCompat.STATE_BUFFERING:
        playPause.setVisibility(INVISIBLE);
        loading.setVisibility(VISIBLE);
        extra.setText(R.string.state_loading);
        stopSeekbarUpdate();
        break;

    default:
        Log.d(TAG, "Unhandled state: " + state.getState());
    }

    skipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    skipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
    shuffle.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE) == 0 ? INVISIBLE : VISIBLE);
    repeat.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SET_REPEAT_MODE) == 0 ? INVISIBLE : VISIBLE);

    // Custom Actions
    for (PlaybackStateCompat.CustomAction action : state.getCustomActions()) {
        switch (action.getAction()) {
        case MediaService.STATE_SHUFFLE_ON:
            shuffle.setColorFilter(ContextCompat.getColor(getBaseContext(), R.color.accent));
            break;

        case MediaService.STATE_SHUFFLE_OFF:
            shuffle.clearColorFilter();
            break;

        case MediaService.STATE_REPEAT_NONE:
            repeat.setImageResource(R.drawable.ic_repeat_white_24dp);
            repeat.clearColorFilter();
            break;

        case MediaService.STATE_REPEAT_ALL:
            repeat.setImageResource(R.drawable.ic_repeat_white_24dp);
            repeat.setColorFilter(ContextCompat.getColor(getBaseContext(), R.color.accent));
            break;

        case MediaService.STATE_REPEAT_ONE:
            repeat.setImageResource(R.drawable.ic_repeat_one_white_24dp);
            repeat.setColorFilter(ContextCompat.getColor(getBaseContext(), R.color.accent));
            break;
        }
    }
}

From source file:cat.terrones.devops.radiofx.ui.FullScreenPlayerActivity.java

private void updateProgress() {
    if (mLastPlaybackState == null) {
        return;//from   w  w w  .java 2  s.c om
    }
    long currentPosition = mLastPlaybackState.getPosition();
    if (mLastPlaybackState.getState() != PlaybackStateCompat.STATE_PAUSED) {
        // Calculate the elapsed time between the last position update and now and unless
        // paused, we can assume (delta * speed) + current position is approximately the
        // latest position. This ensure that we do not repeatedly call the getPlaybackState()
        // on MediaControllerCompat.
        long timeDelta = SystemClock.elapsedRealtime() - mLastPlaybackState.getLastPositionUpdateTime();
        currentPosition += (int) timeDelta * mLastPlaybackState.getPlaybackSpeed();
    }
    mSeekbar.setProgress((int) currentPosition);
}

From source file:org.runbuddy.tomahawk.views.PlaybackPanel.java

public void updatePlaybackState(PlaybackStateCompat playbackState) {
    if (mInitialized) {
        mProgressBarUpdater.setPlaybackState(playbackState);
        if (playbackState.getState() == PlaybackStateCompat.STATE_PLAYING) {
            if (mPlayPauseButton.isIndeterminate()) {
                mPlayPauseButton.setIndeterminate(false);
                mPlayPauseButton.setColor(getResources().getColor(android.R.color.white));
                mPlayPauseButton.resetAnimation();
            }//from  www. ja v a2 s.  c  o  m
            mPauseButton.setVisibility(VISIBLE);
            mPlayButton.setVisibility(GONE);
            mProgressBarUpdater.scheduleSeekbarUpdate();
        } else if (playbackState.getState() == PlaybackStateCompat.STATE_PAUSED) {
            if (mPlayPauseButton.isIndeterminate()) {
                mPlayPauseButton.setIndeterminate(false);
                mPlayPauseButton.setColor(getResources().getColor(android.R.color.white));
                mPlayPauseButton.resetAnimation();
            }
            mPauseButton.setVisibility(GONE);
            mPlayButton.setVisibility(VISIBLE);
            mProgressBarUpdater.stopSeekbarUpdate();
        } else if (playbackState.getState() == PlaybackStateCompat.STATE_BUFFERING) {
            if (!mPlayPauseButton.isIndeterminate()) {
                mPlayPauseButton.setIndeterminate(true);
                mPlayPauseButton.setColor(getResources().getColor(R.color.tomahawk_red));
                mPlayPauseButton.startAnimation();
            }
            mProgressBarUpdater.stopSeekbarUpdate();
        }
    }
}

From source file:org.runbuddy.tomahawk.mediaplayers.PluginMediaPlayer.java

private void handlePlayState() {
    if (mPreparedQuery != null) {
        if (mPlayState == PlaybackStateCompat.STATE_PAUSED && mIsPlaying) {
            callService(MSG_PAUSE);//from www.j ava  2 s  .c  o  m
        } else if (mPlayState == PlaybackStateCompat.STATE_PLAYING && !mIsPlaying) {
            callService(MSG_PLAY);
        }
    }
}

From source file:nuclei.media.playback.ExoPlayerPlayback.java

/**
 * Reconfigures MediaPlayer according to audio focus settings and
 * starts/restarts it. This method starts/restarts the MediaPlayer
 * respecting the current audio focus state. So if we have focus, it will
 * play normally; if we don't have focus, it will either leave the
 * MediaPlayer paused or set it to a low volume, depending on what is
 * allowed by the current focus settings. This method assumes mPlayer !=
 * null, so if you are calling it, you have to do so from a context where
 * you are sure this is the case./*w  ww  .  j a va 2  s .  c o m*/
 */
private void configMediaPlayerState(boolean updateMetaData, boolean forcePlay) {
    if (LOG.isLoggable(Log.DEBUG))
        LOG.d("configMediaPlayerState. mAudioFocus=" + mAudioFocus);
    if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
        // If we don't have audio focus and can't duck, we have to pause,
        if (isPlaying()) {
            pause();
        }
    } else { // we have audio focus:
        if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
            if (mMediaPlayer != null) {
                mMediaPlayer.setVolume(VOLUME_DUCK); // we'll be relatively quiet
            }
        } else {
            if (mMediaPlayer != null) {
                mMediaPlayer.setVolume(VOLUME_NORMAL); // we can be loud again
            } // else do something for remote client.
        }
        // If we were playing when we lost focus, we need to resume playing.
        if (mPlayOnFocusGain && mPlayWhenReady) {
            if (!isMediaPlayerPlaying()) {
                if (LOG.isLoggable(Log.INFO))
                    LOG.d("configMediaPlayerState startMediaPlayer. seeking to " + mCurrentPosition);
                if (mState == PlaybackStateCompat.STATE_PAUSED || mState == PlaybackStateCompat.STATE_STOPPED) {
                    if (forcePlay || mCurrentPosition != mMediaPlayer.getCurrentPosition()) {
                        if (!mWakeLock.isHeld())
                            mWakeLock.acquire();
                        if (!mWifiLock.isHeld())
                            mWifiLock.acquire();
                        mState = PlaybackStateCompat.STATE_BUFFERING;
                        mMediaPlayer.seekTo(mCurrentPosition);
                        mMediaPlayer.setPlayWhenReady(true);
                    } else
                        mState = PlaybackStateCompat.STATE_PLAYING;
                } else {
                    mMediaPlayer.seekTo(mCurrentPosition);
                    mState = PlaybackStateCompat.STATE_BUFFERING;
                }
            }
            mPlayOnFocusGain = false;
        }
    }
    if (mCallback != null) {
        if (updateMetaData)
            mCallback.onMetadataChanged(mMediaMetadata);
        mCallback.onPlaybackStatusChanged(mState);
    }
}

From source file:nuclei.media.playback.CastPlayback.java

void updatePlaybackState() {
    final int status = VideoCastManager.getInstance().getPlaybackStatus();

    // Convert the remote playback states to media playback states.
    switch (status) {
    case MediaStatus.PLAYER_STATE_IDLE:
        final int idleReason = VideoCastManager.getInstance().getIdleReason();
        switch (idleReason) {
        case MediaStatus.IDLE_REASON_ERROR:
            if (mCallback != null)
                mCallback.onError(new Exception("Error: " + idleReason), true);
            break;
        case MediaStatus.IDLE_REASON_INTERRUPTED:
        case MediaStatus.IDLE_REASON_CANCELED:
            // TODO: What should happen here?
            mState = PlaybackStateCompat.STATE_NONE;
            if (mCallback != null)
                mCallback.onPlaybackStatusChanged(mState);
            break;
        case MediaStatus.IDLE_REASON_FINISHED:
            if (mCallback != null)
                mCallback.onCompletion();
            break;
        default:/*from  w ww . j ava 2 s .  com*/
            setMetadataFromRemote();
            if (mCallback != null)
                mCallback.onPlaybackStatusChanged(mState);
            break;
        }
        break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
        mState = PlaybackStateCompat.STATE_BUFFERING;
        setMetadataFromRemote();
        if (mCallback != null)
            mCallback.onPlaybackStatusChanged(mState);
        break;
    case MediaStatus.PLAYER_STATE_PLAYING:
        mState = PlaybackStateCompat.STATE_PLAYING;
        setMetadataFromRemote();
        if (mCallback != null)
            mCallback.onPlaybackStatusChanged(mState);
        break;
    case MediaStatus.PLAYER_STATE_PAUSED:
        mState = PlaybackStateCompat.STATE_PAUSED;
        setMetadataFromRemote();
        if (mCallback != null)
            mCallback.onPlaybackStatusChanged(mState);
        break;
    default: // case unknown
        setMetadataFromRemote();
        if (mCallback != null)
            mCallback.onPlaybackStatusChanged(mState);
        break;
    }
}