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

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

Introduction

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

Prototype

int STATE_PLAYING

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

Click Source Link

Document

State indicating this item is currently playing.

Usage

From source file:com.bullmobi.message.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}/*from  w  w  w  . ja v  a 2  s. c o m*/
 */
protected MediaController2KitKat(@NonNull Activity activity) {
    super(activity);

    SparseIntArray cachedStateSparse = sStateSparse.get();
    if (cachedStateSparse == null) {
        mStateSparse = new SparseIntArray();
        mStateSparse.put(RemoteControlClient.PLAYSTATE_BUFFERING, PlaybackStateCompat.STATE_BUFFERING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_PLAYING, PlaybackStateCompat.STATE_PLAYING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_PAUSED, PlaybackStateCompat.STATE_PAUSED);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_ERROR, PlaybackStateCompat.STATE_ERROR);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_REWINDING, PlaybackStateCompat.STATE_REWINDING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_FAST_FORWARDING,
                PlaybackStateCompat.STATE_FAST_FORWARDING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS,
                PlaybackStateCompat.STATE_SKIPPING_TO_NEXT);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS,
                PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS);

        // Cache sparse array
        sStateSparse = new WeakReference<>(mStateSparse);
    } else {
        mStateSparse = cachedStateSparse;
    }
}

From source file:com.classiqo.nativeandroid_32bitz.playback.PlaybackManager.java

public void updatePlaybackState(String error) {
    LogHelper.d(TAG, "updatePlaybackState, playback state = " + mPlayback.getState());

    long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
    if (mPlayback != null && mPlayback.isConnected()) {
        position = mPlayback.getCurrentStreamPosition();
    }// ww  w.j av  a2s .c o m

    //noinspection ResourceType
    PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
            .setActions(getAvailableActions());

    setCustomAction(stateBuilder);
    int state = mPlayback.getState();

    if (error != null) {
        stateBuilder.setErrorMessage(error);
        state = PlaybackStateCompat.STATE_ERROR;
    }
    //noinspection ResourceType
    stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());

    MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic();

    if (currentMusic != null) {
        stateBuilder.setActiveQueueItemId(currentMusic.getQueueId());
    }

    mServiceCallback.onPlaybackStateUpdated(stateBuilder.build());

    if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_PAUSED) {
        mServiceCallback.onNotificationRequired();
    }
}

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

/**
 * Start playing the previously prepared {@link org.runbuddy.libtomahawk.collection.Track}
 *///ww  w  .j av  a2 s . c  o  m
@Override
public void play() throws IllegalStateException {
    Log.d(TAG, "play()");
    mPlayState = PlaybackStateCompat.STATE_PLAYING;
    handlePlayState();
}

From source file:com.example.android.supportv7.media.Player.java

protected void publishState(int state) {
    if (mMediaSession == null) {
        return;/*  w  w w  . j  a v  a2s  .co m*/
    }
    PlaybackStateCompat.Builder bob = new PlaybackStateCompat.Builder();
    bob.setActions(PLAYBACK_ACTIONS);
    switch (state) {
    case STATE_PLAYING:
        bob.setState(PlaybackStateCompat.STATE_PLAYING, -1, 1);
        break;
    case STATE_READY:
    case STATE_PAUSED:
        bob.setState(PlaybackStateCompat.STATE_PAUSED, -1, 0);
        break;
    case STATE_IDLE:
        bob.setState(PlaybackStateCompat.STATE_STOPPED, -1, 0);
        break;
    }
    PlaybackStateCompat pbState = bob.build();
    Log.d(TAG, "Setting state to " + pbState);
    mMediaSession.setPlaybackState(pbState);
    if (state != STATE_IDLE) {
        mMediaSession.setActive(true);
    } else {
        mMediaSession.setActive(false);
    }
}

From source file:com.classiqo.nativeandroid_32bitz.ui.MediaItemViewHolder.java

public static int getStateFromController(Context context) {
    MediaControllerCompat controller = ((FragmentActivity) context).getSupportMediaController();
    PlaybackStateCompat pbState = controller.getPlaybackState();

    if (pbState == null || pbState.getState() == PlaybackStateCompat.STATE_ERROR) {
        return MediaItemViewHolder.STATE_NONE;
    } else if (pbState.getState() == PlaybackStateCompat.STATE_PLAYING) {
        return MediaItemViewHolder.STATE_PLAYING;
    } else {/*from  www . j a  va 2 s  .  c  o m*/
        return MediaItemViewHolder.STATE_PAUSED;
    }
}

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

