Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f10ca2f9 authored by Jaewan Kim's avatar Jaewan Kim
Browse files

MediaSession2: Implement PlaylistParams replacements

This includes following changes
  - Remove PlaylistParams
  - Implement PlaylistParams replacements. Here's the list.
    - get/setShuffleMode()
    - get/setRepeatMode()
    - Note: Playlist metadata APIs are already submitted (b/74174649)

Bug: 74116823, Bug: 74118768
Test: Run CTS with MediaComponents/runcts.sh
Change-Id: I0267ffeaf92257eb7b81ffc8b6a3f40b5a2f6f9c
parent ebc30594
Loading
Loading
Loading
Loading
+54 −56
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.media.MediaSession2.CommandButton;
import android.media.MediaSession2.CommandGroup;
import android.media.MediaSession2.ControllerInfo;
import android.media.MediaSession2.ErrorCode;
import android.media.MediaSession2.PlaylistParams;
import android.media.session.MediaSessionManager;
import android.media.update.ApiLoader;
import android.media.update.MediaController2Provider;
@@ -249,17 +248,6 @@ public class MediaController2 implements AutoCloseable {
        public void onRepeatModeChanged(@NonNull MediaController2 controller,
                @NonNull MediaPlaylistAgent playlistAgent,
                @MediaPlaylistAgent.RepeatMode int repeatMode) { }

        /**
         * Called when the playlist parameters are changed.
         *
         * @param controller the controller for this event
         * @param params The new play list parameters.
         * @hide
         */
        // TODO(jaewan): Remove (b/74116823)
        public void onPlaylistParamsChanged(@NonNull MediaController2 controller,
                @NonNull PlaylistParams params) { }
    }

    /**
@@ -460,19 +448,6 @@ public class MediaController2 implements AutoCloseable {
        mProvider.seekTo_impl(pos);
    }

    /**
     * Sets the {@link PlaylistParams} for the current play list. Repeat/shuffle mode and metadata
     * for the list can be set by calling this method.
     *
     * @param params A {@link PlaylistParams} object to set.
     * @throws IllegalArgumentException if given {@param param} is null.
     * @hide
     */
    // TODO(jaewan): Remove (b/74116823)
    public void setPlaylistParams(@NonNull PlaylistParams params) {
        mProvider.setPlaylistParams_impl(params);
    }

    /**
     * @hide
     */
