Java Code Examples for android.media.session.PlaybackState#ACTION_SKIP_TO_PREVIOUS

The following examples show how to use android.media.session.PlaybackState#ACTION_SKIP_TO_PREVIOUS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicBrowserService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private long getAvailableActions() {
    long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PLAY_FROM_SEARCH;
    MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
    if (playingMessageObject != null) {
        if (!MediaController.getInstance().isMessagePaused()) {
            actions |= PlaybackState.ACTION_PAUSE;
        }
        actions |= PlaybackState.ACTION_SKIP_TO_PREVIOUS;
        actions |= PlaybackState.ACTION_SKIP_TO_NEXT;
    }
    return actions;
}
 
Example 2
Source File: MusicBrowserService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private long getAvailableActions() {
    long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PLAY_FROM_SEARCH;
    MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
    if (playingMessageObject != null) {
        if (!MediaController.getInstance().isMessagePaused()) {
            actions |= PlaybackState.ACTION_PAUSE;
        }
        actions |= PlaybackState.ACTION_SKIP_TO_PREVIOUS;
        actions |= PlaybackState.ACTION_SKIP_TO_NEXT;
    }
    return actions;
}
 
Example 3
Source File: PlaybackManager.java    From android-music-player with Apache License 2.0 5 votes vote down vote up
private long getAvailableActions() {
    long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID |
            PlaybackState.ACTION_PLAY_FROM_SEARCH |
            PlaybackState.ACTION_SKIP_TO_NEXT  | PlaybackState.ACTION_SKIP_TO_PREVIOUS;
    if (isPlaying()) {
        actions |= PlaybackState.ACTION_PAUSE;
    }
    return actions;
}
 
Example 4
Source File: PlaybackManager.java    From android-music-player with Apache License 2.0 5 votes vote down vote up
private long getAvailableActions() {
    long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID |
            PlaybackState.ACTION_PLAY_FROM_SEARCH |
            PlaybackState.ACTION_SKIP_TO_NEXT  | PlaybackState.ACTION_SKIP_TO_PREVIOUS;
    if (isPlaying()) {
        actions |= PlaybackState.ACTION_PAUSE;
    }
    return actions;
}
 
Example 5
Source File: PlaybackManager.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
private long getAvailableActions() {
    long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID |
            PlaybackState.ACTION_PLAY_FROM_SEARCH |
            PlaybackState.ACTION_SKIP_TO_NEXT  | PlaybackState.ACTION_SKIP_TO_PREVIOUS;
    if (isPlaying()) {
        actions |= PlaybackState.ACTION_PAUSE;
    }
    return actions;
}
 
Example 6
Source File: PlaybackManager.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
private long getAvailableActions() {
    long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID |
            PlaybackState.ACTION_PLAY_FROM_SEARCH |
            PlaybackState.ACTION_SKIP_TO_NEXT  | PlaybackState.ACTION_SKIP_TO_PREVIOUS;
    if (isPlaying()) {
        actions |= PlaybackState.ACTION_PAUSE;
    }
    return actions;
}
 
Example 7
Source File: MusicBrowserService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private long getAvailableActions() {
    long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PLAY_FROM_SEARCH;
    MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
    if (playingMessageObject != null) {
        if (!MediaController.getInstance().isMessagePaused()) {
            actions |= PlaybackState.ACTION_PAUSE;
        }
        actions |= PlaybackState.ACTION_SKIP_TO_PREVIOUS;
        actions |= PlaybackState.ACTION_SKIP_TO_NEXT;
    }
    return actions;
}
 
Example 8
Source File: MusicBrowserService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private long getAvailableActions() {
    long actions = PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PLAY_FROM_MEDIA_ID | PlaybackState.ACTION_PLAY_FROM_SEARCH;
    MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
    if (playingMessageObject != null) {
        if (!MediaController.getInstance().isMessagePaused()) {
            actions |= PlaybackState.ACTION_PAUSE;
        }
        actions |= PlaybackState.ACTION_SKIP_TO_PREVIOUS;
        actions |= PlaybackState.ACTION_SKIP_TO_NEXT;
    }
    return actions;
}
 
