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

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

Introduction

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

Prototype

@State
public int getState() 

Source Link

Document

Get the current state of playback.

Usage

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  w  w w.  j  av a  2s.  c o  m*/
        return MediaItemViewHolder.STATE_PAUSED;
    }
}

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 {//from w w w .j  a  v a2 s .  c o  m
        return MediaItemViewHolder.STATE_PAUSED;
    }
}

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 w w w. ja va 2  s .  c o m*/
        return MediaItemViewHolder.STATE_PAUSED;
    }
}

From source file:org.opensilk.music.ui3.main.MainPresenter.java

public static boolean isActive(PlaybackStateCompat state) {
    switch (state.getState()) {
    case STATE_FAST_FORWARDING:
    case STATE_REWINDING:
    case STATE_SKIPPING_TO_PREVIOUS:
    case STATE_SKIPPING_TO_NEXT:
    case STATE_BUFFERING:
    case STATE_CONNECTING:
    case STATE_PLAYING:
        return true;
    }//from   www.j  a v a 2s.c  o m
    return false;
}

From source file:org.opensilk.music.ui3.main.MainPresenter.java

public static boolean isPlaying(PlaybackStateCompat state) {
    switch (state.getState()) {
    //            case STATE_FAST_FORWARDING:
    //            case STATE_REWINDING:
    //            case STATE_SKIPPING_TO_PREVIOUS:
    //            case STATE_SKIPPING_TO_NEXT:
    //            case STATE_BUFFERING:
    //            case STATE_CONNECTING:
    case STATE_PLAYING:
        return true;
    }/*from  w ww . ja  va2s .co m*/
    return false;
}

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

public static Notification createNotification(Context context, MediaSessionCompat mediaSession) {
    MediaControllerCompat controller = mediaSession.getController();
    MediaMetadataCompat mMetadata = controller.getMetadata();
    PlaybackStateCompat mPlaybackState = controller.getPlaybackState();

    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }/*from   www .  j ava2 s  .  co m*/

    boolean isPlaying = mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING;
    NotificationCompat.Action action = isPlaying
            ? new NotificationCompat.Action(R.drawable.ic_pause_white_24dp,
                    context.getString(R.string.label_pause),
                    MediaButtonReceiver.buildMediaButtonPendingIntent(context,
                            PlaybackStateCompat.ACTION_PAUSE))
            : new NotificationCompat.Action(R.drawable.ic_play_arrow_white_24dp,
                    context.getString(R.string.label_play), MediaButtonReceiver
                            .buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_PLAY));

    MediaDescriptionCompat description = mMetadata.getDescription();
    Bitmap art = description.getIconBitmap();
    if (art == null) {
        // use a placeholder art while the remote art is being downloaded.
        art = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_default_art);
    }

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
    notificationBuilder.setStyle(new NotificationCompat.MediaStyle()
            // show only play/pause in compact view.
            .setShowActionsInCompactView(new int[] { 0 }).setMediaSession(mediaSession.getSessionToken()))
            .addAction(action).setSmallIcon(R.drawable.ic_notification).setShowWhen(false)
            .setContentIntent(controller.getSessionActivity()).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle()).setLargeIcon(art)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

    return notificationBuilder.build();
}

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

public static int getStateFromController(Activity context) {
    MediaControllerCompat controller = MediaControllerCompat.getMediaController(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 {/*from   www . j  ava2 s. c o  m*/
        return MediaItemViewHolder.STATE_PAUSED;
    }
}

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;
    }//  w  w w .  ja va2  s.  c  o m
    return false;
}

From source file:net.simno.klingar.playback.MusicController.java

public void playPause() {
    PlaybackStateCompat state = mediaController.getPlaybackState();
    if (state != null) {
        switch (state.getState()) {
        case STATE_PLAYING:
        case STATE_BUFFERING:
            pause();/*from   w  w w .j av  a2 s .co m*/
            break;
        case STATE_PAUSED:
        case STATE_STOPPED:
            play();
            break;
        default:
        }
    }
}

From source file:info.tongrenlu.MediaNotificationManager.java

/**
 * Posts the notification and starts tracking the session to keep it
 * updated. The notification will automatically be removed if the session is
 * destroyed before {@link #stopNotification} is called.
 */// w w w  .ja va 2 s.c om
public void startNotification(PlaybackStateCompat playbackState) {
    Log.d(TAG, "startNotification, state = " + playbackState.getState());
    if (!mStarted) {
        mPlaybackState = playbackState;
        Notification notification = createNotification();
        if (notification != null) {
            mService.startForeground(NOTIFICATION_ID, notification);
            mStarted = true;
        }
    }
}