@@ -760,17 +735,6 @@ public class MediaController2 implements AutoCloseable {
        return mProvider.getPlaylistMetadata_impl();
    }

    /**
     * Returns the {@link PlaylistParams} for the current play list.
     * Can return {@code null} if the controller doesn't have enough permission, or if the session
     * has not set the parameters.
     * @hide
     */
    // TODO(jaewan): Remove (b/74116823)
    public @Nullable PlaylistParams getPlaylistParams() {
        return mProvider.getPlaylistParams_impl();
    }

    /**
     * Inserts the media item to the playlist at position index.
     * <p>
@@ -818,17 +782,6 @@ public class MediaController2 implements AutoCloseable {
        return mProvider.getCurrentMediaItem_impl();
    }

    /**
     * Skips to the item in the playlist.
     * <p>
     * This calls {@link MediaPlaylistAgent#skipToPlaylistItem(MediaItem2)}.
     *
     * @param item The item in the playlist you want to play
     */
    public void skipToPlaylistItem(@NonNull MediaItem2 item) {
        mProvider.skipToPlaylistItem_impl(item);
    }

    /**
     * Skips to the previous item in the playlist.
     * <p>
@@ -847,21 +800,66 @@ public class MediaController2 implements AutoCloseable {
        mProvider.skipToNextItem_impl();
    }

    /**
     * Skips to the item in the playlist.
     * <p>
     * This calls {@link MediaPlaylistAgent#skipToPlaylistItem(MediaItem2)}.
     *
     * @param item The item in the playlist you want to play
     */
    public void skipToPlaylistItem(@NonNull MediaItem2 item) {
        mProvider.skipToPlaylistItem_impl(item);
    }

    /**
     * Gets the cached repeat mode from the {@link ControllerCallback#onRepeatModeChanged(
     * MediaController2, MediaPlaylistAgent, int)}.
     *
     * @return repeat mode
     * @see MediaPlaylistAgent#REPEAT_MODE_NONE
     * @see MediaPlaylistAgent#REPEAT_MODE_ONE
     * @see MediaPlaylistAgent#REPEAT_MODE_ALL
     * @see MediaPlaylistAgent#REPEAT_MODE_GROUP
     */
    public @RepeatMode int getRepeatMode() {
        // TODO(jaewan): Implement (b/74118768)
        return 0;
        return mProvider.getRepeatMode_impl();
    }

    /**
     * Sets the repeat mode.
     *
     * @param repeatMode repeat mode
     * @see MediaPlaylistAgent#REPEAT_MODE_NONE
     * @see MediaPlaylistAgent#REPEAT_MODE_ONE
     * @see MediaPlaylistAgent#REPEAT_MODE_ALL
     * @see MediaPlaylistAgent#REPEAT_MODE_GROUP
     */
    public void setRepeatMode(@RepeatMode int repeatMode) {
        // TODO(jaewan): Implement (b/74118768)
        mProvider.setRepeatMode_impl(repeatMode);
    }

    /**
     * Gets the cached shuffle mode from the {@link ControllerCallback#onShuffleModeChanged(
     * MediaController2, MediaPlaylistAgent, int)}.
     *
     * @return The shuffle mode
     * @see MediaPlaylistAgent#SHUFFLE_MODE_NONE
     * @see MediaPlaylistAgent#SHUFFLE_MODE_ALL
     * @see MediaPlaylistAgent#SHUFFLE_MODE_GROUP
     */
    public @ShuffleMode int getShuffleMode() {
        // TODO(jaewan): Implement (b/74118768)
        return 0;
        return mProvider.getShuffleMode_impl();
    }

    /**
     * Sets the shuffle mode.
     *
     * @param shuffleMode The shuffle mode
     * @see MediaPlaylistAgent#SHUFFLE_MODE_NONE
     * @see MediaPlaylistAgent#SHUFFLE_MODE_ALL
     * @see MediaPlaylistAgent#SHUFFLE_MODE_GROUP
     */
    public void setShuffleMode(@ShuffleMode int shuffleMode) {
        // TODO(jaewan): Implement (b/74118768)
        mProvider.setShuffleMode_impl(shuffleMode);
    }
}
+8 −8
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public abstract class MediaPlaylistAgent {
    @IntDef({REPEAT_MODE_NONE, REPEAT_MODE_ONE, REPEAT_MODE_ALL,
            REPEAT_MODE_GROUP})
    @Retention(RetentionPolicy.SOURCE)
    @interface RepeatMode {}
    public @interface RepeatMode {}

    /**
     * Playback will be stopped at the end of the playing media list.
@@ -75,7 +75,7 @@ public abstract class MediaPlaylistAgent {
     */
    @IntDef({SHUFFLE_MODE_NONE, SHUFFLE_MODE_ALL, SHUFFLE_MODE_GROUP})
    @Retention(RetentionPolicy.SOURCE)
    @interface ShuffleMode {}
    public @interface ShuffleMode {}

    /**
     * Media list will be played in order.
@@ -281,7 +281,7 @@ public abstract class MediaPlaylistAgent {
    }

    /**
     * Get repeat mode
     * Gets the repeat mode
     *
     * @return repeat mode
     * @see #REPEAT_MODE_NONE
@@ -294,7 +294,7 @@ public abstract class MediaPlaylistAgent {
    }

    /**
     * Set repeat mode
     * Sets the repeat mode
     *
     * @param repeatMode repeat mode
     * @see #REPEAT_MODE_NONE
@@ -307,9 +307,9 @@ public abstract class MediaPlaylistAgent {
    }

    /**
     * Get shuffle mode
     * Gets the shuffle mode
     *
     * @return shuffle mode
     * @return The shuffle mode
     * @see #SHUFFLE_MODE_NONE
     * @see #SHUFFLE_MODE_ALL
     * @see #SHUFFLE_MODE_GROUP
@@ -319,9 +319,9 @@ public abstract class MediaPlaylistAgent {
    }

    /**
     * Set shuffle mode
     * Sets the shuffle mode
     *
     * @param shuffleMode shuffle mode
     * @param shuffleMode The shuffle mode
     * @see #SHUFFLE_MODE_NONE
     * @see #SHUFFLE_MODE_ALL
     * @see #SHUFFLE_MODE_GROUP
+40 −160
Original line number Diff line number Diff line
@@ -28,8 +28,8 @@ import android.content.Intent;
import android.media.MediaPlayerBase.BuffState;
import android.media.MediaPlayerBase.PlayerEventCallback;
import android.media.MediaPlayerBase.PlayerState;
import android.media.MediaSession2.PlaylistParams.RepeatMode;
import android.media.MediaSession2.PlaylistParams.ShuffleMode;
import android.media.MediaPlaylistAgent.RepeatMode;
import android.media.MediaPlaylistAgent.ShuffleMode;
import android.media.update.ApiLoader;
import android.media.update.MediaSession2Provider;
import android.media.update.MediaSession2Provider.BuilderBaseProvider;
@@ -40,7 +40,6 @@ import android.media.update.MediaSession2Provider.ControllerInfoProvider;
import android.media.update.ProviderCreator;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IInterface;
import android.os.ResultReceiver;

@@ -1223,134 +1222,6 @@ public class MediaSession2 implements AutoCloseable {
        }
    }

    /**
     * Parameter for the playlist.
     * @hide
     */
    // TODO(jaewan): Remove (b/74116823)
    public final static class PlaylistParams {
        /**
         * @hide
         */
        @IntDef({REPEAT_MODE_NONE, REPEAT_MODE_ONE, REPEAT_MODE_ALL,
                REPEAT_MODE_GROUP})
        @Retention(RetentionPolicy.SOURCE)
        public @interface RepeatMode {}

        /**
         * Playback will be stopped at the end of the playing media list.
         */
        public static final int REPEAT_MODE_NONE = 0;

        /**
         * Playback of the current playing media item will be repeated.
         */
        public static final int REPEAT_MODE_ONE = 1;

        /**
         * Playing media list will be repeated.
         */
        public static final int REPEAT_MODE_ALL = 2;

        /**
         * Playback of the playing media group will be repeated.
         * A group is a logical block of media items which is specified in the section 5.7 of the
         * Bluetooth AVRCP 1.6.
         */
        public static final int REPEAT_MODE_GROUP = 3;

        /**
         * @hide
         */
        @IntDef({SHUFFLE_MODE_NONE, SHUFFLE_MODE_ALL, SHUFFLE_MODE_GROUP})
        @Retention(RetentionPolicy.SOURCE)
        public @interface ShuffleMode {}

        /**
         * Media list will be played in order.
         */
        public static final int SHUFFLE_MODE_NONE = 0;

        /**
         * Media list will be played in shuffled order.
         */
        public static final int SHUFFLE_MODE_ALL = 1;

        /**
         * Media group will be played in shuffled order.
         * A group is a logical block of media items which is specified in the section 5.7 of the
         * Bluetooth AVRCP 1.6.
         */
        public static final int SHUFFLE_MODE_GROUP = 2;


        private final MediaSession2Provider.PlaylistParamsProvider mProvider;

        /**
         * Instantiate {@link PlaylistParams}
         *
         * @param context context
         * @param repeatMode repeat mode
         * @param shuffleMode shuffle mode
         * @param playlistMetadata metadata for the list
         */
        public PlaylistParams(@NonNull Context context, @RepeatMode int repeatMode,
                @ShuffleMode int shuffleMode, @Nullable MediaMetadata2 playlistMetadata) {
            mProvider = ApiLoader.getProvider(context).createMediaSession2PlaylistParams(
                    context, this, repeatMode, shuffleMode, playlistMetadata);
        }

        /**
         * Create a new bundle for this object.
         *
         * @return
         */
        public @NonNull Bundle toBundle() {
            return mProvider.toBundle_impl();
        }

        /**
         * Create a new playlist params from the bundle that was previously returned by
         * {@link #toBundle}.
         *
         * @param context context
         * @return a new playlist params. Can be {@code null} for error.
         */
        public static @Nullable PlaylistParams fromBundle(
                @NonNull Context context, @Nullable Bundle bundle) {
            return ApiLoader.getProvider(context).fromBundle_PlaylistParams(context, bundle);
        }

        /**
         * Get repeat mode
         *
         * @return repeat mode
         * @see #REPEAT_MODE_NONE, #REPEAT_MODE_ONE, #REPEAT_MODE_ALL, #REPEAT_MODE_GROUP
         */
        public @RepeatMode int getRepeatMode() {
            return mProvider.getRepeatMode_impl();
        }

        /**
         * Get shuffle mode
         *
         * @return shuffle mode
         * @see #SHUFFLE_MODE_NONE, #SHUFFLE_MODE_ALL, #SHUFFLE_MODE_GROUP
         */
        public @ShuffleMode int getShuffleMode() {
            return mProvider.getShuffleMode_impl();
        }

        /**
         * Get metadata for the playlist
         *
         * @return metadata. Can be {@code null}
         */
        public @Nullable MediaMetadata2 getPlaylistMetadata() {
            return mProvider.getPlaylistMetadata_impl();
        }
    }

    /**
     * Constructor is hidden and apps can only instantiate indirectly through {@link Builder}.
     * <p>
@@ -1583,29 +1454,6 @@ public class MediaSession2 implements AutoCloseable {
        // To match with KEYCODE_MEDIA_SKIP_BACKWARD
    }

    /**
     * Sets the {@link PlaylistParams} for the current play list. Repeat/shuffle mode and metadata
     * for the list can be set by calling this method.
     *
     * @param params A {@link PlaylistParams} object to set.
     * @throws IllegalArgumentException if given {@param param} is null.
     * @hide
     */
    // TODO(jaewan): Remove (b/74116823)
    public void setPlaylistParams(PlaylistParams params) {
        mProvider.setPlaylistParams_impl(params);
    }

    /**
     * Returns the {@link PlaylistParams} for the current play list.
     * Returns {@code null} if not set.
     * @hide
     */
    // TODO(jaewan): Remove (b/74116823)
    public PlaylistParams getPlaylistParams() {
        return mProvider.getPlaylistParams_impl();
    }

    /**
     * Notify errors to the connected controllers
     *
@@ -1857,21 +1705,53 @@ public class MediaSession2 implements AutoCloseable {
        mProvider.updatePlaylistMetadata_impl(metadata);
    }

    /**
     * Gets the repeat mode from the {@link MediaPlaylistAgent}.
     *
     * @return repeat mode
     * @see MediaPlaylistAgent#REPEAT_MODE_NONE
     * @see MediaPlaylistAgent#REPEAT_MODE_ONE
     * @see MediaPlaylistAgent#REPEAT_MODE_ALL
     * @see MediaPlaylistAgent#REPEAT_MODE_GROUP
     */
    public @RepeatMode int getRepeatMode() {
        // TODO(jaewan): Implement (b/74118768)
        return 0;
        return mProvider.getRepeatMode_impl();
    }

    /**
     * Sets the repeat mode to the {@link MediaPlaylistAgent}.
     *
     * @param repeatMode repeat mode
     * @see MediaPlaylistAgent#REPEAT_MODE_NONE
     * @see MediaPlaylistAgent#REPEAT_MODE_ONE
     * @see MediaPlaylistAgent#REPEAT_MODE_ALL
     * @see MediaPlaylistAgent#REPEAT_MODE_GROUP
     */
    public void setRepeatMode(@RepeatMode int repeatMode) {
        // TODO(jaewan): Implement (b/74118768)
        mProvider.setRepeatMode_impl(repeatMode);
    }

    /**
     * Gets the shuffle mode from the {@link MediaPlaylistAgent}.
     *
     * @return The shuffle mode
     * @see MediaPlaylistAgent#SHUFFLE_MODE_NONE
     * @see MediaPlaylistAgent#SHUFFLE_MODE_ALL
     * @see MediaPlaylistAgent#SHUFFLE_MODE_GROUP
     */
    public @ShuffleMode int getShuffleMode() {
        // TODO(jaewan): Implement (b/74118768)
        return 0;
        return mProvider.getShuffleMode_impl();
    }

    /**
     * Sets the shuffle mode to the {@link MediaPlaylistAgent}.
     *
     * @param shuffleMode The shuffle mode
     * @see MediaPlaylistAgent#SHUFFLE_MODE_NONE
     * @see MediaPlaylistAgent#SHUFFLE_MODE_ALL
     * @see MediaPlaylistAgent#SHUFFLE_MODE_GROUP
     */
    public void setShuffleMode(@ShuffleMode int shuffleMode) {
        // TODO(jaewan): Implement (b/74118768)
        mProvider.setShuffleMode_impl(shuffleMode);
    }
}
+0 −3
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.media.MediaController2.PlaybackInfo;
import android.media.MediaItem2;
import android.media.MediaMetadata2;
import android.media.MediaSession2.Command;
import android.media.MediaSession2.PlaylistParams;
import android.media.Rating2;
import android.media.SessionToken2;
import android.net.Uri;
@@ -65,8 +64,6 @@ public interface MediaController2Provider extends TransportControlProvider {
    void replacePlaylistItem_impl(int index, MediaItem2 item);
    void removePlaylistItem_impl(MediaItem2 item);

    PlaylistParams getPlaylistParams_impl();
    void setPlaylistParams_impl(PlaylistParams params);
    int getPlayerState_impl();
    long getPosition_impl();
    float getPlaybackSpeed_impl();
+0 −10
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.media.MediaSession2.CommandButton;
import android.media.MediaSession2.CommandButton.Builder;
import android.media.MediaSession2.CommandGroup;
import android.media.MediaSession2.ControllerInfo;
import android.media.MediaSession2.PlaylistParams;
import android.media.MediaSession2.SessionCallback;
import android.media.SessionToken2;
import android.media.VolumeProvider2;
@@ -65,8 +64,6 @@ public interface MediaSession2Provider extends TransportControlProvider {
    List<MediaItem2> getPlaylist_impl();
    void setPlaylist_impl(List<MediaItem2> list, MediaMetadata2 metadata);
    MediaItem2 getCurrentPlaylistItem_impl();
    void setPlaylistParams_impl(PlaylistParams params);
    PlaylistParams getPlaylistParams_impl();
    void notifyError_impl(int errorCode, Bundle extras);

    interface CommandProvider {
@@ -115,13 +112,6 @@ public interface MediaSession2Provider extends TransportControlProvider {
        String toString_impl();
    }

    interface PlaylistParamsProvider {
        int getRepeatMode_impl();
        int getShuffleMode_impl();
        MediaMetadata2 getPlaylistMetadata_impl();
        Bundle toBundle_impl();
    }

    interface BuilderBaseProvider<T extends MediaSession2, C extends SessionCallback> {
        void setPlayer_impl(MediaPlayerBase player);
        void setPlaylistAgent_impl(MediaPlaylistAgent playlistAgent);
Loading