Merge changes from topics "session2_additem", "session2_playlistmetadata", "session2_getplaylist" into pi-dev

* changes:
  MediaSession2: Implement add/remove/replacePlaylistItem()
  MediaSession2: Implement update/getPlaylistMetadata()
  MediaSession2: Implement get/setPlaylist()
This commit is contained in:
Jaewan Kim
2018-03-13 04:30:50 +00:00
committed by Android (Google) Code Review
6 changed files with 95 additions and 51 deletions

View File

@@ -748,7 +748,14 @@ public class MediaController2 implements AutoCloseable {
} }
/** /**
* Return playlist from the session. * Returns the cached playlist from
* {@link ControllerCallback#onPlaylistChanged(MediaController2, MediaPlaylistAgent, List,
* MediaMetadata2)}.
* <p>
* This list may differ with the list that was specified with
* {@link #setPlaylist(List, MediaMetadata2)} depending on the {@link MediaPlaylistAgent}
* implementation. Use media items returned here for other playlist agent APIs such as
* {@link MediaPlaylistAgent#skipToPlaylistItem(MediaItem2)}.
* *
* @return playlist. Can be {@code null} if the controller doesn't have enough permission. * @return playlist. Can be {@code null} if the controller doesn't have enough permission.
*/ */
@@ -758,12 +765,19 @@ public class MediaController2 implements AutoCloseable {
/** /**
* Sets the playlist. * Sets the playlist.
* <p>
* Even when the playlist is successfully set, use the playlist returned from
* {@link #getPlaylist()} for playlist APIs such as {@link #skipToPlaylistItem(MediaItem2)}.
* Otherwise the session in the remote process can't distinguish between media items.
* *
* @param list playlist * @param list playlist
* @param metadata metadata of the playlist * @param metadata metadata of the playlist
* @see #getPlaylist()
* @see ControllerCallback#onPlaylistChanged(
* MediaController2, MediaPlaylistAgent, List, MediaMetadata2)
*/ */
public void setPlaylist(@NonNull List<MediaItem2> list, @Nullable MediaMetadata2 metadata) { public void setPlaylist(@NonNull List<MediaItem2> list, @Nullable MediaMetadata2 metadata) {
// TODO(jaewan): Implement (b/74174649) mProvider.setPlaylist_impl(list, metadata);
} }
/** /**
@@ -772,17 +786,20 @@ public class MediaController2 implements AutoCloseable {
* @param metadata metadata of the playlist * @param metadata metadata of the playlist
*/ */
public void updatePlaylistMetadata(@Nullable MediaMetadata2 metadata) { public void updatePlaylistMetadata(@Nullable MediaMetadata2 metadata) {
// TODO(jaewan): Implement (b/74174649) mProvider.updatePlaylistMetadata_impl(metadata);
} }
/** /**
* Returns the playlist metadata * Gets the lastly cached playlist playlist metadata either from
* {@link ControllerCallback#onPlaylistMetadataChanged(
* MediaController2, MediaPlaylistAgent, MediaMetadata2)} or
* {@link ControllerCallback#onPlaylistChanged(
* MediaController2, MediaPlaylistAgent, List, MediaMetadata2)}.
* *
* @return metadata metadata of the playlist, or null if none is set * @return metadata metadata of the playlist, or null if none is set
*/ */
public @Nullable MediaMetadata2 getPlaylistMetadata() { public @Nullable MediaMetadata2 getPlaylistMetadata() {
// TODO(jaewan): Implement (b/74174649) return mProvider.getPlaylistMetadata_impl();
return null;
} }
/** /**
@@ -797,15 +814,14 @@ public class MediaController2 implements AutoCloseable {
} }
/** /**
* Inserts the media item to the play list at position index. * Inserts the media item to the playlist at position index.
* <p> * <p>
* This will not change the currently playing media item. * This will not change the currently playing media item.
* If index is less than or equal to the current index of the play list, * If index is less than or equal to the current index of the playlist,
* the current index of the play list will be incremented correspondingly. * the current index of the playlist will be incremented correspondingly.
* *
* @param index the index you want to add * @param index the index you want to add
* @param item the media item you want to add * @param item the media item you want to add
* @throws IndexOutOfBoundsException if index is outside play list range
*/ */
public void addPlaylistItem(int index, @NonNull MediaItem2 item) { public void addPlaylistItem(int index, @NonNull MediaItem2 item) {
mProvider.addPlaylistItem_impl(index, item); mProvider.addPlaylistItem_impl(index, item);
@@ -816,6 +832,8 @@ public class MediaController2 implements AutoCloseable {
*<p> *<p>
* If the item is the currently playing item of the playlist, current playback * If the item is the currently playing item of the playlist, current playback
* will be stopped and playback moves to next source in the list. * will be stopped and playback moves to next source in the list.
*
* @param item the media item you want to add
*/ */
public void removePlaylistItem(@NonNull MediaItem2 item) { public void removePlaylistItem(@NonNull MediaItem2 item) {
mProvider.removePlaylistItem_impl(item); mProvider.removePlaylistItem_impl(item);

View File

@@ -64,6 +64,13 @@ public class MediaItem2 {
mProvider = provider; mProvider = provider;
} }
/**
* @hide
*/
public MediaItem2Provider getProvider() {
return mProvider;
}
/** /**
* Return this object as a bundle to share between processes. * Return this object as a bundle to share between processes.
* *
@@ -141,9 +148,7 @@ public class MediaItem2 {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
// TODO(jaewan): Override this. MediaItem2 may have auto-generated srcId when the DSD isn't return mProvider.equals_impl(obj);
// set, and it should be compared for the equals.
return super.equals(obj);
} }
/** /**

View File

@@ -61,7 +61,7 @@ import java.util.concurrent.Executor;
* sessions can be created to provide finer grain controls of media. * sessions can be created to provide finer grain controls of media.
* <p> * <p>
* If you want to support background playback, {@link MediaSessionService2} is preferred * If you want to support background playback, {@link MediaSessionService2} is preferred
* instead. With it, your playback can be revived even after you've finished playback. See * instead. With it, your playback can be revived even after playback is finished. See
* {@link MediaSessionService2} for details. * {@link MediaSessionService2} for details.
* <p> * <p>
* A session can be obtained by {@link Builder}. The owner of the session may pass its session token * A session can be obtained by {@link Builder}. The owner of the session may pass its session token
@@ -254,7 +254,7 @@ public class MediaSession2 implements AutoCloseable {
public static final int COMMAND_CODE_PLAYLIST_GET_LIST = 18; public static final int COMMAND_CODE_PLAYLIST_GET_LIST = 18;
/** /**
* Command code for {@link MediaController2#setPlaylist(List, MediaMetadata2). * Command code for {@link MediaController2#setPlaylist(List, MediaMetadata2)}.
* <p> * <p>
* Command would be sent directly to the playlist agent if the session doesn't reject the * Command would be sent directly to the playlist agent if the session doesn't reject the
* request through the * request through the
@@ -263,11 +263,8 @@ public class MediaSession2 implements AutoCloseable {
public static final int COMMAND_CODE_PLAYLIST_SET_LIST = 19; public static final int COMMAND_CODE_PLAYLIST_SET_LIST = 19;
/** /**
* Command code for {@link MediaController2#getPlaylistMetadata()} ()}. This will expose * Command code for {@link MediaController2#getPlaylistMetadata()}. This will expose
* metadata information to the controller. * metadata information to the controller.
* *
* Command code for {@link MediaController2#setPlaylist(List, MediaMetadata2)} and
* {@link MediaController2#updatePlaylistMetadata(MediaMetadata2)}.
* <p> * <p>
* Command would be sent directly to the playlist agent if the session doesn't reject the * Command would be sent directly to the playlist agent if the session doesn't reject the
* request through the * request through the
@@ -827,7 +824,11 @@ public class MediaSession2 implements AutoCloseable {
@NonNull MediaPlayerBase player, @NonNull MediaItem2 item, @BuffState int state) { } @NonNull MediaPlayerBase player, @NonNull MediaItem2 item, @BuffState int state) { }
/** /**
* Called when a playlist is changed. * Called when a playlist is changed from the {@link MediaPlaylistAgent}.
* <p>
* This is called when the underlying agent has called
* {@link MediaPlaylistAgent.PlaylistEventCallback#onPlaylistChanged(MediaPlaylistAgent,
* List, MediaMetadata2)}.
* *
* @param session the session for this event * @param session the session for this event
* @param playlistAgent playlist agent for this event * @param playlistAgent playlist agent for this event
@@ -1681,7 +1682,7 @@ public class MediaSession2 implements AutoCloseable {
* <p> * <p>
* If it's not set, playback wouldn't happen for the item without data source descriptor. * If it's not set, playback wouldn't happen for the item without data source descriptor.
* <p> * <p>
* The helper will be run on the executor that you've specified by the * The helper will be run on the executor that was specified by
* {@link Builder#setSessionCallback(Executor, SessionCallback)}. * {@link Builder#setSessionCallback(Executor, SessionCallback)}.
* *
* @param helper a data source missing helper. * @param helper a data source missing helper.
@@ -1705,40 +1706,46 @@ public class MediaSession2 implements AutoCloseable {
} }
/** /**
* Return the playlist which is lastly set. * Returns the playlist from the {@link MediaPlaylistAgent}.
* <p>
* This list may differ with the list that was specified with
* {@link #setPlaylist(List, MediaMetadata2)} depending on the {@link MediaPlaylistAgent}
* implementation. Use media items returned here for other playlist agent APIs such as
* {@link MediaPlaylistAgent#skipToPlaylistItem(MediaItem2)}.
* *
* @return playlist * @return playlist
* @see MediaPlaylistAgent#getPlaylist()
* @see SessionCallback#onPlaylistChanged(
* MediaSession2, MediaPlaylistAgent, List, MediaMetadata2)
*/ */
public List<MediaItem2> getPlaylist() { public List<MediaItem2> getPlaylist() {
return mProvider.getPlaylist_impl(); return mProvider.getPlaylist_impl();
} }
/** /**
* Set a list of {@link MediaItem2} as the current play list. * Sets a list of {@link MediaItem2} to the {@link MediaPlaylistAgent}. Ensure uniqueness of
* * each {@link MediaItem2} in the playlist so the session can uniquely identity individual
* @param playlist A list of {@link MediaItem2} objects to set as a play list. * items.
* @throws IllegalArgumentException if given {@param playlist} is null.
* @hide
*/
// TODO(jaewan): Remove
public void setPlaylist(@NonNull List<MediaItem2> playlist) {
mProvider.setPlaylist_impl(playlist);
}
/**
* Set a list of {@link MediaItem2} as the current play list. Ensure uniqueness in the
* {@link MediaItem2} in the playlist so session can uniquely identity individual items.
* <p> * <p>
* You may specify a {@link MediaItem2} without {@link DataSourceDesc}. However, in that case, * This may be an asynchronous call, and {@link MediaPlaylistAgent} may keep the copy of the
* you should set {@link OnDataSourceMissingHelper} for player to prepare. * list. Wait for {@link SessionCallback#onPlaylistChanged(MediaSession2, MediaPlaylistAgent,
* List, MediaMetadata2)} to know the operation finishes.
* <p>
* You may specify a {@link MediaItem2} without {@link DataSourceDesc}. In that case,
* {@link MediaPlaylistAgent} has responsibility to dynamically query {@link DataSourceDesc}
* when such media item is ready for preparation or play. Default implementation needs
* {@link OnDataSourceMissingHelper} for such case.
* *
* @param list A list of {@link MediaItem2} objects to set as a play list. * @param list A list of {@link MediaItem2} objects to set as a play list.
* @throws IllegalArgumentException if given list is {@code null}, or has duplicated media item. * @throws IllegalArgumentException if given list is {@code null}, or has duplicated media
* items.
* @see MediaPlaylistAgent#setPlaylist(List, MediaMetadata2)
* @see SessionCallback#onPlaylistChanged(
* MediaSession2, MediaPlaylistAgent, List, MediaMetadata2)
* @see #setOnDataSourceMissingHelper * @see #setOnDataSourceMissingHelper
*/ */
public void setPlaylist(@NonNull List<MediaItem2> list, @Nullable MediaMetadata2 metadata) { public void setPlaylist(@NonNull List<MediaItem2> list, @Nullable MediaMetadata2 metadata) {
// TODO(jaewan): Handle metadata here (b/74174649) mProvider.setPlaylist_impl(list, metadata);
// TODO(jaewan): Handle list change (b/74326040)
} }
/** /**
@@ -1760,13 +1767,17 @@ public class MediaSession2 implements AutoCloseable {
mProvider.skipToNextItem_impl(); mProvider.skipToNextItem_impl();
} }
/**
* Gets the playlist metadata from the {@link MediaPlaylistAgent}.
*
* @return the playlist metadata
*/
public MediaMetadata2 getPlaylistMetadata() { public MediaMetadata2 getPlaylistMetadata() {
// TODO(jaewan): Implement (b/74174649) return mProvider.getPlaylistMetadata_impl();
return null;
} }
/** /**
* Add the media item to the play list at position index. * Adds the media item to the playlist at position index.
* <p> * <p>
* This will not change the currently playing media item. * This will not change the currently playing media item.
* If index is less than or equal to the current index of the play list, * If index is less than or equal to the current index of the play list,
@@ -1774,26 +1785,25 @@ public class MediaSession2 implements AutoCloseable {
* *
* @param index the index you want to add * @param index the index you want to add
* @param item the media item you want to add * @param item the media item you want to add
* @throws IndexOutOfBoundsException if index is outside play list range
*/ */
public void addPlaylistItem(int index, @NonNull MediaItem2 item) { public void addPlaylistItem(int index, @NonNull MediaItem2 item) {
mProvider.addPlaylistItem_impl(index, item); mProvider.addPlaylistItem_impl(index, item);
} }
/** /**
* Remove the media item in the play list. * Removes the media item in the playlist.
* <p> * <p>
* If the item is the currently playing item of the playlist, current playback * If the item is the currently playing item of the playlist, current playback
* will be stopped and playback moves to next source in the list. * will be stopped and playback moves to next source in the list.
* *
* @throws IllegalArgumentException if the play list is null * @param item the media item you want to add
*/ */
public void removePlaylistItem(@NonNull MediaItem2 item) { public void removePlaylistItem(@NonNull MediaItem2 item) {
mProvider.removePlaylistItem_impl(item); mProvider.removePlaylistItem_impl(item);
} }
/** /**
* Replace the media item at index in the playlist. This can be also used to update metadata of * Replaces the media item at index in the playlist. This can be also used to update metadata of
* an item. * an item.
* *
* @param index the index of the item to replace * @param index the index of the item to replace
@@ -1813,8 +1823,13 @@ public class MediaSession2 implements AutoCloseable {
return mProvider.getCurrentPlaylistItem_impl(); return mProvider.getCurrentPlaylistItem_impl();
} }
/**
* Updates the playlist metadata to the {@link MediaPlaylistAgent}.
*
* @param metadata metadata of the playlist
*/
public void updatePlaylistMetadata(@Nullable MediaMetadata2 metadata) { public void updatePlaylistMetadata(@Nullable MediaMetadata2 metadata) {
// TODO(jaewan): Implement (b/74174649) mProvider.updatePlaylistMetadata_impl(metadata);
} }
public @RepeatMode int getRepeatMode() { public @RepeatMode int getRepeatMode() {

View File

@@ -21,6 +21,7 @@ import android.app.PendingIntent;
import android.media.AudioAttributes; import android.media.AudioAttributes;
import android.media.MediaController2.PlaybackInfo; import android.media.MediaController2.PlaybackInfo;
import android.media.MediaItem2; import android.media.MediaItem2;
import android.media.MediaMetadata2;
import android.media.MediaSession2.Command; import android.media.MediaSession2.Command;
import android.media.MediaSession2.PlaylistParams; import android.media.MediaSession2.PlaylistParams;
import android.media.PlaybackState2; import android.media.PlaybackState2;
@@ -58,6 +59,9 @@ public interface MediaController2Provider extends TransportControlProvider {
void setRating_impl(String mediaId, Rating2 rating); void setRating_impl(String mediaId, Rating2 rating);
void sendCustomCommand_impl(Command command, Bundle args, ResultReceiver cb); void sendCustomCommand_impl(Command command, Bundle args, ResultReceiver cb);
List<MediaItem2> getPlaylist_impl(); List<MediaItem2> getPlaylist_impl();
void setPlaylist_impl(List<MediaItem2> list, MediaMetadata2 metadata);
MediaMetadata2 getPlaylistMetadata_impl();
void updatePlaylistMetadata_impl(MediaMetadata2 metadata);
void addPlaylistItem_impl(int index, MediaItem2 item); void addPlaylistItem_impl(int index, MediaItem2 item);
void replacePlaylistItem_impl(int index, MediaItem2 item); void replacePlaylistItem_impl(int index, MediaItem2 item);

View File

@@ -35,6 +35,7 @@ public interface MediaItem2Provider {
MediaMetadata2 getMetadata_impl(); MediaMetadata2 getMetadata_impl();
String getMediaId_impl(); String getMediaId_impl();
DataSourceDesc getDataSourceDesc_impl(); DataSourceDesc getDataSourceDesc_impl();
boolean equals_impl(Object obj);
interface BuilderProvider { interface BuilderProvider {
Builder setMediaId_impl(String mediaId); Builder setMediaId_impl(String mediaId);

View File

@@ -47,6 +47,8 @@ public interface MediaSession2Provider extends TransportControlProvider {
void updatePlayer_impl(MediaPlayerBase player, MediaPlaylistAgent playlistAgent, void updatePlayer_impl(MediaPlayerBase player, MediaPlaylistAgent playlistAgent,
VolumeProvider2 volumeProvider); VolumeProvider2 volumeProvider);
MediaPlayerBase getPlayer_impl(); MediaPlayerBase getPlayer_impl();
MediaMetadata2 getPlaylistMetadata_impl();
void updatePlaylistMetadata_impl(MediaMetadata2 metadata);
MediaPlaylistAgent getPlaylistAgent_impl(); MediaPlaylistAgent getPlaylistAgent_impl();
VolumeProvider2 getVolumeProvider_impl(); VolumeProvider2 getVolumeProvider_impl();
SessionToken2 getToken_impl(); SessionToken2 getToken_impl();
@@ -57,12 +59,11 @@ public interface MediaSession2Provider extends TransportControlProvider {
void sendCustomCommand_impl(ControllerInfo controller, Command command, Bundle args, void sendCustomCommand_impl(ControllerInfo controller, Command command, Bundle args,
ResultReceiver receiver); ResultReceiver receiver);
void sendCustomCommand_impl(Command command, Bundle args); void sendCustomCommand_impl(Command command, Bundle args);
void setPlaylist_impl(List<MediaItem2> playlist);
void addPlaylistItem_impl(int index, MediaItem2 item); void addPlaylistItem_impl(int index, MediaItem2 item);
void removePlaylistItem_impl(MediaItem2 item); void removePlaylistItem_impl(MediaItem2 item);
void editPlaylistItem_impl(MediaItem2 item);
void replacePlaylistItem_impl(int index, MediaItem2 item); void replacePlaylistItem_impl(int index, MediaItem2 item);
List<MediaItem2> getPlaylist_impl(); List<MediaItem2> getPlaylist_impl();
void setPlaylist_impl(List<MediaItem2> list, MediaMetadata2 metadata);
MediaItem2 getCurrentPlaylistItem_impl(); MediaItem2 getCurrentPlaylistItem_impl();
void setPlaylistParams_impl(PlaylistParams params); void setPlaylistParams_impl(PlaylistParams params);
PlaylistParams getPlaylistParams_impl(); PlaylistParams getPlaylistParams_impl();