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

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

Merge "MediaSession2: Implement skipTo APIs" into pi-dev

parents 44240378 54d63861
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@ oneway interface IMediaSession2 {
    void addPlaylistItem(IMediaController2 caller, int index, in Bundle mediaItem);
    void removePlaylistItem(IMediaController2 caller, in Bundle mediaItem);
    void replacePlaylistItem(IMediaController2 caller, int index, in Bundle mediaItem);
    void skipToPlaylistItem(IMediaController2 caller, in Bundle mediaItem);
    void skipToPreviousItem(IMediaController2 caller);
    void skipToNextItem(IMediaController2 caller);

    //////////////////////////////////////////////////////////////////////////////////////////////
    // library service specific
+37 −20
Original line number Diff line number Diff line
@@ -334,14 +334,49 @@ public class MediaController2Impl implements MediaController2Provider {
        sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_STOP);
    }

    @Override
    public void skipToPlaylistItem_impl(MediaItem2 item) {
        if (item == null) {
            throw new IllegalArgumentException("item shouldn't be null");
        }
        final IMediaSession2 binder = mSessionBinder;
        if (binder != null) {
            try {
                binder.skipToPlaylistItem(mControllerStub, item.toBundle());
            } catch (RemoteException e) {
                Log.w(TAG, "Cannot connect to the service or the session is gone", e);
            }
        } else {
            Log.w(TAG, "Session isn't active", new IllegalStateException());
        }
    }

    @Override
    public void skipToPreviousItem_impl() {
        sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_PREV_ITEM);
        final IMediaSession2 binder = mSessionBinder;
        if (binder != null) {
            try {
                binder.skipToPreviousItem(mControllerStub);
            } catch (RemoteException e) {
                Log.w(TAG, "Cannot connect to the service or the session is gone", e);
            }
        } else {
            Log.w(TAG, "Session isn't active", new IllegalStateException());
        }
    }

    @Override
    public void skipToNextItem_impl() {
        sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM);
        final IMediaSession2 binder = mSessionBinder;
        if (binder != null) {
            try {
                binder.skipToNextItem(mControllerStub);
            } catch (RemoteException e) {
                Log.w(TAG, "Cannot connect to the service or the session is gone", e);
            }
        } else {
            Log.w(TAG, "Session isn't active", new IllegalStateException());
        }
    }

    private void sendTransportControlCommand(int commandCode) {
@@ -361,9 +396,6 @@ public class MediaController2Impl implements MediaController2Provider {
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////
    // TODO(jaewan): Implement follows
    //////////////////////////////////////////////////////////////////////////////////////
    @Override
    public PendingIntent getSessionActivity_impl() {
        return mSessionActivity;
@@ -616,21 +648,6 @@ public class MediaController2Impl implements MediaController2Provider {
        sendTransportControlCommand(MediaSession2.COMMAND_CODE_PLAYBACK_SEEK_TO, args);
    }

    @Override
    public void skipToPlaylistItem_impl(MediaItem2 item) {
        if (item == null) {
            throw new IllegalArgumentException("item shouldn't be null");
        }

        // TODO(jaewan): Implement this
        /*
        Bundle args = new Bundle();
        args.putInt(MediaSession2Stub.ARGUMENT_KEY_ITEM_INDEX, item);
        sendTransportControlCommand(
                MediaSession2.COMMAND_CODE_PLAYLIST_SKIP_TO_PLAYLIST_ITEM, args);
        */
    }

    @Override
    public void addPlaylistItem_impl(int index, MediaItem2 item) {
        if (index < 0) {
+19 −33
Original line number Diff line number Diff line
@@ -385,33 +385,37 @@ public class MediaSession2Impl implements MediaSession2Provider {
        }
    }

    @Override
    public void skipToPlaylistItem_impl(MediaItem2 item) {
        if (item == null) {
            throw new IllegalArgumentException("item shouldn't be null");
        }
        final MediaPlaylistAgent agent = mPlaylistAgent;
        if (agent != null) {
            agent.skipToPlaylistItem(item);
        } else if (DEBUG) {
            Log.d(TAG, "API calls after the close()", new IllegalStateException());
        }
    }

    @Override
    public void skipToPreviousItem_impl() {
        ensureCallingThread();
        // TODO(jaewan): Implement this (b/74175632)
        /*
        final MediaPlayerBase player = mPlayer;
        if (player != null) {
            // TODO implement
            //player.skipToPrevious();
        final MediaPlaylistAgent agent = mPlaylistAgent;
        if (agent != null) {
            agent.skipToPreviousItem();
        } else if (DEBUG) {
            Log.d(TAG, "API calls after the close()", new IllegalStateException());
        }
        */
    }

    @Override
    public void skipToNextItem_impl() {
        ensureCallingThread();
        // TODO(jaewan): Implement this (b/74175632)
        /*
        final MediaPlayerBase player = mPlayer;
        if (player != null) {
            player.skipToNext();
        final MediaPlaylistAgent agent = mPlaylistAgent;
        if (agent != null) {
            agent.skipToNextItem();
        } else if (DEBUG) {
            Log.d(TAG, "API calls after the close()", new IllegalStateException());
        }
        */
    }

    @Override
@@ -645,24 +649,6 @@ public class MediaSession2Impl implements MediaSession2Provider {
        }
    }

    @Override
    public void skipToPlaylistItem_impl(MediaItem2 item) {
        ensureCallingThread();
        if (item == null) {
            throw new IllegalArgumentException("item shouldn't be null");
        }
        // TODO: Uncomment or remove
        /*
        final MediaPlayerBase player = mPlayer;
        if (player != null) {
            // TODO implement
            //player.setCurrentPlaylistItem(item);
        } else if (DEBUG) {
            Log.d(TAG, "API calls after the close()", new IllegalStateException());
        }
        */
    }

    @Override
    public void registerPlayerEventCallback_impl(Executor executor, PlayerEventCallback callback) {
        if (executor == null) {
+33 −16
Original line number Diff line number Diff line
@@ -495,12 +495,6 @@ public class MediaSession2Stub extends IMediaSession2.Stub {
                case MediaSession2.COMMAND_CODE_PLAYBACK_STOP:
                    session.getInstance().stop();
                    break;
                case MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_PREV_ITEM:
                    session.getInstance().skipToPreviousItem();
                    break;
                case MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM:
                    session.getInstance().skipToNextItem();
                    break;
                case MediaSession2.COMMAND_CODE_PLAYBACK_PREPARE:
                    session.getInstance().prepare();
                    break;
@@ -513,13 +507,6 @@ public class MediaSession2Stub extends IMediaSession2.Stub {
                case MediaSession2.COMMAND_CODE_PLAYBACK_SEEK_TO:
                    session.getInstance().seekTo(args.getLong(ARGUMENT_KEY_POSITION));
                    break;
                case MediaSession2.COMMAND_CODE_PLAYLIST_SKIP_TO_PLAYLIST_ITEM:
                    // TODO(jaewan): Implement
                    /*
                    session.getInstance().skipToPlaylistItem(
                            args.getInt(ARGUMENT_KEY_ITEM_INDEX));
                    */
                    break;
                    // TODO(jaewan): Remove (b/74116823)
                    /*
                case MediaSession2.COMMAND_CODE_PLAYBACK_SET_PLAYLIST_PARAMS:
@@ -708,9 +695,8 @@ public class MediaSession2Stub extends IMediaSession2.Stub {
        onCommand(caller, MediaSession2.COMMAND_CODE_PLAYLIST_REMOVE_ITEM,
                (session, controller) -> {
            MediaItem2 item = MediaItem2.fromBundle(session.getContext(), mediaItem);
            List<MediaItem2> list = session.getInstance().getPlaylist();
            // Trick to use the same reference for calls from the controller.
            session.getInstance().removePlaylistItem(list.get(list.indexOf(item)));
            // Note: MediaItem2 has hidden UUID to identify it across the processes.
            session.getInstance().removePlaylistItem(item);
        });
    }

@@ -721,10 +707,41 @@ public class MediaSession2Stub extends IMediaSession2.Stub {
                    // Resets the UUID from the incoming media id, so controller may reuse a media
                    // item multiple times for replacePlaylistItem.
                    session.getInstance().replacePlaylistItem(index,
                            MediaItem2Impl.fromBundle(session.getContext(), mediaItem, null));
                });
    }

    @Override
    public void skipToPlaylistItem(IMediaController2 caller, Bundle mediaItem) {
        onCommand(caller, MediaSession2.COMMAND_CODE_PLAYLIST_SKIP_TO_PLAYLIST_ITEM,
                (session, controller) -> {
                    if (mediaItem == null) {
                        Log.w(TAG, "skipToPlaylistItem(): Ignoring null mediaItem from "
                                + controller);
                    }
                    // Note: MediaItem2 has hidden UUID to identify it across the processes.
                    session.getInstance().skipToPlaylistItem(
                            MediaItem2.fromBundle(session.getContext(), mediaItem));
                });
    }

    @Override
    public void skipToPreviousItem(IMediaController2 caller) {
        onCommand(caller, MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_PREV_ITEM,
                (session, controller) -> {
                    session.getInstance().skipToPreviousItem();
                });
    }

    @Override
    public void skipToNextItem(IMediaController2 caller) {
        onCommand(caller, MediaSession2.COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM,
                (session, controller) -> {
                    session.getInstance().skipToNextItem();
                });
    }


    //////////////////////////////////////////////////////////////////////////////////////////////
    // AIDL methods for LibrarySession overrides
    //////////////////////////////////////////////////////////////////////////////////////////////