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

Commit c7c1ce80 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "MediaSession2: Refine APIs"

parents 81b3bb99 aa080a80
Loading
Loading
Loading
Loading
+20 −13
Original line number Original line Diff line number Diff line
@@ -23378,6 +23378,7 @@ package android.media {
    method public void rewind();
    method public void rewind();
    method public void seekTo(long);
    method public void seekTo(long);
    method public void sendCustomCommand(android.media.MediaSession2.Command, android.os.Bundle, android.os.ResultReceiver);
    method public void sendCustomCommand(android.media.MediaSession2.Command, android.os.Bundle, android.os.ResultReceiver);
    method public void setPlaybackSpeed(float);
    method public void setPlaylistParams(android.media.MediaSession2.PlaylistParams);
    method public void setPlaylistParams(android.media.MediaSession2.PlaylistParams);
    method public void setRating(java.lang.String, android.media.Rating2);
    method public void setRating(java.lang.String, android.media.Rating2);
    method public void setVolumeTo(int, int);
    method public void setVolumeTo(int, int);
@@ -23396,13 +23397,13 @@ package android.media {
    method public void onCustomCommand(android.media.MediaSession2.Command, android.os.Bundle, android.os.ResultReceiver);
    method public void onCustomCommand(android.media.MediaSession2.Command, android.os.Bundle, android.os.ResultReceiver);
    method public void onCustomLayoutChanged(java.util.List<android.media.MediaSession2.CommandButton>);
    method public void onCustomLayoutChanged(java.util.List<android.media.MediaSession2.CommandButton>);
    method public void onDisconnected();
    method public void onDisconnected();
    method public void onError(int, int);
    method public void onError(int, android.os.Bundle);
    method public void onPlaybackInfoChanged(android.media.MediaController2.PlaybackInfo);
    method public void onPlaybackInfoChanged(android.media.MediaController2.PlaybackInfo);
    method public void onPlaybackSpeedChanged(float);
    method public void onPlaybackSpeedChanged(float);
    method public void onPlayerStateChanged(int);
    method public void onPlayerStateChanged(int);
    method public void onPlaylistChanged(java.util.List<android.media.MediaItem2>);
    method public void onPlaylistChanged(java.util.List<android.media.MediaItem2>);
    method public void onPlaylistParamsChanged(android.media.MediaSession2.PlaylistParams);
    method public void onPlaylistParamsChanged(android.media.MediaSession2.PlaylistParams);
    method public void onPositionUpdated(long, long);
    method public void onPositionChanged(long, long);
  }
  }
  public static final class MediaController2.PlaybackInfo {
  public static final class MediaController2.PlaybackInfo {
@@ -23854,9 +23855,11 @@ package android.media {
  }
  }
  public static final class MediaLibraryService2.MediaLibrarySession.Builder {
  public static final class MediaLibraryService2.MediaLibrarySession.Builder {
    ctor public MediaLibraryService2.MediaLibrarySession.Builder(android.media.MediaLibraryService2, android.media.MediaPlayerBase, java.util.concurrent.Executor, android.media.MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback);
    ctor public MediaLibraryService2.MediaLibrarySession.Builder(android.media.MediaLibraryService2, java.util.concurrent.Executor, android.media.MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback);
    method public android.media.MediaLibraryService2.MediaLibrarySession build();
    method public android.media.MediaLibraryService2.MediaLibrarySession build();
    method public android.media.MediaLibraryService2.MediaLibrarySession.Builder setId(java.lang.String);
    method public android.media.MediaLibraryService2.MediaLibrarySession.Builder setId(java.lang.String);
    method public android.media.MediaLibraryService2.MediaLibrarySession.Builder setPlayer(android.media.MediaPlayerBase);
    method public android.media.MediaLibraryService2.MediaLibrarySession.Builder setPlaylistController(android.media.MediaPlaylistController);
    method public android.media.MediaLibraryService2.MediaLibrarySession.Builder setSessionActivity(android.app.PendingIntent);
    method public android.media.MediaLibraryService2.MediaLibrarySession.Builder setSessionActivity(android.app.PendingIntent);
    method public android.media.MediaLibraryService2.MediaLibrarySession.Builder setSessionCallback(java.util.concurrent.Executor, android.media.MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback);
    method public android.media.MediaLibraryService2.MediaLibrarySession.Builder setSessionCallback(java.util.concurrent.Executor, android.media.MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback);
    method public android.media.MediaLibraryService2.MediaLibrarySession.Builder setVolumeProvider(android.media.VolumeProvider2);
    method public android.media.MediaLibraryService2.MediaLibrarySession.Builder setVolumeProvider(android.media.VolumeProvider2);
@@ -24806,15 +24809,17 @@ package android.media {
  public class MediaSession2 implements java.lang.AutoCloseable android.media.MediaPlaylistController {
  public class MediaSession2 implements java.lang.AutoCloseable android.media.MediaPlaylistController {
    method public void addPlaylistItem(int, android.media.MediaItem2);
    method public void addPlaylistItem(int, android.media.MediaItem2);
    method public void close();
    method public void close();
    method public void editPlaylistItem(android.media.MediaItem2);
    method public void fastForward();
    method public void fastForward();
    method public java.util.List<android.media.MediaSession2.ControllerInfo> getConnectedControllers();
    method public java.util.List<android.media.MediaSession2.ControllerInfo> getConnectedControllers();
    method public android.media.MediaItem2 getCurrentPlaylistItem();
    method public android.media.MediaItem2 getCurrentPlaylistItem();
    method public android.media.MediaPlaylistController getMediaPlaylistController();
    method public float getPlaybackSpeed();
    method public android.media.MediaPlayerBase getPlayer();
    method public android.media.MediaPlayerBase getPlayer();
    method public java.util.List<android.media.MediaItem2> getPlaylist();
    method public java.util.List<android.media.MediaItem2> getPlaylist();
    method public android.media.MediaSession2.PlaylistParams getPlaylistParams();
    method public android.media.MediaSession2.PlaylistParams getPlaylistParams();
    method public android.media.SessionToken2 getToken();
    method public android.media.SessionToken2 getToken();
    method public void notifyError(int, int);
    method public android.media.VolumeProvider2 getVolumeProvider();
    method public void notifyError(int, android.os.Bundle);
    method public void pause();
    method public void pause();
    method public void play();
    method public void play();
    method public void prepare();
    method public void prepare();
@@ -24826,14 +24831,14 @@ package android.media {
    method public void sendCustomCommand(android.media.MediaSession2.ControllerInfo, android.media.MediaSession2.Command, android.os.Bundle, android.os.ResultReceiver);
    method public void sendCustomCommand(android.media.MediaSession2.ControllerInfo, android.media.MediaSession2.Command, android.os.Bundle, android.os.ResultReceiver);
    method public void setAllowedCommands(android.media.MediaSession2.ControllerInfo, android.media.MediaSession2.CommandGroup);
    method public void setAllowedCommands(android.media.MediaSession2.ControllerInfo, android.media.MediaSession2.CommandGroup);
    method public void setCustomLayout(android.media.MediaSession2.ControllerInfo, java.util.List<android.media.MediaSession2.CommandButton>);
    method public void setCustomLayout(android.media.MediaSession2.ControllerInfo, java.util.List<android.media.MediaSession2.CommandButton>);
    method public void setPlayer(android.media.MediaPlayerBase);
    method public void setPlaybackSpeed(float);
    method public void setPlayer(android.media.MediaPlayerBase, android.media.VolumeProvider2);
    method public void setPlaylist(java.util.List<android.media.MediaItem2>);
    method public void setPlaylist(java.util.List<android.media.MediaItem2>);
    method public void setPlaylistParams(android.media.MediaSession2.PlaylistParams);
    method public void setPlaylistParams(android.media.MediaSession2.PlaylistParams);
    method public void skipToNext();
    method public void skipToNext();
    method public void skipToPlaylistItem(android.media.MediaItem2);
    method public void skipToPlaylistItem(android.media.MediaItem2);
    method public void skipToPrevious();
    method public void skipToPrevious();
    method public void stop();
    method public void stop();
    method public void updatePlayer(android.media.MediaPlayerBase, android.media.MediaPlaylistController, android.media.VolumeProvider2);
    field public static final int COMMAND_CODE_BROWSER = 22; // 0x16
    field public static final int COMMAND_CODE_BROWSER = 22; // 0x16
    field public static final int COMMAND_CODE_CUSTOM = 0; // 0x0
    field public static final int COMMAND_CODE_CUSTOM = 0; // 0x0
    field public static final int COMMAND_CODE_PLAYBACK_FAST_FORWARD = 7; // 0x7
    field public static final int COMMAND_CODE_PLAYBACK_FAST_FORWARD = 7; // 0x7
@@ -24842,10 +24847,10 @@ package android.media {
    field public static final int COMMAND_CODE_PLAYBACK_PREPARE = 6; // 0x6
    field public static final int COMMAND_CODE_PLAYBACK_PREPARE = 6; // 0x6
    field public static final int COMMAND_CODE_PLAYBACK_REWIND = 8; // 0x8
    field public static final int COMMAND_CODE_PLAYBACK_REWIND = 8; // 0x8
    field public static final int COMMAND_CODE_PLAYBACK_SEEK_TO = 9; // 0x9
    field public static final int COMMAND_CODE_PLAYBACK_SEEK_TO = 9; // 0x9
    field public static final int COMMAND_CODE_PLAYBACK_SET_CURRENT_PLAYLIST_ITEM = 10; // 0xa
    field public static final int COMMAND_CODE_PLAYBACK_SET_PLAYLIST_PARAMS = 11; // 0xb
    field public static final int COMMAND_CODE_PLAYBACK_SET_PLAYLIST_PARAMS = 11; // 0xb
    field public static final int COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM = 4; // 0x4
    field public static final int COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM = 4; // 0x4
    field public static final int COMMAND_CODE_PLAYBACK_SKIP_PREV_ITEM = 5; // 0x5
    field public static final int COMMAND_CODE_PLAYBACK_SKIP_PREV_ITEM = 5; // 0x5
    field public static final int COMMAND_CODE_PLAYBACK_SKIP_TO_PLAYLIST_ITEM = 10; // 0xa
    field public static final int COMMAND_CODE_PLAYBACK_STOP = 3; // 0x3
    field public static final int COMMAND_CODE_PLAYBACK_STOP = 3; // 0x3
    field public static final int COMMAND_CODE_PLAYLIST_ADD = 12; // 0xc
    field public static final int COMMAND_CODE_PLAYLIST_ADD = 12; // 0xc
    field public static final int COMMAND_CODE_PLAYLIST_GET = 14; // 0xe
    field public static final int COMMAND_CODE_PLAYLIST_GET = 14; // 0xe
@@ -24873,10 +24878,11 @@ package android.media {
  }
  }
  public static final class MediaSession2.Builder {
  public static final class MediaSession2.Builder {
    ctor public MediaSession2.Builder(android.content.Context, android.media.MediaPlayerBase);
    ctor public MediaSession2.Builder(android.content.Context);
    ctor public MediaSession2.Builder(android.content.Context, android.media.MediaPlayerBase, android.media.MediaPlaylistController);
    method public android.media.MediaSession2 build();
    method public android.media.MediaSession2 build();
    method public android.media.MediaSession2.Builder setId(java.lang.String);
    method public android.media.MediaSession2.Builder setId(java.lang.String);
    method public android.media.MediaSession2.Builder setPlayer(android.media.MediaPlayerBase);
    method public android.media.MediaSession2.Builder setPlaylistController(android.media.MediaPlaylistController);
    method public android.media.MediaSession2.Builder setSessionActivity(android.app.PendingIntent);
    method public android.media.MediaSession2.Builder setSessionActivity(android.app.PendingIntent);
    method public android.media.MediaSession2.Builder setSessionCallback(java.util.concurrent.Executor, android.media.MediaSession2.SessionCallback);
    method public android.media.MediaSession2.Builder setSessionCallback(java.util.concurrent.Executor, android.media.MediaSession2.SessionCallback);
    method public android.media.MediaSession2.Builder setVolumeProvider(android.media.VolumeProvider2);
    method public android.media.MediaSession2.Builder setVolumeProvider(android.media.VolumeProvider2);
@@ -24887,13 +24893,13 @@ package android.media {
    ctor public MediaSession2.Command(android.content.Context, java.lang.String, android.os.Bundle);
    ctor public MediaSession2.Command(android.content.Context, java.lang.String, android.os.Bundle);
    method public int getCommandCode();
    method public int getCommandCode();
    method public java.lang.String getCustomCommand();
    method public java.lang.String getCustomCommand();
    method public android.os.Bundle getExtra();
    method public android.os.Bundle getExtras();
  }
  }
  public static final class MediaSession2.CommandButton {
  public static final class MediaSession2.CommandButton {
    method public android.media.MediaSession2.Command getCommand();
    method public android.media.MediaSession2.Command getCommand();
    method public java.lang.String getDisplayName();
    method public java.lang.String getDisplayName();
    method public android.os.Bundle getExtra();
    method public android.os.Bundle getExtras();
    method public int getIconResId();
    method public int getIconResId();
    method public boolean isEnabled();
    method public boolean isEnabled();
  }
  }
@@ -24904,7 +24910,7 @@ package android.media {
    method public android.media.MediaSession2.CommandButton.Builder setCommand(android.media.MediaSession2.Command);
    method public android.media.MediaSession2.CommandButton.Builder setCommand(android.media.MediaSession2.Command);
    method public android.media.MediaSession2.CommandButton.Builder setDisplayName(java.lang.String);
    method public android.media.MediaSession2.CommandButton.Builder setDisplayName(java.lang.String);
    method public android.media.MediaSession2.CommandButton.Builder setEnabled(boolean);
    method public android.media.MediaSession2.CommandButton.Builder setEnabled(boolean);
    method public android.media.MediaSession2.CommandButton.Builder setExtra(android.os.Bundle);
    method public android.media.MediaSession2.CommandButton.Builder setExtras(android.os.Bundle);
    method public android.media.MediaSession2.CommandButton.Builder setIconResId(int);
    method public android.media.MediaSession2.CommandButton.Builder setIconResId(int);
  }
  }
@@ -24913,6 +24919,7 @@ package android.media {
    ctor public MediaSession2.CommandGroup(android.content.Context, android.media.MediaSession2.CommandGroup);
    ctor public MediaSession2.CommandGroup(android.content.Context, android.media.MediaSession2.CommandGroup);
    method public void addAllPredefinedCommands();
    method public void addAllPredefinedCommands();
    method public void addCommand(android.media.MediaSession2.Command);
    method public void addCommand(android.media.MediaSession2.Command);
    method public java.util.List<android.media.MediaSession2.Command> getCommands();
    method public boolean hasCommand(android.media.MediaSession2.Command);
    method public boolean hasCommand(android.media.MediaSession2.Command);
    method public boolean hasCommand(int);
    method public boolean hasCommand(int);
    method public void removeCommand(android.media.MediaSession2.Command);
    method public void removeCommand(android.media.MediaSession2.Command);
+12 −5
Original line number Original line Diff line number Diff line
@@ -156,7 +156,7 @@ public class MediaController2 implements AutoCloseable, MediaPlaylistController
         * @param updateTimeMs timestamp when the position information is sent from the session
         * @param updateTimeMs timestamp when the position information is sent from the session
         * @param positionMs position in millis
         * @param positionMs position in millis
         */
         */
        public void onPositionUpdated(long updateTimeMs, long positionMs) { }
        public void onPositionChanged(long updateTimeMs, long positionMs) { }


        /**
        /**
         * Called when playback speed is changed.
         * Called when playback speed is changed.
@@ -176,9 +176,9 @@ public class MediaController2 implements AutoCloseable, MediaPlaylistController
         * Called when a error from
         * Called when a error from
         *
         *
         * @param errorCode error code
         * @param errorCode error code
         * @param extra extra information
         * @param extras extra information
         */
         */
        public void onError(@ErrorCode int errorCode, int extra) { }
        public void onError(@ErrorCode int errorCode, @Nullable Bundle extras) { }


        /**
        /**
         * Called when the player's current playing item is changed
         * Called when the player's current playing item is changed
@@ -599,7 +599,7 @@ public class MediaController2 implements AutoCloseable, MediaPlaylistController
    }
    }


    /**
    /**
     * Get the lastly cached position from {@link ControllerCallback#onPositionUpdated(long, long)}.
     * Get the lastly cached position from {@link ControllerCallback#onPositionChanged(long, long)}.
     * <p>
     * <p>
     * This returns the calculated value of the position, based on the difference between the
     * This returns the calculated value of the position, based on the difference between the
     * update time and current time.
     * update time and current time.
@@ -620,6 +620,13 @@ public class MediaController2 implements AutoCloseable, MediaPlaylistController
        return mProvider.getPlaybackSpeed_impl();
        return mProvider.getPlaybackSpeed_impl();
    }
    }


    /**
     * Set the playback speed.
     */
    public void setPlaybackSpeed(float speed) {
        // TODO: implement this
    }

    /**
    /**
     * Get the lastly cached buffered position from
     * Get the lastly cached buffered position from
     * {@link ControllerCallback#onBufferedPositionChanged(long)}.
     * {@link ControllerCallback#onBufferedPositionChanged(long)}.
@@ -700,7 +707,7 @@ public class MediaController2 implements AutoCloseable, MediaPlaylistController
    /**
    /**
     * Removes the media item at index in the playlist.
     * Removes the media item at index in the playlist.
     *<p>
     *<p>
     * If index is same as the current index 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.
     */
     */
    @Override
    @Override
+12 −3
Original line number Original line Diff line number Diff line
@@ -198,16 +198,25 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
            // Ideally it's better to make it inner class of service to enforce, it violates API
            // Ideally it's better to make it inner class of service to enforce, it violates API
            // guideline that Builders should be the inner class of the building target.
            // guideline that Builders should be the inner class of the building target.
            public Builder(@NonNull MediaLibraryService2 service,
            public Builder(@NonNull MediaLibraryService2 service,
                    @NonNull MediaPlayerBase player,
                    @NonNull @CallbackExecutor Executor callbackExecutor,
                    @NonNull @CallbackExecutor Executor callbackExecutor,
                    @NonNull MediaLibrarySessionCallback callback) {
                    @NonNull MediaLibrarySessionCallback callback) {
                super((instance) -> ApiLoader.getProvider(service)
                super((instance) -> ApiLoader.getProvider(service)
                        .createMediaLibraryService2Builder(service, (Builder) instance, player,
                        .createMediaLibraryService2Builder(service, (Builder) instance,
                                callbackExecutor, callback));
                                callbackExecutor, callback));
            }
            }


            @Override
            @Override
            public Builder setVolumeProvider(@Nullable VolumeProvider2 volumeProvider) {
            public Builder setPlayer(@NonNull MediaPlayerBase player) {
                return super.setPlayer(player);
            }

            @Override
            public Builder setPlaylistController(@NonNull MediaPlaylistController mplc) {
                return super.setPlaylistController(mplc);
            }

            @Override
            public Builder setVolumeProvider(@NonNull VolumeProvider2 volumeProvider) {
                return super.setVolumeProvider(volumeProvider);
                return super.setVolumeProvider(volumeProvider);
            }
            }


+0 −2
Original line number Original line Diff line number Diff line
@@ -16,11 +16,9 @@


package android.media;
package android.media;


import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.media.MediaSession2.PlaylistParams;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
+116 −67
Original line number Original line Diff line number Diff line
@@ -24,6 +24,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.media.MediaPlayerBase.PlayerEventCallback;
import android.media.MediaPlayerBase.PlayerEventCallback;
import android.media.MediaPlaylistController;
import android.media.session.MediaSession;
import android.media.session.MediaSession;
import android.media.session.MediaSession.Callback;
import android.media.session.MediaSession.Callback;
import android.media.session.PlaybackState;
import android.media.session.PlaybackState;
@@ -69,7 +70,7 @@ import java.util.concurrent.Executor;
 * <p>
 * <p>
 * When a session receive transport control commands, the session sends the commands directly to
 * When a session receive transport control commands, the session sends the commands directly to
 * the the underlying media player set by {@link Builder} or
 * the the underlying media player set by {@link Builder} or
 * {@link #setPlayer(MediaPlayerBase)}.
 * {@link #updatePlayer}.
 * <p>
 * <p>
 * When an app is finished performing playback it must call {@link #close()} to clean up the session
 * When an app is finished performing playback it must call {@link #close()} to clean up the session
 * and notify any controllers.
 * and notify any controllers.
@@ -117,7 +118,7 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
    public static final int COMMAND_CODE_PLAYBACK_STOP = 3;
    public static final int COMMAND_CODE_PLAYBACK_STOP = 3;


    /**
    /**
     * Command code for {@link MediaController2#skipToNext()} ()}.
     * Command code for {@link MediaController2#skipToNext()}.
     * <p>
     * <p>
     * Command would be sent directly to the player if the session doesn't reject the request
     * Command would be sent directly to the player if the session doesn't reject the request
     * through the {@link SessionCallback#onCommandRequest(ControllerInfo, Command)}.
     * through the {@link SessionCallback#onCommandRequest(ControllerInfo, Command)}.
@@ -125,7 +126,7 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
    public static final int COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM = 4;
    public static final int COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM = 4;


    /**
    /**
     * Command code for {@link MediaController2#skipToPrevious()} ()}.
     * Command code for {@link MediaController2#skipToPrevious()}.
     * <p>
     * <p>
     * Command would be sent directly to the player if the session doesn't reject the request
     * Command would be sent directly to the player if the session doesn't reject the request
     * through the {@link SessionCallback#onCommandRequest(ControllerInfo, Command)}.
     * through the {@link SessionCallback#onCommandRequest(ControllerInfo, Command)}.
@@ -170,10 +171,10 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
     * Command would be sent directly to the player if the session doesn't reject the request
     * Command would be sent directly to the player if the session doesn't reject the request
     * through the {@link SessionCallback#onCommandRequest(ControllerInfo, Command)}.
     * through the {@link SessionCallback#onCommandRequest(ControllerInfo, Command)}.
     */
     */
    public static final int COMMAND_CODE_PLAYBACK_SET_CURRENT_PLAYLIST_ITEM = 10;
    public static final int COMMAND_CODE_PLAYBACK_SKIP_TO_PLAYLIST_ITEM = 10;


    /**
    /**
     * Command code for {@link MediaController2#setPlaylistParams(PlaylistParams)} ()}.
     * Command code for {@link MediaController2#setPlaylistParams(PlaylistParams)}.
     * <p>
     * <p>
     * Command would be sent directly to the player if the session doesn't reject the request
     * Command would be sent directly to the player if the session doesn't reject the request
     * through the {@link SessionCallback#onCommandRequest(ControllerInfo, Command)}.
     * through the {@link SessionCallback#onCommandRequest(ControllerInfo, Command)}.
@@ -347,12 +348,12 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
                    .createMediaSession2Command(this, commandCode, null, null);
                    .createMediaSession2Command(this, commandCode, null, null);
        }
        }


        public Command(@NonNull Context context, @NonNull String action, @Nullable Bundle extra) {
        public Command(@NonNull Context context, @NonNull String action, @Nullable Bundle extras) {
            if (action == null) {
            if (action == null) {
                throw new IllegalArgumentException("action shouldn't be null");
                throw new IllegalArgumentException("action shouldn't be null");
            }
            }
            mProvider = ApiLoader.getProvider(context)
            mProvider = ApiLoader.getProvider(context)
                    .createMediaSession2Command(this, COMMAND_CODE_CUSTOM, action, extra);
                    .createMediaSession2Command(this, COMMAND_CODE_CUSTOM, action, extras);
        }
        }


        public int getCommandCode() {
        public int getCommandCode() {
@@ -363,8 +364,8 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
            return mProvider.getCustomCommand_impl();
            return mProvider.getCustomCommand_impl();
        }
        }


        public @Nullable Bundle getExtra() {
        public @Nullable Bundle getExtras() {
            return mProvider.getExtra_impl();
            return mProvider.getExtras_impl();
        }
        }


        /**
        /**
@@ -433,6 +434,11 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
            return mProvider.hasCommand_impl(code);
            return mProvider.hasCommand_impl(code);
        }
        }


        public List<Command> getCommands() {
            // TODO: implement this
            return null;
        }

        /**
        /**
         * @hide
         * @hide
         */
         */
@@ -512,7 +518,7 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
         * @see #COMMAND_CODE_PLAYBACK_FAST_FORWARD
         * @see #COMMAND_CODE_PLAYBACK_FAST_FORWARD
         * @see #COMMAND_CODE_PLAYBACK_REWIND
         * @see #COMMAND_CODE_PLAYBACK_REWIND
         * @see #COMMAND_CODE_PLAYBACK_SEEK_TO
         * @see #COMMAND_CODE_PLAYBACK_SEEK_TO
         * @see #COMMAND_CODE_PLAYBACK_SET_CURRENT_PLAYLIST_ITEM
         * @see #COMMAND_CODE_PLAYBACK_SKIP_TO_PLAYLIST_ITEM
         * @see #COMMAND_CODE_PLAYBACK_SET_PLAYLIST_PARAMS
         * @see #COMMAND_CODE_PLAYBACK_SET_PLAYLIST_PARAMS
         * @see #COMMAND_CODE_PLAYLIST_ADD
         * @see #COMMAND_CODE_PLAYLIST_ADD
         * @see #COMMAND_CODE_PLAYLIST_REMOVE
         * @see #COMMAND_CODE_PLAYLIST_REMOVE
@@ -685,16 +691,38 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
        }
        }


        /**
        /**
         * Set volume provider to configure this session to use remote volume handling.
         * Set the underlying {@link MediaPlayerBase} for this session to dispatch incoming event
         * This must be called to receive volume button events, otherwise the system
         * to.
         * will adjust the appropriate stream volume for this session's player.
         * <p>
         * <p>
         * Set {@code null} to reset.
         *
         *
         * @param volumeProvider The provider that will handle volume changes. Can be {@code null}.
         * @param player a {@link MediaPlayerBase} that handles actual media playback in your app.
         */
        U setPlayer(@NonNull MediaPlayerBase player) {
            // TODO: Change the provider properly
            mProvider.setPlayer_impl(player, null, null);
            return (U) this;
        }

        /**
         * Set the {@link MediaPlaylistController} for this session to manages playlist of the
         * underlying {@link MediaPlayerBase player}.
         *
         * @param mplc a {@link MediaPlaylistController} that manages playlist of the
         * {@code player.}
         */
        U setPlaylistController(@NonNull MediaPlaylistController mplc) {
            // TODO: implement this
            return (U) this;
        }

        /**
         * Set the {@link VolumeProvider2} for this session to receive volume button events. If not
         * set, system will adjust the appropriate stream volume for this session's player.
         *
         * @param volumeProvider The provider that will receive volume button events.
         */
         */
        U setVolumeProvider(@Nullable VolumeProvider2 volumeProvider) {
        U setVolumeProvider(@NonNull VolumeProvider2 volumeProvider) {
            mProvider.setVolumeProvider_impl(volumeProvider);
            // TODO: implement this
            return (U) this;
            return (U) this;
        }
        }


@@ -759,23 +787,32 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
    // Override all methods just to show them with the type instead of generics in Javadoc.
    // Override all methods just to show them with the type instead of generics in Javadoc.
    // This workarounds javadoc issue described in the MediaSession2.BuilderBase.
    // This workarounds javadoc issue described in the MediaSession2.BuilderBase.
    public static final class Builder extends BuilderBase<MediaSession2, Builder, SessionCallback> {
    public static final class Builder extends BuilderBase<MediaSession2, Builder, SessionCallback> {
        public Builder(Context context, @NonNull MediaPlayerBase player) {
        public Builder(Context context) {
            super((instance) -> ApiLoader.getProvider(context).createMediaSession2Builder(
            super((instance) -> ApiLoader.getProvider(context).createMediaSession2Builder(
                    context, (Builder) instance, player));
                    context, (Builder) instance));
        }
        }


        public Builder(Context context, @NonNull MediaPlayerBase player,
        @Override
                @NonNull MediaPlaylistController mplc) {
        public Builder setPlayer(@NonNull MediaPlayerBase player) {
            //TODO use the MediaPlaylistController
            if (player == null) {
            super((instance) -> ApiLoader.getProvider(context).createMediaSession2Builder(
                throw new IllegalArgumentException("Illegal null MediaPlayerBase");
                    context, (Builder) instance, player));
            }
            return super.setPlayer(player);
        }

        @Override
        public Builder setPlaylistController(@NonNull MediaPlaylistController mplc) {
            if (mplc == null) {
            if (mplc == null) {
                throw new IllegalArgumentException("Illegal null PlaylistController");
                throw new IllegalArgumentException("Illegal null MediaPlaylistController");
            }
            }
            return super.setPlaylistController(mplc);
        }
        }


        @Override
        @Override
        public Builder setVolumeProvider(@Nullable VolumeProvider2 volumeProvider) {
        public Builder setVolumeProvider(@NonNull VolumeProvider2 volumeProvider) {
            if (volumeProvider == null) {
                throw new IllegalArgumentException("Illegal null VolumeProvider2");
            }
            return super.setVolumeProvider(volumeProvider);
            return super.setVolumeProvider(volumeProvider);
        }
        }


@@ -922,8 +959,8 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
         *
         *
         * @return
         * @return
         */
         */
        public @Nullable Bundle getExtra() {
        public @Nullable Bundle getExtras() {
            return mProvider.getExtra_impl();
            return mProvider.getExtras_impl();
        }
        }


        /**
        /**
@@ -969,8 +1006,8 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
                return mProvider.setEnabled_impl(enabled);
                return mProvider.setEnabled_impl(enabled);
            }
            }


            public Builder setExtra(Bundle extra) {
            public Builder setExtras(Bundle extras) {
                return mProvider.setExtra_impl(extra);
                return mProvider.setExtras_impl(extras);
            }
            }


            public CommandButton build() {
            public CommandButton build() {
@@ -1135,28 +1172,17 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
     * Set the underlying {@link MediaPlayerBase} for this session to dispatch incoming event
     * Set the underlying {@link MediaPlayerBase} for this session to dispatch incoming event
     * to. Events from the {@link MediaController2} will be sent directly to the underlying
     * to. Events from the {@link MediaController2} will be sent directly to the underlying
     * player on the {@link Handler} where the session is created on.
     * player on the {@link Handler} where the session is created on.
     * <p>
     * For the remote playback case which you want to handle volume by yourself, use
     * {@link #setPlayer(MediaPlayerBase, VolumeProvider2)}.
     *
     * @param player a {@link MediaPlayerBase} that handles actual media playback in your app.
     * @throws IllegalArgumentException if the player is {@code null}.
     */
    public void setPlayer(@NonNull MediaPlayerBase player) {
        mProvider.setPlayer_impl(player);
    }

    /**
     * Set the underlying {@link MediaPlayerBase} with the volume provider for remote playback.
     *
     *
     * @param player a {@link MediaPlayerBase} that handles actual media playback in your app.
     * @param player a {@link MediaPlayerBase} that handles actual media playback in your app.
     * @param volumeProvider a volume provider
     * @param mplc a {@link MediaPlaylistController} that manages playlist of the
     * @see #setPlayer(MediaPlayerBase)
     * {@code player.}
     * @see Builder#setVolumeProvider(VolumeProvider2)
     * @param volumeProvider The provider that will receive volume button events. If
     * {@code null}, system will adjust the appropriate stream volume for this session's player.
     */
     */
    public void setPlayer(@NonNull MediaPlayerBase player,
    public void updatePlayer(@NonNull MediaPlayerBase player,
            @NonNull VolumeProvider2 volumeProvider) {
            @Nullable MediaPlaylistController mplc, @NonNull VolumeProvider2 volumeProvider) {
        mProvider.setPlayer_impl(player, volumeProvider);
        // TODO: rename setPlayer_impl to updatePlayer_impl
        mProvider.setPlayer_impl(player, mplc, volumeProvider);
    }
    }


    @Override
    @Override
@@ -1172,6 +1198,24 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
        return mProvider.getPlayer_impl();
        return mProvider.getPlayer_impl();
    }
    }


    /**
     * @return playlist controller
     */
    public @Nullable
    MediaPlaylistController getMediaPlaylistController() {
        // TODO: implement this
        return null;
    }

    /**
     * @return volume provider
     */
    public @Nullable
    VolumeProvider2 getVolumeProvider() {
     // TODO: implement this
        return null;
    }

    /**
    /**
     * Returns the {@link SessionToken2} for creating {@link MediaController2}.
     * Returns the {@link SessionToken2} for creating {@link MediaController2}.
     */
     */
@@ -1368,9 +1412,9 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
    }
    }


    /**
    /**
     * Remove the media item at index in the play list.
     * Remove the media item in the play list.
     * <p>
     * <p>
     * If index is same as the current index 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
     * @throws IllegalArgumentException if the play list is null
@@ -1397,18 +1441,6 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
        mProvider.addPlaylistItem_impl(index, item);
        mProvider.addPlaylistItem_impl(index, item);
    }
    }


    /**
     * Edit the media item to the play list at position index. This is expected to be called when
     * the metadata information is updated.
     * <p>
     * This will not change the currently playing media item.
     *
     * @param item the media item you want to add to the play list
     */
    public void editPlaylistItem(@NonNull MediaItem2 item) {
        mProvider.editPlaylistItem_impl(item);
    }

    /**
    /**
     * Replace the media item at index in the playlist.
     * Replace the media item at index in the playlist.
     * @param index the index of the item to replace
     * @param index the index of the item to replace
@@ -1462,10 +1494,10 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
     * Notify errors to the connected controllers
     * Notify errors to the connected controllers
     *
     *
     * @param errorCode error code
     * @param errorCode error code
     * @param extra extra
     * @param extras extras
     */
     */
    public void notifyError(@ErrorCode int errorCode, int extra) {
    public void notifyError(@ErrorCode int errorCode, @Nullable Bundle extras) {
        mProvider.notifyError_impl(errorCode, extra);
        mProvider.notifyError_impl(errorCode, extras);
    }
    }


    /**
    /**
@@ -1506,4 +1538,21 @@ public class MediaSession2 implements AutoCloseable, MediaPlaylistController {
    public PlaybackState2 getPlaybackState() {
    public PlaybackState2 getPlaybackState() {
        return mProvider.getPlaybackState_impl();
        return mProvider.getPlaybackState_impl();
    }
    }

    /**
     * Get the playback speed.
     *
     * @return speed
     */
    public float getPlaybackSpeed() {
        // TODO: implement this
        return -1;
    }

    /**
     * Set the playback speed.
     */
    public void setPlaybackSpeed(float speed) {
        // TODO: implement this
    }
}
}
Loading