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.mylovemhz.simplay.MusicService.java

public void pause() {
    if (currentState == State.STARTED) {
        mediaPlayer.pause();//from   w w  w  . j  a v a2 s  .  c o m
        currentState = State.PAUSED;
        updateSessionState(PlaybackStateCompat.STATE_PAUSED);
        showNotification();
    }
}

From source file:info.tongrenlu.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from ww w . j a v  a 2  s. c  o m
    }
    Log.d(TAG, "updatePlaybackState, playback state=" + state.getState());
    mLastPlaybackState = state;

    mLine3.setText("");

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(View.INVISIBLE);
        mPlayPause.setVisibility(View.VISIBLE);
        //                mPlayPause.setImageDrawable(mPauseDrawable);
        Glide.with(this).load(R.drawable.ic_pause_white_48dp).into(mPlayPause);
        mControllers.setVisibility(View.VISIBLE);
        scheduleProgressUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(View.VISIBLE);
        mLoading.setVisibility(View.INVISIBLE);
        mPlayPause.setVisibility(View.VISIBLE);
        //                mPlayPause.setImageDrawable(mPlayDrawable);
        Glide.with(this).load(R.drawable.ic_play_arrow_white_48dp).into(mPlayPause);
        stopProgressUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(View.INVISIBLE);
        mPlayPause.setVisibility(View.VISIBLE);
        Glide.with(this).load(R.drawable.ic_play_arrow_white_48dp).into(mPlayPause);
        stopProgressUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(View.INVISIBLE);
        mLoading.setVisibility(View.VISIBLE);
        mLine3.setText(R.string.loading);
        stopProgressUpdate();
        break;
    default:
        Log.d(TAG, "Unhandled state " + state.getState());
    }

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

From source file:com.torrenttunes.android.CastPlayback.java

private void updatePlaybackState() {
    int status = mCastManager.getPlaybackStatus();
    int idleReason = mCastManager.getIdleReason();

    LogHelper.d(TAG, "onRemoteMediaPlayerStatusUpdated ", status);

    // Convert the remote playback states to media playback states.
    switch (status) {
    case MediaStatus.PLAYER_STATE_IDLE:
        if (idleReason == MediaStatus.IDLE_REASON_FINISHED) {
            if (mCallback != null) {
                mCallback.onCompletion();
            }// ww w .ja  va  2s .  c o  m
        }
        break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
        mState = PlaybackStateCompat.STATE_BUFFERING;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        break;
    case MediaStatus.PLAYER_STATE_PLAYING:
        mState = PlaybackStateCompat.STATE_PLAYING;
        updateMetadata();
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        break;
    case MediaStatus.PLAYER_STATE_PAUSED:
        mState = PlaybackStateCompat.STATE_PAUSED;
        updateMetadata();
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        break;
    default: // case unknown
        LogHelper.d(TAG, "State default : ", status);
        break;
    }
}

From source file:com.murati.oszk.audiobook.ui.tv.TvPlaybackFragment.java

protected void updatePlaybackState(PlaybackStateCompat state) {
    if (mPlaybackControlsRow == null) {
        // We only update playback state after we get a valid metadata.
        return;//from  w  ww.j  a  va 2 s .  c  o  m
    }
    mLastPosition = state.getPosition();
    mLastPositionUpdateTime = state.getLastPositionUpdateTime();
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        startProgressAutomation();
        mPlayPauseAction.setIndex(PlayPauseAction.PAUSE);
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        stopProgressAutomation();
        mPlayPauseAction.setIndex(PlayPauseAction.PLAY);
        break;
    }

    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    updatePlayListRow(controller.getQueue());
    mRowsAdapter.notifyArrayItemRangeChanged(mRowsAdapter.indexOf(mPlaybackControlsRow), 1);
}

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

@Override
public void pause() {
    LOG.d("pause");
    mPlayWhenReady = false;/*from  w w  w  .j  a  va  2s  .c om*/
    if (isPlaying()) {
        // Pause media player and cancel the 'foreground service' state.
        if (isMediaPlayerPlaying()) {
            mCurrentPosition = getCurrentStreamPosition();
            mMediaPlayer.setPlayWhenReady(false);
        }
    }
    // while paused, retain the MediaPlayer but give up audio focus
    relaxResources(false);
    giveUpAudioFocus();
    mState = PlaybackStateCompat.STATE_PAUSED;
    if (mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }
    unregisterAudioNoisyReceiver();
}

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

/**
 * Switch to a different Playback instance, maintaining all playback state, if possible.
 *
 * @param playback switch to this playback
 *//*from  w  ww  . ja  v a 2  s.  c o  m*/
public void switchToPlayback(Playback playback, boolean resumePlaying) {
    if (playback == null) {
        throw new IllegalArgumentException("Playback cannot be null");
    }
    playback.setSurface(mPlayback.getSurfaceId(), mPlayback.getSurface());
    // suspend the current one.
    final int oldState = mPlayback.getState();
    long pos = mPlayback.getCurrentStreamPosition();
    if (pos < 0)
        pos = mPlayback.getStartStreamPosition();
    mPlayback.stop(false);
    playback.setCallback(this);
    playback.setCurrentStreamPosition(pos);
    playback.setCurrentMediaMetadata(mPlayback.getCurrentMediaId(), mPlayback.getCurrentMetadata());
    playback.start();
    // finally swap the instance
    mPlayback = playback;
    switch (oldState) {
    case PlaybackStateCompat.STATE_BUFFERING:
    case PlaybackStateCompat.STATE_CONNECTING:
    case PlaybackStateCompat.STATE_PAUSED:
        mPlayback.pause();
        break;
    case PlaybackStateCompat.STATE_PLAYING:
        if (resumePlaying && mMediaMetadata != null) {
            mPlayback.play(mMediaMetadata);
        } else if (!resumePlaying) {
            mPlayback.pause();
        } else {
            mPlayback.stop(true);
        }
        break;
    case PlaybackStateCompat.STATE_NONE:
        break;
    default:

    }
}