public static int getStateFromController(Context context) {
    MediaControllerCompat controller = ((FragmentActivity) context).getSupportMediaController();
    PlaybackStateCompat pbState = controller.getPlaybackState();
    if (pbState == null || pbState.getState() == PlaybackStateCompat.STATE_ERROR) {
        return MediaItemViewHolder.STATE_NONE;
    } else if (pbState.getState() == PlaybackStateCompat.STATE_PLAYING) {
        return MediaItemViewHolder.STATE_PLAYING;
    } else {/*from   ww w  .  j a v a2s . c o  m*/
        return MediaItemViewHolder.STATE_PAUSED;
    }
}

From source file:com.doctoror.fuckoffmusicplayer.data.reporter.MediaSessionPlaybackReporter.java

@Override
public void reportPlaybackStateChanged(@NonNull final PlaybackState state,
        @Nullable final CharSequence errorMessage) {
    @PlaybackStateCompat.State//from w  w w.  j a v  a2 s .co m
    final int playbackState = toPlaybackStateCompat(state);
    final boolean isPlaying = playbackState == PlaybackStateCompat.STATE_PLAYING;
    final PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder()
            .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE
                    | PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_STOP
                    | PlaybackStateCompat.ACTION_SKIP_TO_NEXT | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
                    | PlaybackStateCompat.ACTION_SEEK_TO | PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH)
            .setState(playbackState, 0, isPlaying ? 1 : 0);

    if (errorMessage != null) {
        builder.setErrorMessage(PlaybackStateCompat.ERROR_CODE_APP_ERROR, errorMessage);
    }

    mMediaSession.setPlaybackState(builder.build());
}

From source file:com.doctoror.fuckoffmusicplayer.data.reporter.MediaSessionPlaybackReporter.java

@PlaybackStateCompat.State
private static int toPlaybackStateCompat(@NonNull final PlaybackState state) {
    switch (state) {
    case STATE_LOADING:
        return PlaybackStateCompat.STATE_BUFFERING;

    case STATE_PLAYING:
        return PlaybackStateCompat.STATE_PLAYING;

    case STATE_PAUSED:
        return PlaybackStateCompat.STATE_PAUSED;

    case STATE_ERROR:
        return PlaybackStateCompat.STATE_ERROR;

    case STATE_IDLE:
    default://from ww  w . j  a v  a 2s . c o m
        return PlaybackStateCompat.STATE_NONE;
    }
}

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

public static int getStateFromController(Context context) {
    MediaControllerCompat controller = MediaControllerCompat.getMediaController((FragmentActivity) context);
    PlaybackStateCompat pbState = controller.getPlaybackState();
    if (pbState == null || pbState.getState() == PlaybackStateCompat.STATE_ERROR) {
        return MediaItemViewHolder.STATE_NONE;
    } else if (pbState.getState() == PlaybackStateCompat.STATE_PLAYING) {
        return MediaItemViewHolder.STATE_PLAYING;
    } else {//w w  w.  j av a 2s. c om
        return MediaItemViewHolder.STATE_PAUSED;
    }
}

From source file:com.appdevper.mediaplayer.app.PlaybackManager.java

/**
 * Update the current media player state, optionally showing an error message.
 *
 * @param error if not null, error message to present to the user.
 *///  ww  w  .  ja  v a 2 s.c  om
public void updatePlaybackState(String error) {
    LogHelper.d(TAG, "updatePlaybackState, playback state=" + mPlayback.getState());
    long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
    if (mPlayback != null && mPlayback.isConnected()) {
        position = mPlayback.getCurrentStreamPosition();
    }

    //noinspection ResourceType
    PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
            .setActions(getAvailableActions());

    setCustomAction(stateBuilder);
    int state = mPlayback.getState();

    // If there is an error message, send it to the playback state:
    if (error != null) {
        // Error states are really only supposed to be used for errors that cause playback to
        // stop unexpectedly and persist until the user takes action to fix it.
        stateBuilder.setErrorMessage(error);
        state = PlaybackStateCompat.STATE_ERROR;
    }
    //noinspection ResourceType
    stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());

    // Set the activeQueueItemId if the current index is valid.
    MediaSessionCompat.QueueItem currentMusic = mQueueManager.getCurrentMusic();
    if (currentMusic != null) {
        stateBuilder.setActiveQueueItemId(currentMusic.getQueueId());
    }

    mServiceCallback.onPlaybackStateUpdated(stateBuilder.build());

    if (state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_PAUSED) {
        mServiceCallback.onNotificationRequired();
    }
}