Example usage for android.support.v4.media.session MediaControllerCompat getPlaybackState

List of usage examples for android.support.v4.media.session MediaControllerCompat getPlaybackState

Introduction

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

Prototype

public PlaybackStateCompat getPlaybackState() 

Source Link

Usage

From source file:nuclei.media.MediaPlayerController.java

public static boolean isPlaying(MediaControllerCompat mediaControllerCompat,
        PlaybackStateCompat playbackStateCompat, MediaId mediaId) {
    if (isEquals(mediaControllerCompat, mediaId)) {
        if (playbackStateCompat == null)
            playbackStateCompat = mediaControllerCompat.getPlaybackState();
        int state = -1;
        if (playbackStateCompat != null)
            state = playbackStateCompat.getState();
        return state == PlaybackStateCompat.STATE_BUFFERING || state == PlaybackStateCompat.STATE_PLAYING;
    }//from w  w w. j  a  v a2  s  . com
    return false;
}

From source file:com.thelotradio.android.PlayerActivity.java

@Override
public void onClick(View view) {
    MediaControllerCompat controller = getSupportMediaController();
    if (controller != null) {
        int state = controller.getPlaybackState().getState();
        if (state == PlaybackStateCompat.STATE_PAUSED) {
            controller.getTransportControls().play();
        } else if (state == PlaybackStateCompat.STATE_PLAYING) {
            controller.getTransportControls().pause();
        }//from w w  w .j av  a2  s .c o  m
    }
}

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

protected boolean shouldShowControls() {
    MediaControllerCompat mediaController = getSupportMediaController();

    if (mediaController == null || mediaController.getMetadata() == null
            || mediaController.getPlaybackState() == null) {
        return false;
    }//from ww w.j  a  v a 2s .  com

    switch (mediaController.getPlaybackState().getState()) {
    case PlaybackStateCompat.STATE_ERROR:
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        return false;
    default:
        return true;
    }
}

From source file:com.appdevper.mediaplayer.activity.BaseActivity.java

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

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 w w  w  .j av a  2  s . 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.scooter1556.sms.android.activity.BaseActivity.java

/**
 * Check if the Media Session is active/*from   w w  w  . ja  v a2  s.c om*/
 */
protected boolean shouldShowControls() {
    MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(this);

    if (mediaController == null || mediaController.getMetadata() == null
            || mediaController.getPlaybackState() == null) {
        return false;
    }

    switch (mediaController.getPlaybackState().getState()) {
    case PlaybackStateCompat.STATE_ERROR:
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        return false;
    default:
        return true;
    }
}

From source file:com.murati.oszk.audiobook.ui.BaseActivity.java

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

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 ww  . ja  v a2  s  .c o  m*/
    } 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:rocks.stalin.android.app.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;//w  w  w.  ja  va 2  s . c  om
    } else {
        // otherwise, if state is ERROR and metadata!=null, use playback state error message:
        MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
        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) {
            // Finally, if the caller requested to show error, show a generic message:
            mErrorMessage.setText(R.string.error_loading_media);
            showError = true;
            PermissionHelper.requestMissingPermissions(getActivity(),
                    PermissionHelper.SHOULD_RECREATE_ACTIVITY);
        }
    }
    mErrorView.setVisibility(showError ? View.VISIBLE : View.GONE);
    LogHelper.d(TAG, "checkForUserVisibleErrors. forceError=", forceError, " showError=", showError,
            " isOnline=", NetworkHelper.isOnline(getActivity()));
}

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

private void checkForUserVisibleErrors(boolean forceError) {
    boolean showError = forceError;
    // If offline, message is about the lack of connectivity:
    if (!Utils.isOnline(getActivity())) {
        mErrorMessage.setText(R.string.error_no_connection);
        showError = true;//  w w  w .ja v  a 2 s . com
    } else {
        // otherwise, if state is ERROR and metadata!=null, use playback state error message:
        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) {
            // 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);
    Log.d(TAG, "checkForUserVisibleErrors. forceError=" + forceError + " showError=" + showError + " isOnline="
            + Utils.isOnline(getActivity()));
}