Example usage for android.media.session PlaybackState STATE_ERROR

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

Introduction

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

Prototype

int STATE_ERROR

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

Click Source Link

Document

State indicating this item is currently in an error state.

Usage

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

/**
 * Check if the MediaSession is active and in a "playback-able" state
 * (not NONE and not STOPPED)./*from   ww  w. j a  v  a2s.c  o  m*/
 *
 * @return true if the MediaSession's state requires playback controls to be visible.
 */
protected boolean shouldShowControls() {
    MediaControllerCompat mediaController = mMediaController;
    if (mediaController == null || mediaController.getMetadata() == null
            || mediaController.getPlaybackState() == null) {
        return false;
    }
    switch (mediaController.getPlaybackState().getState()) {
    case PlaybackState.STATE_ERROR:
    case PlaybackState.STATE_NONE:
    case PlaybackState.STATE_STOPPED:
        return false;
    default:
        return true;
    }
}

From source file:com.example.android.mediabrowserservice.QueueFragment.java

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (state == null) {
        return;//from www.  j a  v a 2  s  . c om
    }
    mQueueAdapter.setActiveQueueItemId(state.getActiveQueueItemId());
    mQueueAdapter.notifyDataSetChanged();
    boolean enablePlay = false;
    StringBuilder statusBuilder = new StringBuilder();
    switch (state.getState()) {
    case PlaybackState.STATE_PLAYING:
        statusBuilder.append("playing");
        enablePlay = false;
        break;
    case PlaybackState.STATE_PAUSED:
        statusBuilder.append("paused");
        enablePlay = true;
        break;
    case PlaybackState.STATE_STOPPED:
        statusBuilder.append("ended");
        enablePlay = true;
        break;
    case PlaybackState.STATE_ERROR:
        statusBuilder.append("error: ").append(state.getErrorMessage());
        break;
    case PlaybackState.STATE_BUFFERING:
        statusBuilder.append("buffering");
        break;
    case PlaybackState.STATE_NONE:
        statusBuilder.append("none");
        enablePlay = false;
        break;
    case PlaybackState.STATE_CONNECTING:
        statusBuilder.append("connecting");
        break;
    default:
        statusBuilder.append(mPlaybackState);
    }
    statusBuilder.append(" -- At position: ").append(state.getPosition());
    LogHelper.d(TAG, statusBuilder.toString());

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

    mSkipPrevious.setEnabled((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0);
    mSkipNext.setEnabled((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0);

    LogHelper.d(TAG, "Queue From MediaController *** Title " + mMediaController.getQueueTitle() + "\n: Queue: "
            + mMediaController.getQueue() + "\n Metadata " + mMediaController.getMetadata());
}

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   w w w  . j av a  2  s . 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.torrenttunes.android.ui.MediaBrowserFragment.java

private void checkForUserVisibleErrors(boolean forceError) {
    boolean showError = forceError;
    // If offline, message is about the lack of connectivity:
    if (!NetworkHelper.isOnline(getActivity())) {
        mErrorMessage.setText(R.string.error_no_connection);
        showError = true;//from   w w  w .j  av  a 2 s .c o  m
    } else {
        // otherwise, if state is ERROR and metadata!=null, use playback state error message:
        MediaControllerCompat controller = mMediaControllerProvider.getSupportMediaController();
        if (controller != null && controller.getMetadata() != null
                && controller.getPlaybackState().getState() == PlaybackState.STATE_ERROR
                && controller.getPlaybackState().getErrorMessage() != null) {
            mErrorMessage.setText(controller.getPlaybackState().getErrorMessage());
            showError = true;
        } else if (forceError) {
            // Finally, if the caller requested to show error, show a generic message:
            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()));
}