diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 47170725be..5ceebf14d9 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -46,6 +46,9 @@ * Add the media session as an argument of `getMediaButtons()` of the `DefaultMediaNotificationProvider` and use immutable lists for clarity ([#216](https://github.com/androidx/media/issues/216)). + * Add `onSetMediaItems` callback listener to provide means to modify/set + `MediaItem` list, starting index and position by session before setting + onto Player ([#156](https://github.com/androidx/media/issues/156)). * Metadata: * Parse multiple null-separated values from ID3 frames, as permitted by ID3 v2.4. diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaSession.java b/libraries/session/src/main/java/androidx/media3/session/MediaSession.java index 7f09c4280b..9037f9aae8 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaSession.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaSession.java @@ -58,6 +58,8 @@ import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.Util; import androidx.media3.session.MediaLibraryService.LibraryParams; import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; +import com.google.common.primitives.Longs; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import java.util.HashMap; @@ -1055,13 +1057,13 @@ public class MediaSession { /** * Called when a controller requested to add new {@linkplain MediaItem media items} to the - * playlist via one of the {@code Player.addMediaItem(s)} or {@code Player.setMediaItem(s)} - * methods. + * playlist via one of the {@code Player.addMediaItem(s)} methods. Unless overriden, {@link + * Callback#onSetMediaItems} will direct {@code Player.setMediaItem(s)} to this method as well. * - *

This callback is also called when an app is using a legacy {@link - * MediaControllerCompat.TransportControls} to prepare or play media (for instance when browsing - * the catalogue and then selecting an item for preparation from Android Auto that is using the - * legacy Media1 library). + *

In addition, unless {@link Callback#onSetMediaItems} is overridden, this callback is also + * called when an app is using a legacy {@link MediaControllerCompat.TransportControls} to + * prepare or play media (for instance when browsing the catalogue and then selecting an item + * for preparation from Android Auto that is using the legacy Media1 library). * *

Note that the requested {@linkplain MediaItem media items} don't have a {@link * MediaItem.LocalConfiguration} (for example, a URI) and need to be updated to make them @@ -1074,8 +1076,8 @@ public class MediaSession { * the {@link MediaItem media items} have been resolved, the session will call {@link * Player#setMediaItems} or {@link Player#addMediaItems} as requested. * - *

Interoperability: This method will be called in response to the following {@link - * MediaControllerCompat} methods: + *

Interoperability: This method will be called, unless {@link Callback#onSetMediaItems} is + * overridden, in response to the following {@link MediaControllerCompat} methods: * *