mirror of
https://github.com/androidx/media.git
synced 2025-05-05 22:50:57 +08:00
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
This commit is contained in:
parent
6b8a1a365c
commit
ff9585f153
@ -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 {
|
|||||||
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 {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -699,6 +701,14 @@ public final class MediaSessionConnector {
|
|||||||
this.dispatchUnsupportedActionsEnabled = dispatchUnsupportedActionsEnabled;
|
this.dispatchUnsupportedActionsEnabled = dispatchUnsupportedActionsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
|||||||
@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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user