@@ -194,8 +194,8 @@ default void onForegroundServiceStartNotAllowedException() {}
194
194
public @interface ShowNotificationForIdlePlayerMode {}
195
195
196
196
/**
197
- * Always show a notification when the {@link Player} is in {@link Player#STATE_IDLE}, has media,
198
- * and the notification wasn't explicitly dismissed.
197
+ * Always show a notification when the {@link Player} is in {@link Player#STATE_IDLE} and the
198
+ * notification wasn't explicitly dismissed.
199
199
*/
200
200
@ UnstableApi public static final int SHOW_NOTIFICATION_FOR_IDLE_PLAYER_ALWAYS = 1 ;
201
201
@@ -204,10 +204,45 @@ default void onForegroundServiceStartNotAllowedException() {}
204
204
205
205
/**
206
206
* Shows a notification when the {@link Player} is in {@link Player#STATE_IDLE} due to {@link
207
- * Player#stop} or an error, has media, and the notification wasn't explicitly dismissed.
207
+ * Player#stop} or an error, and the notification wasn't explicitly dismissed.
208
208
*/
209
209
@ UnstableApi public static final int SHOW_NOTIFICATION_FOR_IDLE_PLAYER_AFTER_STOP_OR_ERROR = 3 ;
210
210
211
+ /**
212
+ * The behavior for showing notifications when the {@link Player} has no media.
213
+ *
214
+ * <p>One of {@link #SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_ALWAYS}, {@link
215
+ * #SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_NEVER}, {@link
216
+ * #SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_AFTER_STOP_OR_ERROR}.
217
+ *
218
+ * <p>The default value is {@link #SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_NEVER}.
219
+ */
220
+ @ UnstableApi
221
+ @ Documented
222
+ @ Retention (RetentionPolicy .SOURCE )
223
+ @ Target (TYPE_USE )
224
+ @ IntDef ({
225
+ SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_ALWAYS ,
226
+ SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_NEVER ,
227
+ SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_AFTER_STOP_OR_ERROR
228
+ })
229
+ public @interface ShowNotificationForEmptyPlayerMode {}
230
+
231
+ /**
232
+ * Always show a notification when the {@link Player} is empty and the notification wasn't
233
+ * explicitly dismissed.
234
+ */
235
+ @ UnstableApi public static final int SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_ALWAYS = 1 ;
236
+
237
+ /** Never show a notification when the {@link Player} is empty. */
238
+ @ UnstableApi public static final int SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_NEVER = 2 ;
239
+
240
+ /**
241
+ * Shows a notification when the {@link Player} is empty, in {@link Player#STATE_IDLE} due to
242
+ * {@link Player#stop} or an error, and the notification wasn't explicitly dismissed.
243
+ */
244
+ @ UnstableApi public static final int SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_AFTER_STOP_OR_ERROR = 3 ;
245
+
211
246
private static final String TAG = "MSessionService" ;
212
247
213
248
private final Object lock ;
@@ -547,6 +582,18 @@ public final void setShowNotificationForIdlePlayer(
547
582
.setShowNotificationForIdlePlayer (showNotificationForIdlePlayerMode );
548
583
}
549
584
585
+ /**
586
+ * Sets whether and when a notification for a {@link Player} that has no media should be shown.
587
+ *
588
+ * @param showNotificationForEmptyPlayerMode The {@link ShowNotificationForEmptyPlayerMode}.
589
+ */
590
+ @ UnstableApi
591
+ public final void setShowNotificationForEmptyPlayer (
592
+ @ ShowNotificationForEmptyPlayerMode int showNotificationForEmptyPlayerMode ) {
593
+ getMediaNotificationManager ()
594
+ .setShowNotificationForEmptyPlayer (showNotificationForEmptyPlayerMode );
595
+ }
596
+
550
597
/**
551
598
* Returns whether there is a session with ongoing user-engaged playback that is run in a
552
599
* foreground service.
0 commit comments