/** * Creates a notification manager and a low-priority notification channel with the specified * {@code channelId} and {@code channelName}. * * @param context The {@link Context}. * @param channelId The id of the notification channel. * @param channelName A string resource identifier for the user visible name of the channel. The * recommended maximum length is 40 characters; the value may be truncated if it is too long. * @param notificationId The id of the notification. * @param mediaDescriptionAdapter The {@link MediaDescriptionAdapter}. */ public static PlayerNotificationManager createWithNotificationChannel( Context context, String channelId, @StringRes int channelName, int notificationId, MediaDescriptionAdapter mediaDescriptionAdapter) { NotificationUtil.createNotificationChannel( context, channelId, channelName, NotificationUtil.IMPORTANCE_LOW); return new PlayerNotificationManager( context, channelId, notificationId, mediaDescriptionAdapter); }
R.drawable.exo_notification_play, context.getString(R.string.exo_controls_play_description), createBroadcastIntent(ACTION_PLAY, context, instanceId))); actions.put( ACTION_PAUSE, R.drawable.exo_notification_pause, context.getString(R.string.exo_controls_pause_description), createBroadcastIntent(ACTION_PAUSE, context, instanceId))); actions.put( ACTION_STOP, R.drawable.exo_notification_stop, context.getString(R.string.exo_controls_stop_description), createBroadcastIntent(ACTION_STOP, context, instanceId))); actions.put( ACTION_REWIND, R.drawable.exo_notification_rewind, context.getString(R.string.exo_controls_rewind_description), createBroadcastIntent(ACTION_REWIND, context, instanceId))); actions.put( ACTION_FAST_FORWARD, R.drawable.exo_notification_fastforward, context.getString(R.string.exo_controls_fastforward_description), createBroadcastIntent(ACTION_FAST_FORWARD, context, instanceId))); actions.put( ACTION_PREVIOUS,
@RequiresNonNull("player") private Notification updateNotification(@Nullable Bitmap bitmap) { Notification notification = createNotification(player, bitmap); notificationManager.notify(notificationId, notification); return notification; }
/** * As soon as somebody starts this service as background player, we create the * player notification. When created this notification will move the service to * foreground to avoid being destroyed by the system. */ private void handleStartInBackground() { isPlaybackInBackground = true; playerNotificationManager = new PlayerNotificationManager(this, NotificationHelper.BACKGROUND_PLAYBACK_CHANNEL_ID, NotificationHelper.BACKGROUND_PLAYBACK_NOTIFICATION_ID, this); playerNotificationManager.setOngoing(false); playerNotificationManager.setPlayer(player.getExoPlayer()); playerNotificationManager.setNotificationListener(this); playerNotificationManager.setSmallIcon(R.drawable.ic_zapp_tv); playerNotificationManager.setColor(getResources().getColor(R.color.colorPrimaryDark)); playerNotificationManager.setMediaSessionToken(player.getMediaSession().getSessionToken()); }
playerNotificationManager = PlayerNotificationManager.createWithNotificationChannel( context, PLAYBACK_CHANNEL_ID, R.string.playback_channel_name, PLAYBACK_NOTIFICATION_ID, playerNotificationManager.setSmallIcon(R.drawable.ic_peertube_bw); playerNotificationManager.setUseNavigationActions(false); playerNotificationManager.setNotificationListener( new PlayerNotificationManager.NotificationListener() { @Override playerNotificationManager.setPlayer(player); playerNotificationManager.setMediaSessionToken(mediaSession.getSessionToken()); MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession); mediaSessionConnector.setQueueNavigator(new TimelineQueueNavigator(mediaSession) {
@Override public void onDestroy() { Log.v(TAG, "onDestroy..."); if (playerNotificationManager != null) { playerNotificationManager.setPlayer(null); } if (player != null) { player.release(); player = null; } super.onDestroy(); }
List<String> actionNames = getActions(player); for (int i = 0; i < actionNames.size(); i++) { String actionName = actionNames.get(i); mediaStyle.setMediaSession(mediaSessionToken); mediaStyle.setShowActionsInCompactView(getActionIndicesForCompactView(actionNames, player));
playbackActions = createPlaybackActions(context, instanceId); for (String action : playbackActions.keySet()) { intentFilter.addAction(action);
/** * @see Binder#movePlaybackToForeground() */ private void movePlaybackToForeground() { isPlaybackInBackground = false; stopForeground(true); stopSelf(); if (playerNotificationManager != null) { playerNotificationManager.setPlayer(null); } }