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

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

Introduction

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

Prototype

int ERROR_CODE_UNKNOWN_ERROR

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

Click Source Link

Document

This is the default error code and indicates that none of the other error codes applies.

Usage

From source file:rocks.stalin.android.app.playback.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.
 *//*from  w w w.  j av a  2 s .  com*/
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(PlaybackStateCompat.ERROR_CODE_UNKNOWN_ERROR, 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();
    }
}