Commit ff9585f1 by bachinger Committed by kim-vde

Provide an opt-out from clearing media items on stop

After removing the deprecated call to player.stop(/* reset= */ true) and instead using two calls to the player, overridding stop in a ForwardingPlayer does not help to avoid clearing the player. To remove the deprecation we need an option so that users who want not to clear the player have a way to do so.

PiperOrigin-RevId: 411518090
parent 6b8a1a36
...@@ -14,6 +14,11 @@ ...@@ -14,6 +14,11 @@
* HLS: * HLS:
* Support key-frame accurate seeking in HLS * Support key-frame accurate seeking in HLS
([#2882](https://github.com/google/ExoPlayer/issues/2882)). ([#2882](https://github.com/google/ExoPlayer/issues/2882)).
* Correctly populate `Format.label` for audio only HLS streams
([#9608](https://github.com/google/ExoPlayer/issues/9608)).
* MediaSession extension
* Remove deprecated call to `onStop(/* reset= */ true)` and provide an
opt-out flag for apps that don't want to clear the playlist on stop.
### 2.16.1 (2021-11-18) ### 2.16.1 (2021-11-18)
......
...@@ -466,6 +466,7 @@ public final class MediaSessionConnector { ...@@ -466,6 +466,7 @@ public final class MediaSessionConnector {
private long enabledPlaybackActions; private long enabledPlaybackActions;
private boolean metadataDeduplicationEnabled; private boolean metadataDeduplicationEnabled;
private boolean dispatchUnsupportedActionsEnabled; private boolean dispatchUnsupportedActionsEnabled;
private boolean clearMediaItemsOnStop;
/** /**
* Creates an instance. * Creates an instance.
...@@ -486,6 +487,7 @@ public final class MediaSessionConnector { ...@@ -486,6 +487,7 @@ public final class MediaSessionConnector {
enabledPlaybackActions = DEFAULT_PLAYBACK_ACTIONS; enabledPlaybackActions = DEFAULT_PLAYBACK_ACTIONS;
mediaSession.setFlags(BASE_MEDIA_SESSION_FLAGS); mediaSession.setFlags(BASE_MEDIA_SESSION_FLAGS);
mediaSession.setCallback(componentListener, new Handler(looper)); mediaSession.setCallback(componentListener, new Handler(looper));
clearMediaItemsOnStop = true;
} }
/** /**
...@@ -700,6 +702,14 @@ public final class MediaSessionConnector { ...@@ -700,6 +702,14 @@ public final class MediaSessionConnector {
} }
/** /**
* Sets whether media items are cleared from the playlist when a client sends a {@link
* MediaControllerCompat.TransportControls#stop()} command.
*/
public void setClearMediaItemsOnStop(boolean clearMediaItemsOnStop) {
this.clearMediaItemsOnStop = clearMediaItemsOnStop;
}
/**
* Sets whether {@link MediaMetadataProvider#sameAs(MediaMetadataCompat, MediaMetadataCompat)} * Sets whether {@link MediaMetadataProvider#sameAs(MediaMetadataCompat, MediaMetadataCompat)}
* should be consulted before calling {@link MediaSessionCompat#setMetadata(MediaMetadataCompat)}. * should be consulted before calling {@link MediaSessionCompat#setMetadata(MediaMetadataCompat)}.
* *
...@@ -1208,7 +1218,10 @@ public final class MediaSessionConnector { ...@@ -1208,7 +1218,10 @@ public final class MediaSessionConnector {
@Override @Override
public void onStop() { public void onStop() {
if (canDispatchPlaybackAction(PlaybackStateCompat.ACTION_STOP)) { if (canDispatchPlaybackAction(PlaybackStateCompat.ACTION_STOP)) {
player.stop(/* reset= */ true); player.stop();
if (clearMediaItemsOnStop) {
player.clearMediaItems();
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment