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

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

Introduction

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

Prototype

int STATE_ERROR

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

Click Source Link

Document

State indicating this item is currently in an error state.

Usage

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

@Override
public void setState(int state) {
    mState = state;//www .  ja  v a 2s .  c o  m
    if (state == PlaybackStateCompat.STATE_ERROR) {
        try {
            mCurrentPosition = getCurrentStreamPosition();
        } catch (Exception err) {
            LOG.e("Error capturing current pos", err);
        }
    }
}

From source file:rocks.stalin.android.app.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;// w  w w  .  java  2s.  com
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.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 = MediaControllerCompat.getMediaController(getActivity());
    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.classiqo.nativeandroid_32bitz.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   w  w  w.j a  v a  2  s.c o m*/
    }

    if (state == null) {
        return;
    }

    boolean enablePlay = false;

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.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.bayapps.android.robophish.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;/*  w  ww .  j  a v a  2  s .  c  om*/
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.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.torrenttunes.android.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 www .j a v a2s .  c o  m
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.STATE_ERROR:
        LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
        Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
        break;
    }

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

    MediaControllerCompat controller = mMediaControllerProvider.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.pi.android.brainbeats.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   w  ww  .j  ava 2  s. c o m
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.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);
        }
    }
    final MediaMetadataCompat metadata = controller.getMetadata();
    if (metadata != null) {
        updateTags(metadata);
    }
    setExtraInfo(extraInfo);
}

From source file:nuclei.media.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.
 *//*www  .j a va  2 s . c  om*/
public void updatePlaybackState(Exception error, boolean canPause) {
    long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
    if (mPlayback != null && mPlayback.isConnected()) {
        position = mPlayback.getCurrentStreamPosition();
    }

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

    int state = mPlayback == null ? PlaybackStateCompat.STATE_NONE : mPlayback.getState();

    // If there is an error message, send it to the playback state:
    if (error != null) {
        mHandler.removeMessages(TIMER_COUNTDOWN);
        mHandler.removeMessages(TIMER_TIMING);
        int errorCode = ResourceProvider.getInstance().getExceptionCode(error);
        String message = ResourceProvider.getInstance().getExceptionMessage(error);
        if (message == null)
            message = error.getMessage();
        // 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(errorCode, message);
        state = PlaybackStateCompat.STATE_ERROR;
        if (mPlayback != null) {
            int lastState = state;
            mPlayback.setState(state);
            if (mPlayback.isPlaying()) {
                mPlayback.setState(lastState);
                state = lastState;
            } else if (canPause) {
                mPlayback.pause();
            }
        }
        MediaProvider.getInstance().onError(error);
    }

    float audioSpeed;
    if (mPlayback instanceof CastPlayback)
        audioSpeed = 1;
    else
        audioSpeed = mServiceCallback.getAudioSpeed();

    //noinspection ResourceType
    stateBuilder.setState(state, position, audioSpeed, SystemClock.elapsedRealtime());

    mServiceCallback.onPlaybackStateUpdated(stateBuilder.build());

    if (state == PlaybackStateCompat.STATE_PLAYING) {
        if (mTimer > -1 && !mHandler.hasMessages(TIMER_COUNTDOWN))
            mHandler.sendEmptyMessageDelayed(TIMER_COUNTDOWN, ONE_SECOND);
        if (mPlayback.getTiming() != null && !mHandler.hasMessages(TIMER_TIMING))
            mHandler.sendEmptyMessageDelayed(TIMER_TIMING, ONE_SECOND);
    }

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

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

private void checkForUserVisibleErrors(boolean forceError) {
    boolean showError = forceError;

    if (!NetworkHelper.isOnline(getActivity())) {
        mErrorMessage.setText(R.string.error_no_connection);
        showError = true;//from   w  w  w.j a  va2 s. c  om
    } else {
        MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();

        if (controller != null && controller.getMetadata() != null && controller.getPlaybackState() != null
                && controller.getPlaybackState().getState() == PlaybackStateCompat.STATE_ERROR
                && controller.getPlaybackState().getErrorMessage() != null) {
            mErrorMessage.setText(controller.getPlaybackState().getErrorMessage());
            showError = true;
        } else if (forceError) {
            mErrorMessage.setText(R.string.error_loading_media);
            showError = true;
        }
    }
    mErrorView.setVisibility(showError ? View.VISIBLE : View.GONE);

    LogHelper.d(TAG, "checkForUserVisibleErrors.forceError = ", forceError, " showError = ", showError,
            " isOnline = ", NetworkHelper.isOnline(getActivity()));
}

From source file:net.simno.klingar.ui.BrowserController.java

private void observePlayback() {
    disposables.add(musicController.state().compose(bindUntilEvent(DETACH)).compose(rx.flowableSchedulers())
            .subscribe(state -> {//from  w  w  w . j  a v a  2 s.  c om
                switch (state) {
                case PlaybackStateCompat.STATE_ERROR:
                case PlaybackStateCompat.STATE_NONE:
                case PlaybackStateCompat.STATE_STOPPED:
                    for (Router router : getChildRouters()) {
                        removeChildRouter(router);
                    }
                    break;
                default:
                    Router miniplayerRouter = getChildRouter(miniplayerContainer);
                    if (!miniplayerRouter.hasRootController()) {
                        miniplayerRouter.setRoot(RouterTransaction.with(new MiniPlayerController(null)));
                    }
                }
            }, Rx::onError));
}

From source file:com.achep.acdisplay.ui.components.MediaWidget.java

@Override
public void onPlaybackStateChanged(int state) {

    // Making transformation rule for the warning icon is too
    // much overkill for me.
    if (state == PlaybackStateCompat.STATE_ERROR) {
        mButtonPlayPause.setImageDrawable(mWarningDrawable);
    } else {//w w  w  . j  ava  2s  . c om
        mButtonPlayPause.setImageDrawable(mPlayPauseDrawable);
    }

    if (DEBUG)
        Log.d(TAG, "Playback state is " + state);

    final int imageDescId;
    switch (state) {
    case PlaybackStateCompat.STATE_ERROR:
        imageDescId = R.string.media_play_description;
        break;
    case PlaybackStateCompat.STATE_PLAYING:
        mPlayPauseDrawable.transformToPause();
        imageDescId = R.string.media_pause_description;
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
    case PlaybackStateCompat.STATE_STOPPED:
        mPlayPauseDrawable.transformToStop();
        imageDescId = R.string.media_stop_description;
        break;
    case PlaybackStateCompat.STATE_PAUSED:
    default:
        mPlayPauseDrawable.transformToPlay();
        imageDescId = R.string.media_play_description;
        break;
    }

    mButtonPlayPause.setContentDescription(getFragment().getString(imageDescId));
}