@@ -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,46 @@ 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
+ *
243
+ * @link Player#stop} or an error, and the notification wasn't explicitly dismissed.
244
+ */
245
+ @ UnstableApi public static final int SHOW_NOTIFICATION_FOR_EMPTY_PLAYER_AFTER_STOP_OR_ERROR = 3 ;
246
+
211
247
private static final String TAG = "MSessionService" ;
212
248
213
249
private final Object lock ;
@@ -547,6 +583,18 @@ public final void setShowNotificationForIdlePlayer(
547
583
.setShowNotificationForIdlePlayer (showNotificationForIdlePlayerMode );
548
584
}
549
585
586
+ /**
587
+ * Sets whether and when a notification for a {@link Player} that has no media should be shown.
588
+ *
589
+ * @param showNotificationForEmptyPlayerMode The {@link ShowNotificationForEmptyPlayerMode}.
590
+ */
591
+ @ UnstableApi
592
+ public final void setShowNotificationForEmptyPlayer (
593
+ @ ShowNotificationForEmptyPlayerMode int showNotificationForEmptyPlayerMode ) {
594
+ getMediaNotificationManager ()
595
+ .setShowNotificationForEmptyPlayer (showNotificationForEmptyPlayerMode );
596
+ }
597
+
550
598
/**
551
599
* Returns whether there is a session with ongoing user-engaged playback that is run in a
552
600
* foreground service.
0 commit comments