Example 9
Source File: MediaNotificationManager.java    From android-music-player with Apache License 2.0 4 votes vote down vote up
public void update(MediaMetadata metadata, PlaybackState state, MediaSession.Token token) {
    if (state == null || state.getState() == PlaybackState.STATE_STOPPED ||
            state.getState() == PlaybackState.STATE_NONE) {
        mService.stopForeground(true);
        try {
            mService.unregisterReceiver(this);
        } catch (IllegalArgumentException ex) {
            // ignore receiver not registered
        }
        mService.stopSelf();
        return;
    }
    if (metadata == null) {
        return;
    }
    boolean isPlaying = state.getState() == PlaybackState.STATE_PLAYING;
    Notification.Builder notificationBuilder = new Notification.Builder(mService);
    MediaDescription description = metadata.getDescription();

    notificationBuilder
            .setStyle(new Notification.MediaStyle()
                    .setMediaSession(token)
                    .setShowActionsInCompactView(0, 1, 2))
            .setColor(mService.getApplication().getResources().getColor(R.color.notification_bg))
            .setSmallIcon(R.drawable.ic_notification)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setContentIntent(createContentIntent())
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setLargeIcon(MusicLibrary.getAlbumBitmap(mService, description.getMediaId()))
            .setOngoing(isPlaying)
            .setWhen(isPlaying ? System.currentTimeMillis() - state.getPosition() : 0)
            .setShowWhen(isPlaying)
            .setUsesChronometer(isPlaying);

    // If skip to next action is enabled
    if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(mPrevAction);
    }

    notificationBuilder.addAction(isPlaying ? mPauseAction : mPlayAction);

    // If skip to prev action is enabled
    if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(mNextAction);
    }

    Notification notification = notificationBuilder.build();

    if (isPlaying && !mStarted) {
        mService.startService(new Intent(mService.getApplicationContext(), MusicService.class));
        mService.startForeground(NOTIFICATION_ID, notification);
        mStarted = true;
    } else {
        if (!isPlaying) {
            mService.stopForeground(false);
            mStarted = false;
        }
        mNotificationManager.notify(NOTIFICATION_ID, notification);
    }
}
 
Example 10
Source File: MediaNotificationManager.java    From io2015-codelabs with Apache License 2.0 4 votes vote down vote up
public void update(MediaMetadata metadata, PlaybackState state, MediaSession.Token token) {
    if (state == null || state.getState() == PlaybackState.STATE_STOPPED ||
            state.getState() == PlaybackState.STATE_NONE) {
        mService.stopForeground(true);
        try {
            mService.unregisterReceiver(this);
        } catch (IllegalArgumentException ex) {
            // ignore receiver not registered
        }
        mService.stopSelf();
        return;
    }
    if (metadata == null) {
        return;
    }
    boolean isPlaying = state.getState() == PlaybackState.STATE_PLAYING;
    Notification.Builder notificationBuilder = new Notification.Builder(mService);
    MediaDescription description = metadata.getDescription();

    notificationBuilder
            .setStyle(new Notification.MediaStyle()
                    .setMediaSession(token)
                    .setShowActionsInCompactView(0, 1, 2))
            .setColor(mService.getApplication().getResources().getColor(R.color.notification_bg))
            .setSmallIcon(R.drawable.ic_notification)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .setContentIntent(createContentIntent())
            .setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle())
            .setLargeIcon(MusicLibrary.getAlbumBitmap(mService, description.getMediaId()))
            .setOngoing(isPlaying)
            .setWhen(isPlaying ? System.currentTimeMillis() - state.getPosition() : 0)
            .setShowWhen(isPlaying)
            .setUsesChronometer(isPlaying);

    // If skip to next action is enabled
    if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(mPrevAction);
    }

    notificationBuilder.addAction(isPlaying ? mPauseAction : mPlayAction);

    // If skip to prev action is enabled
    if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(mNextAction);
    }

    Notification notification = notificationBuilder.build();

    if (isPlaying && !mStarted) {
        mService.startService(new Intent(mService.getApplicationContext(), MusicService.class));
        mService.startForeground(NOTIFICATION_ID, notification);
        mStarted = true;
    } else {
        if (!isPlaying) {
            mService.stopForeground(false);
            mStarted = false;
        }
        mNotificationManager.notify(NOTIFICATION_ID, notification);
    }
}