From source file:com.example.chu.googleplaylibrary.playback.CastPlayback.java

private void updatePlaybackState() {
    int status = VideoCastManager.getInstance().getPlaybackStatus();
    int idleReason = VideoCastManager.getInstance().getIdleReason();

    LogHelper.d(TAG, "onRemoteMediaPlayerStatusUpdated ", status);

    // Convert the remote playback states to media playback states.
    switch (status) {
    case MediaStatus.PLAYER_STATE_IDLE:
        if (idleReason == MediaStatus.IDLE_REASON_FINISHED) {
            if (mCallback != null) {
                mCallback.onCompletion();
            }/* ww w . j  a  va 2  s .c  om*/
        }
        break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
        mState = PlaybackStateCompat.STATE_BUFFERING;
        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
        LogHelper.d(TAG, "State default : ", status);
        break;
    }
}

From source file:com.bayapps.android.robophish.ui.tv.TvPlaybackFragment.java

protected void updatePlaybackState(PlaybackStateCompat state) {
    if (mPlaybackControlsRow == null) {
        // We only update playback state after we get a valid metadata.
        return;// w w  w .  ja v a  2 s .c  o m
    }
    mLastPosition = state.getPosition();
    mLastPositionUpdateTime = state.getLastPositionUpdateTime();
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        startProgressAutomation();
        mPlayPauseAction.setIndex(PlayPauseAction.PAUSE);
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        stopProgressAutomation();
        mPlayPauseAction.setIndex(PlayPauseAction.PLAY);
        break;
    }

    MediaControllerCompat controller = getActivity().getSupportMediaController();
    updatePlayListRow(controller.getQueue());
    mRowsAdapter.notifyArrayItemRangeChanged(mRowsAdapter.indexOf(mPlaybackControlsRow), 1);
}

From source file:org.runbuddy.tomahawk.ui.fragments.PlaybackFragment.java

/**
 * Called every time an item inside a ListView or GridView is clicked
 *  @param view the clicked view//  w ww .  ja va2 s  .  co m
 * @param item the Object which corresponds to the click
 * @param segment
 */
@Override
public void onItemClick(View view, Object item, Segment segment) {
    if (getMediaController() == null) {
        Log.d(TAG, "onItemClick failed because getMediaController() is null");
        return;
    }
    if (item instanceof PlaylistEntry) {
        PlaylistEntry entry = (PlaylistEntry) item;
        if (entry.getQuery().isPlayable()) {
            if (getPlaybackManager().getCurrentEntry() == entry) {
                // if the user clicked on an already playing track
                int playState = getMediaController().getPlaybackState().getState();
                if (playState == PlaybackStateCompat.STATE_PLAYING) {
                    getMediaController().getTransportControls().pause();
                } else if (playState == PlaybackStateCompat.STATE_PAUSED) {
                    getMediaController().getTransportControls().play();
                }
            } else {
                getPlaybackManager().setCurrentEntry(entry);
            }
        }
    }
}

From source file:com.scooter1556.sms.android.playback.CastPlayback.java

private void updatePlaybackState() {
    String log = "updatePlaybackState() > ";

    int status = remoteMediaClient.getPlayerState();
    int idleReason = remoteMediaClient.getIdleReason();

    // Convert the remote playback states to media playback states
    switch (status) {
    case MediaStatus.PLAYER_STATE_IDLE:
        log += "IDLE";

        if (idleReason == MediaStatus.IDLE_REASON_FINISHED && !finished) {
            log += ":FINISHED";

            finished = true;//from w ww.j  a  v a 2s .  c o m
            currentJobId = null;

            if (callback != null) {
                callback.onCompletion();
            }
        }

        break;

    case MediaStatus.PLAYER_STATE_BUFFERING:
        log += "BUFFERING";

        finished = false;

        playbackState = PlaybackStateCompat.STATE_BUFFERING;

        if (callback != null) {
            callback.onPlaybackStatusChanged(playbackState);
        }

        break;

    case MediaStatus.PLAYER_STATE_PLAYING:
        log += "PLAYING";

        finished = false;

        playbackState = PlaybackStateCompat.STATE_PLAYING;
        setMetadataFromRemote();

        if (callback != null) {
            callback.onPlaybackStatusChanged(playbackState);
        }

        break;

    case MediaStatus.PLAYER_STATE_PAUSED:
        log += "PAUSED";

        playbackState = PlaybackStateCompat.STATE_PAUSED;
        setMetadataFromRemote();

        if (callback != null) {
            callback.onPlaybackStatusChanged(playbackState);
        }
        break;

    default:
        log += "UNKNOWN:" + status;
        break;
    }

    Log.d(TAG, log);
}