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

Commit bdbd7a62 authored by Jaewan Kim's avatar Jaewan Kim Committed by Android (Google) Code Review
Browse files

Merge changes from topics "mediaplayerinterface", "mediasession2_executor"

* changes:
  MediaSession2: Change MediaPlayerBase to MediaPlayerInterface
  MediaSession2: Use Executor for callback handling
parents b0db811f 1a2c263c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import android.annotation.Nullable;
import android.content.Context;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.MediaPlayerBase;
import android.media.MediaPlayerInterface;
import android.media.session.MediaController;
import android.media.update.ApiLoader;
import android.media.update.VideoView2Provider;
@@ -256,7 +256,7 @@ public class VideoView2 extends FrameLayout {
     * @throws IllegalStateException if MediaControlView2 is not set.
     */
    public void setRouteAttributes(@NonNull List<String> routeCategories,
            @Nullable MediaPlayerBase player) {
            @Nullable MediaPlayerInterface player) {
        mProvider.setRouteAttributes_impl(routeCategories, player);
    }

+2 −0
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ interface IMediaSession2 {
    // send command
    //////////////////////////////////////////////////////////////////////////////////////////////
    oneway void sendCommand(IMediaSession2Callback caller, in Bundle command, in Bundle args);
    oneway void sendTransportControlCommand(IMediaSession2Callback caller,
            int commandCode, long arg);

    Bundle getPlaybackState();

+6 −5
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
    public class MediaLibrarySession extends MediaSession2 {
        private final MediaLibrarySessionProvider mProvider;

        MediaLibrarySession(Context context, MediaPlayerBase player, String id,
        MediaLibrarySession(Context context, MediaPlayerInterface player, String id,
                VolumeProvider volumeProvider, int ratingType, PendingIntent sessionActivity,
                Executor callbackExecutor, SessionCallback callback) {
            super(context, player, id, volumeProvider, ratingType, sessionActivity,
@@ -75,9 +75,10 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
        }

        @Override
        MediaSession2Provider createProvider(Context context, MediaPlayerBase player, String id,
                VolumeProvider volumeProvider, int ratingType, PendingIntent sessionActivity,
                Executor callbackExecutor, SessionCallback callback) {
        MediaSession2Provider createProvider(Context context, MediaPlayerInterface player,
                String id, VolumeProvider volumeProvider, int ratingType,
                PendingIntent sessionActivity, Executor callbackExecutor,
                SessionCallback callback) {
            return ApiLoader.getProvider(context)
                    .createMediaLibraryService2MediaLibrarySession(context, this, player, id,
                            volumeProvider, ratingType, sessionActivity,
@@ -206,7 +207,7 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
    public class MediaLibrarySessionBuilder
            extends BuilderBase<MediaLibrarySessionBuilder, MediaLibrarySessionCallback> {
        public MediaLibrarySessionBuilder(
                @NonNull Context context, @NonNull MediaPlayerBase player,
                @NonNull Context context, @NonNull MediaPlayerInterface player,
                @NonNull @CallbackExecutor Executor callbackExecutor,
                @NonNull MediaLibrarySessionCallback callback) {
            super(context, player);
+18 −17
Original line number Diff line number Diff line
@@ -25,32 +25,33 @@ import java.util.concurrent.Executor;
 * Base interfaces for all media players that want media session.
 * @hide
 */
public abstract class MediaPlayerBase {
public interface MediaPlayerInterface {
    /**
     * Listens change in {@link PlaybackState2}.
     */
    public interface PlaybackListener {
    interface PlaybackListener {
        /**
         * Called when {@link PlaybackState2} for this player is changed.
         */
        void onPlaybackChanged(PlaybackState2 state);
    }

    public abstract void play();
    public abstract void prepare();
    public abstract void pause();
    public abstract void stop();
    public abstract void skipToPrevious();
    public abstract void skipToNext();
    public abstract void seekTo(long pos);
    public abstract void fastFoward();
    public abstract void rewind();
    // Transport controls that session will send command directly to this player.
    void play();
    void prepare();
    void pause();
    void stop();
    void skipToPrevious();
    void skipToNext();
    void seekTo(long pos);
    void fastFoward();
    void rewind();

    public abstract PlaybackState2 getPlaybackState();
    public abstract AudioAttributes getAudioAttributes();
    PlaybackState2 getPlaybackState();
    AudioAttributes getAudioAttributes();

    public abstract void setPlaylist(List<MediaItem2> item, PlaylistParams param);
    public abstract void setCurrentPlaylistItem(int index);
    void setPlaylist(List<MediaItem2> item, PlaylistParams param);
    void setCurrentPlaylistItem(int index);

    /**
     * Add a {@link PlaybackListener} to be invoked when the playback state is changed.
@@ -58,12 +59,12 @@ public abstract class MediaPlayerBase {
     * @param executor the Handler that will receive the listener
     * @param listener the listener that will be run
     */
    public abstract void addPlaybackListener(Executor executor, PlaybackListener listener);
    void addPlaybackListener(Executor executor, PlaybackListener listener);

    /**
     * Remove previously added {@link PlaybackListener}.
     *
     * @param listener the listener to be removed
     */
    public abstract void removePlaybackListener(PlaybackListener listener);
    void removePlaybackListener(PlaybackListener listener);
}
+24 −18
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ import android.annotation.SystemApi;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayerBase.PlaybackListener;
import android.media.MediaPlayerInterface.PlaybackListener;
import android.media.session.MediaSession;
import android.media.session.MediaSession.Callback;
import android.media.session.PlaybackState;
@@ -67,7 +67,8 @@ import java.util.concurrent.Executor;
 * session.
 * <p>
 * When a session receive transport control commands, the session sends the commands directly to
 * the the underlying media player set by {@link Builder} or {@link #setPlayer(MediaPlayerBase)}.
 * the the underlying media player set by {@link Builder} or
 * {@link #setPlayer(MediaPlayerInterface)}.
 * <p>
 * When an app is finished performing playback it must call {@link #close()} to clean up the session
 * and notify any controllers.
@@ -457,7 +458,7 @@ public class MediaSession2 implements AutoCloseable {
    static abstract class BuilderBase
            <T extends MediaSession2.BuilderBase<T, C>, C extends SessionCallback> {
        final Context mContext;
        final MediaPlayerBase mPlayer;
        final MediaPlayerInterface mPlayer;
        String mId;
        Executor mCallbackExecutor;
        C mCallback;
@@ -474,7 +475,7 @@ public class MediaSession2 implements AutoCloseable {
         *      {@link MediaSession2} or {@link MediaController2}.
         */
        // TODO(jaewan): Also need executor
        public BuilderBase(@NonNull Context context, @NonNull MediaPlayerBase player) {
        public BuilderBase(@NonNull Context context, @NonNull MediaPlayerInterface player) {
            if (context == null) {
                throw new IllegalArgumentException("context shouldn't be null");
            }
@@ -589,12 +590,15 @@ public class MediaSession2 implements AutoCloseable {
    // TODO(jaewan): Add setRatingType()
    // TODO(jaewan): Add setSessionActivity()
    public static final class Builder extends BuilderBase<Builder, SessionCallback> {
        public Builder(Context context, @NonNull MediaPlayerBase player) {
        public Builder(Context context, @NonNull MediaPlayerInterface player) {
            super(context, player);
        }

        @Override
        public MediaSession2 build() {
            if (mCallbackExecutor == null) {
                mCallbackExecutor = mContext.getMainExecutor();
            }
            if (mCallback == null) {
                mCallback = new SessionCallback();
            }
@@ -941,16 +945,16 @@ public class MediaSession2 implements AutoCloseable {
     * @hide
     */

    MediaSession2(Context context, MediaPlayerBase player, String id, VolumeProvider volumeProvider,
            int ratingType, PendingIntent sessionActivity, Executor callbackExecutor,
            SessionCallback callback) {
    MediaSession2(Context context, MediaPlayerInterface player, String id,
            VolumeProvider volumeProvider, int ratingType, PendingIntent sessionActivity,
            Executor callbackExecutor, SessionCallback callback) {
        super();
        mProvider = createProvider(context, player, id, volumeProvider, ratingType, sessionActivity,
                callbackExecutor, callback
        );
    }

    MediaSession2Provider createProvider(Context context, MediaPlayerBase player, String id,
    MediaSession2Provider createProvider(Context context, MediaPlayerInterface player, String id,
            VolumeProvider volumeProvider, int ratingType, PendingIntent sessionActivity,
            Executor callbackExecutor, SessionCallback callback) {
        return ApiLoader.getProvider(context)
@@ -964,8 +968,8 @@ public class MediaSession2 implements AutoCloseable {
    }

    /**
     * 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
     * Set the underlying {@link MediaPlayerInterface} for this session to dispatch incoming event
     * to. Events from the {@link MediaController2} will be sent directly to the underlying
     * player on the {@link Handler} where the session is created on.
     * <p>
     * If the new player is successfully set, {@link PlaybackListener}
@@ -974,22 +978,23 @@ public class MediaSession2 implements AutoCloseable {
     * You can also specify a volume provider. If so, playback in the player is considered as
     * remote playback.
     *
     * @param player a {@link MediaPlayerBase} that handles actual media playback in your app.
     * @param player a {@link MediaPlayerInterface} that handles actual media playback in your app.
     * @throws IllegalArgumentException if the player is {@code null}.
     */
    public void setPlayer(@NonNull MediaPlayerBase player) {
    public void setPlayer(@NonNull MediaPlayerInterface player) {
        mProvider.setPlayer_impl(player);
    }

    /**
     * Set the underlying {@link MediaPlayerBase} with the volume provider for remote playback.
     * Set the underlying {@link MediaPlayerInterface} with the volume provider for remote playback.
     *
     * @param player a {@link MediaPlayerBase} that handles actual media playback in your app.
     * @param player a {@link MediaPlayerInterface} that handles actual media playback in your app.
     * @param volumeProvider a volume provider
     * @see #setPlayer(MediaPlayerBase)
     * @see #setPlayer(MediaPlayerInterface)
     * @see Builder#setVolumeProvider(VolumeProvider)
     */
    public void setPlayer(@NonNull MediaPlayerBase player, @NonNull VolumeProvider volumeProvider) {
    public void setPlayer(@NonNull MediaPlayerInterface player,
            @NonNull VolumeProvider volumeProvider) {
        mProvider.setPlayer_impl(player, volumeProvider);
    }

@@ -1001,7 +1006,8 @@ public class MediaSession2 implements AutoCloseable {
    /**
     * @return player
     */
    public @Nullable MediaPlayerBase getPlayer() {
    public @Nullable
    MediaPlayerInterface getPlayer() {
        return mProvider.getPlayer_impl();
    }

Loading