Example usage for android.media.session PlaybackState STATE_PAUSED

List of usage examples for android.media.session PlaybackState STATE_PAUSED

Introduction

In this page you can find the example usage for android.media.session PlaybackState STATE_PAUSED.

Prototype

int STATE_PAUSED

To view the source code for android.media.session PlaybackState STATE_PAUSED.

Click Source Link

Document

State indicating this item is currently paused.

Usage

From source file:org.amahi.anywhere.tv.fragment.TvPlaybackAudioFragment.java

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void playbackStateChanged() {

    if (mCurrentPlaybackState != PlaybackState.STATE_PLAYING) {
        mCurrentPlaybackState = PlaybackState.STATE_PLAYING;
        startProgressAutomation();//ww w.j a va 2 s.co  m
        setFadingEnabled(false);
        mPlayPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.PAUSE);
        mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlaybackControlsRow.PlayPauseAction.PAUSE));
        notifyChanged(mPlayPauseAction);
    } else {
        mCurrentPlaybackState = PlaybackState.STATE_PAUSED;
        stopProgressAutomation();
        mPlayPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.PLAY);
        mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlaybackControlsRow.PlayPauseAction.PLAY));
        notifyChanged(mPlayPauseAction);
    }
}

From source file:com.appdevper.mediaplayer.ui.PlaybackControlsFragment.java

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null,"
                + "this should not happen if the callback was properly unregistered. Ignoring.");
        return;/*from ww  w.  j a v a  2s  .  co m*/
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackState.STATE_PAUSED:
    case PlaybackState.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackState.STATE_ERROR:
        LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
        Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
        break;
    }

    if (enablePlay) {
        mPlayPause.setImageDrawable(
                ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_36dp));
    } else {
        mPlayPause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_36dp));
    }

    MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();
    String extraInfo = null;
    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    setExtraInfo(extraInfo);
}

From source file:com.orangesoft.jook.CastPlayback.java

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

    Log.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 (callback != null)
                callback.onCompletion();
        }//from   w w  w. j a  v a  2 s  .  com
        break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
        safeStatusChangeNotification(PlaybackState.STATE_BUFFERING);
        break;
    case MediaStatus.PLAYER_STATE_PLAYING:
        safeStatusChangeNotification(PlaybackState.STATE_PLAYING);
        break;
    case MediaStatus.PLAYER_STATE_PAUSED:
        safeStatusChangeNotification(PlaybackState.STATE_PAUSED);
        break;
    }
}

From source file:com.appdevper.mediaplayer.app.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. java  2s. c  o  m
        }
        break;
    case MediaStatus.PLAYER_STATE_BUFFERING:
        mState = PlaybackState.STATE_BUFFERING;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        break;
    case MediaStatus.PLAYER_STATE_PLAYING:
        mState = PlaybackState.STATE_PLAYING;
        updateMetadata();
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        break;
    case MediaStatus.PLAYER_STATE_PAUSED:
        mState = PlaybackState.STATE_PAUSED;
        updateMetadata();
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        break;
    default: // case unknown
        LogHelper.d(TAG, "State default : ", status);
        break;
    }
}

From source file:org.amahi.anywhere.tv.fragment.TvPlaybackVideoFragment.java

public void playbackStateChanged() {
    if (mCurrentPlaybackState != PlaybackState.STATE_PLAYING) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mCurrentPlaybackState = PlaybackState.STATE_PLAYING;
        }/* www  . j a v a 2 s. co  m*/
        startProgressAutomation();
        setFadingEnabled(true);
        mPlayPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.PAUSE);
        mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlaybackControlsRow.PlayPauseAction.PAUSE));
        notifyChanged(mPlayPauseAction);
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mCurrentPlaybackState = PlaybackState.STATE_PAUSED;
        }
        stopProgressAutomation();
        setFadingEnabled(false);
        mPlayPauseAction.setIndex(PlaybackControlsRow.PlayPauseAction.PLAY);
        mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlaybackControlsRow.PlayPauseAction.PLAY));
        notifyChanged(mPlayPauseAction);
    }
}

From source file:info.tongrenlu.FullScreenPlayerActivity.java

private void updateProgress() {
    if (mLastPlaybackState == null) {
        return;/*ww  w.  j ava 2  s.co m*/
    }
    long currentPosition = mLastPlaybackState.getPosition();
    if (mLastPlaybackState.getState() != PlaybackState.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:de.kraenksoft.c3tv.ui.PlaybackOverlayFragment.java

private void playPause(boolean doPlay) {
    if (getPlaybackState() == PlaybackState.STATE_NONE) {
        setupCallbacks();//from  ww  w  . j  ava2 s  .c o  m
    }

    if (doPlay && getPlaybackState() != PlaybackState.STATE_PLAYING) {
        if (mPosition > 0) {
            mVideoView.seekTo(mPosition);
        }
        mVideoView.start();
        mStartTimeMillis = System.currentTimeMillis();
        setPlaybackState(PlaybackState.STATE_PLAYING);
    } else {
        int timeElapsedSinceStart = (int) (System.currentTimeMillis() - mStartTimeMillis);
        setPosition(mPosition + timeElapsedSinceStart);
        mVideoView.pause();
        setPlaybackState(PlaybackState.STATE_PAUSED);
    }
}

From source file:org.mythtv.android.presentation.view.fragment.TvPlaybackOverlayFragment.java

private void playPause(boolean doPlay) {

    if (getPlaybackState() == PlaybackState.STATE_NONE) {

        setupCallbacks();/*from w w w .  j av a 2  s  .co  m*/

    }

    if (doPlay && getPlaybackState() != PlaybackState.STATE_PLAYING) {

        if (mPosition > 0) {

            mVideoView.seekTo(mPosition);

        }

        mVideoView.start();
        mStartTimeMillis = System.currentTimeMillis();
        setPlaybackState(PlaybackState.STATE_PLAYING);

    } else {

        int timeElapsedSinceStart = (int) (System.currentTimeMillis() - mStartTimeMillis);
        setPosition(mPosition + timeElapsedSinceStart);
        mVideoView.pause();
        setPlaybackState(PlaybackState.STATE_PAUSED);

    }

}

From source file:com.appdevper.mediaplayer.activity.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*from w ww.  j  a  v  a  2s  .  co 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);
        mLine3.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackState.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackState.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackState.STATE_NONE:
    case PlaybackState.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackState.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() & PlaybackState.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:com.sgottard.tvdemoapp.ui.PlaybackOverlayFragment.java

private void next(boolean autoPlay) {
    if (++mCurrentItem >= mItems.size()) {
        mCurrentItem = 0;/*  w  w  w  .  j  a  va2 s  . c om*/
    }
    Bundle bundle = new Bundle();
    bundle.putBoolean(PlaybackActivity.AUTO_PLAY, autoPlay);
    if (autoPlay) {
        mCurrentPlaybackState = PlaybackState.STATE_PAUSED;
    }
    mMediaController.getTransportControls().playFromMediaId(mItems.get(mCurrentItem).getId(), bundle);
    mFfwRwdSpeed = INITIAL_SPEED;
}