Java Code Examples for androidx.media.session.MediaButtonReceiver#buildMediaButtonPendingIntent()

The following examples show how to use androidx.media.session.MediaButtonReceiver#buildMediaButtonPendingIntent() . 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: NotificationBuilder.java    From YouTube-In-Background with MIT License 5 votes vote down vote up
public NotificationBuilder(Context context)
{
    this.context = context;

    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    skipToPreviousAction = new Action(
            R.drawable.exo_controls_previous,
            context.getString(R.string.notification_skip_to_previous),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_SKIP_TO_PREVIOUS)
    );
    playAction = new Action(
            R.drawable.exo_controls_play,
            context.getString(R.string.notification_play),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_PLAY)
    );
    pauseAction = new Action(
            R.drawable.exo_controls_pause,
            context.getString(R.string.notification_pause),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_PAUSE)
    );
    skipToNextAction = new Action(
            R.drawable.exo_controls_next,
            context.getString(R.string.notification_skip_to_next),
            MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_SKIP_TO_NEXT)
    );

    stopPendingIntent = MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_STOP);
}
 
Example 2
Source File: PlayerService.java    From Jockey with Apache License 2.0 5 votes vote down vote up
/**
 * Generate and post a notification for the current player status
 * Posts the notification by starting the service in the foreground
 */
private void notifyNowPlaying(boolean foreground) {
    Timber.i("notifyNowPlaying called");

    if (musicPlayer == null || musicPlayer.getMediaSession() == null) {
        Timber.i("Not showing notification. Media session is uninitialized");
        return;
    }

    if (mBeQuiet) {
        mBeQuiet = !musicPlayer.isPlaying();
    }

    NotificationCompat.Builder builder = MediaStyleHelper.from(
            this,
            musicPlayer.getMediaSession(),
            NOTIFICATION_CHANNEL_ID
    );

    setupNotificationActions(builder);

    PendingIntent stopIntent = MediaButtonReceiver.buildMediaButtonPendingIntent(this,
            PlaybackStateCompat.ACTION_STOP);

    builder.setSmallIcon(getNotificationIcon())
            .setDeleteIntent(stopIntent)
            .setStyle(
                    new MediaStyle()
                            .setShowActionsInCompactView(0, 1, 2)
                            .setShowCancelButton(true)
                            .setCancelButtonIntent(stopIntent)
                            .setMediaSession(musicPlayer.getMediaSession().getSessionToken()));

    showNotification(builder.build(), foreground);
}
 
Example 3
Source File: PlayerService.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void addNotificationAction(NotificationCompat.Builder builder,
                                   @DrawableRes int icon, @StringRes int string,
                                   @MediaKeyAction long action) {

    PendingIntent intent = MediaButtonReceiver.buildMediaButtonPendingIntent(this, action);
    builder.addAction(new NotificationCompat.Action(icon, getString(string), intent));
}
 
Example 4
Source File: BaseWidget.java    From Jockey with Apache License 2.0 4 votes vote down vote up
protected PendingIntent getSkipNextIntent(Context context) {
    return MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_SKIP_TO_NEXT);
}
 
Example 5
Source File: BaseWidget.java    From Jockey with Apache License 2.0 4 votes vote down vote up
protected PendingIntent getSkipPreviousIntent(Context context) {
    return MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_SKIP_TO_PREVIOUS);
}
 
Example 6
Source File: BaseWidget.java    From Jockey with Apache License 2.0 4 votes vote down vote up
protected PendingIntent getPlayPauseIntent(Context context) {
    return MediaButtonReceiver.buildMediaButtonPendingIntent(context, ACTION_PLAY_PAUSE);
}
 
Example 7
Source File: TtsService.java    From android-app with GNU General Public License v3.0 4 votes vote down vote up
private PendingIntent generateActionIntent(long action) {
    return MediaButtonReceiver.buildMediaButtonPendingIntent(
            getApplicationContext(), mediaActionComponentName, action);
}