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

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

Introduction

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

Prototype

int STATE_STOPPED

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

Click Source Link

Document

State indicating this item is currently stopped.

Usage

From source file:com.example.android.leanback.PlaybackTransportControlGlueSample.java

/**
 * Helper function to create a playback state based on current adapter's state.
 *
 * @return playback state compat builder
 *///from  ww w  .j a  v a 2  s  . c om
private PlaybackStateCompat createPlaybackStateBasedOnAdapterState() {

    PlaybackStateCompat.Builder playbackStateCompatBuilder = new PlaybackStateCompat.Builder();
    long currentPosition = getCurrentPosition();
    long bufferedPosition = getBufferedPosition();

    // In this glue we only support normal speed
    float playbackSpeed = NORMAL_SPEED;

    // Translate player adapter's state to play back state compat
    // If player adapter is not prepared
    // ==> STATE_STOPPED
    //     (Launcher can only visualize the media session under playing state,
    //     it makes more sense to map this state to PlaybackStateCompat.STATE_STOPPED)
    // If player adapter is prepared
    //     If player is playing
    //     ==> STATE_PLAYING
    //     If player is not playing
    //     ==> STATE_PAUSED
    if (!getPlayerAdapter().isPrepared()) {
        playbackStateCompatBuilder.setState(PlaybackStateCompat.STATE_STOPPED, currentPosition, playbackSpeed)
                .setActions(getPlaybackStateActions());
    } else if (getPlayerAdapter().isPlaying()) {
        playbackStateCompatBuilder.setState(PlaybackStateCompat.STATE_PLAYING, currentPosition, playbackSpeed)
                .setActions(getPlaybackStateActions());
    } else {
        playbackStateCompatBuilder.setState(PlaybackStateCompat.STATE_PAUSED, currentPosition, playbackSpeed)
                .setActions(getPlaybackStateActions());
    }

    // always fill buffered position
    return playbackStateCompatBuilder.setBufferedPosition(bufferedPosition).build();
}

From source file:com.mylovemhz.simplay.MusicService.java

public void previous() {
    if (hasPrevious()) {
        if (currentState == State.STARTED || currentState == State.PAUSED) {
            mediaPlayer.stop();/* ww  w. j  a v a 2s. co  m*/
            currentState = State.STOPPED;
            updateSessionState(PlaybackStateCompat.STATE_STOPPED);
        }
        if (currentState == State.STOPPED) {
            mediaPlayer.reset();
            currentState = State.IDLE;
            updateSessionState(PlaybackStateCompat.STATE_STOPPED);
            showNotification();
        }
        if (currentState == State.IDLE) {
            try {
                currentTrackIndex--;
                updateSessionState(PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS);
                cueTrack();
            } catch (Exception e) {
                stop();
            }
        }
    }
}

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

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*from  w  w w.  j  av a2 s. c o m*/
    }
    mLastPlaybackState = state;
    String castName = mMediaController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
    String line3Text = "";
    if (castName != null) {
        line3Text = 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:cat.terrones.devops.radiofx.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from  w  w w  .j  a  v a2 s  .  com
    }
    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 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:androidx.media.MediaUtils2.java

static int toPlayerState(int playbackStateCompatState) {
    switch (playbackStateCompatState) {
    case PlaybackStateCompat.STATE_ERROR:
        return MediaPlayerBase.PLAYER_STATE_ERROR;
    case PlaybackStateCompat.STATE_NONE:
        return MediaPlayerBase.PLAYER_STATE_IDLE;
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
    case PlaybackStateCompat.STATE_BUFFERING: // means paused for buffering.
        return MediaPlayerBase.PLAYER_STATE_PAUSED;
    case PlaybackStateCompat.STATE_FAST_FORWARDING:
    case PlaybackStateCompat.STATE_PLAYING:
    case PlaybackStateCompat.STATE_REWINDING:
    case PlaybackStateCompat.STATE_SKIPPING_TO_NEXT:
    case PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS:
    case PlaybackStateCompat.STATE_SKIPPING_TO_QUEUE_ITEM:
    case PlaybackStateCompat.STATE_CONNECTING: // Note: there's no perfect match for this.
        return MediaPlayerBase.PLAYER_STATE_PLAYING;
    }//from w  w  w.  j a v a2 s .  co  m
    return MediaPlayerBase.PLAYER_STATE_ERROR;
}

From source file:rocks.stalin.android.app.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//  w w w.jav  a2s  . c o  m
    }
    mLastPlaybackState = state;
    if (MediaControllerCompat.getMediaController(this) != null
            && MediaControllerCompat.getMediaController(this).getExtras() != null) {
        String castName = MediaControllerCompat.getMediaController(this).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.bayapps.android.robophish.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*  w w  w .  j av  a2 s  .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);
        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.murati.oszk.audiobook.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from  w  w w.j  ava 2s  .  c  o  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.scooter1556.sms.android.activity.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from  www  .jav a2 s .c  om
    }

    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: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.//from  ww  w . j av  a2  s.  co  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);
    }
}