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

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

Merge changes from topics "playerinterface_onError",...

Merge changes from topics "playerinterface_onError", "mediasession2_notifychildren", "mediasession2_subscribe", "MediaSession2_rating_style_for_each_item"

* changes:
  MediaSession2: Add a way to notify errors between session and player
  MediaSession2: Implement MediaLibrarySession#notifyChildrenChanged()
  MediaSession2: Implement subscribe/unsubscribe
  MediaSession2: Remove rating style from session
parents 6c9afb62 ef2a534d
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.media.MediaLibraryService2.MediaLibrarySession;
import android.media.MediaSession2.ControllerInfo;
import android.media.update.ApiLoader;
import android.media.update.MediaBrowser2Provider;
import android.os.Bundle;
@@ -54,11 +56,18 @@ public class MediaBrowser2 extends MediaController2 {

        /**
         * Called when there's change in the parent's children.
         * <p>
         * This API is called when the library service called
         * {@link MediaLibrarySession#notifyChildrenChanged(ControllerInfo, String, int, Bundle)} or
         * {@link MediaLibrarySession#notifyChildrenChanged(String, int, Bundle)} for the parent.
         *
         * @param parentId parent id that you've specified with {@link #subscribe(String, Bundle)}
         * @param extras extra bundle from the library service
         * @param childCount number of children
         * @param extras extra bundle from the library service. Can be differ from extras that
         *               you've specified with {@link #subscribe(String, Bundle)}.
         */
        public void onChildrenChanged(@NonNull String parentId, @Nullable Bundle extras) { }
        public void onChildrenChanged(@NonNull String parentId, int childCount,
                @Nullable Bundle extras) { }

        /**
         * Called when the list of items has been returned by the library service for the previous
@@ -142,7 +151,7 @@ public class MediaBrowser2 extends MediaController2 {

    /**
     * Subscribe to a parent id for the change in its children. When there's a change,
     * {@link BrowserCallback#onChildrenChanged(String, Bundle)} will be called with the bundle
     * {@link BrowserCallback#onChildrenChanged(String, int, Bundle)} will be called with the bundle
     * that you've specified. You should call {@link #getChildren(String, int, int, Bundle)} to get
     * the actual contents for the parent.
     *
@@ -156,12 +165,14 @@ public class MediaBrowser2 extends MediaController2 {
    /**
     * Unsubscribe for changes to the children of the parent, which was previously subscribed with
     * {@link #subscribe(String, Bundle)}.
     * <p>
     * This unsubscribes all previous subscription with the parent id, regardless of the extra
     * that was previously sent to the library service.
     *
     * @param parentId parent id
     * @param extras extra bundle
     */
    public void unsubscribe(String parentId, @Nullable Bundle extras) {
        mProvider.unsubscribe_impl(parentId, extras);
    public void unsubscribe(String parentId) {
        mProvider.unsubscribe_impl(parentId);
    }

    /**
+6 −19
Original line number Diff line number Diff line
@@ -520,24 +520,6 @@ public class MediaController2 implements AutoCloseable {
        mProvider.adjustVolume_impl(direction, flags);
    }

    /**
     * Get the rating type supported by the session. One of:
     * <ul>
     * <li>{@link Rating2#RATING_NONE}</li>
     * <li>{@link Rating2#RATING_HEART}</li>
     * <li>{@link Rating2#RATING_THUMB_UP_DOWN}</li>
     * <li>{@link Rating2#RATING_3_STARS}</li>
     * <li>{@link Rating2#RATING_4_STARS}</li>
     * <li>{@link Rating2#RATING_5_STARS}</li>
     * <li>{@link Rating2#RATING_PERCENTAGE}</li>
     * </ul>
     *
     * @return The supported rating type
     */
    public int getRatingType() {
        return mProvider.getRatingType_impl();
    }

    /**
     * Get an intent for launching UI associated with this session if one exists.
     *
@@ -571,7 +553,12 @@ public class MediaController2 implements AutoCloseable {

    /**
     * Rate the media. This will cause the rating to be set for the current user.
     * The Rating type must match the type returned by {@link #getRatingType()}.
     * The rating style must follow the user rating style from the session.
     * You can get the rating style from the session through the
     * {@link MediaMetadata#getRating(String)} with the key
     * {@link MediaMetadata#METADATA_KEY_USER_RATING}.
     * <p>
     * If the user rating was {@code null}, the media item does not accept setting user rating.
     *
     * @param mediaId The id of the media
     * @param rating The rating to set
+27 −21
Original line number Diff line number Diff line
@@ -78,26 +78,36 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
        }

        /**
         * Notify subscribed controller about change in a parent's children.
         * Notify the controller of the change in a parent's children.
         * <p>
         * If the controller hasn't subscribed to the parent, the API will do nothing.
         * <p>
         * Controllers will use {@link MediaBrowser2#getChildren(String, int, int, Bundle)} to get
         * the list of children.
         *
         * @param controller controller to notify
         * @param parentId
         * @param extras
         * @param parentId parent id with changes in its children
         * @param childCount number of children.
         * @param extras extra information from session to controller
         */
        public void notifyChildrenChanged(@NonNull ControllerInfo controller,
                @NonNull String parentId, @NonNull Bundle extras) {
            mProvider.notifyChildrenChanged_impl(controller, parentId, extras);
                @NonNull String parentId, int childCount, @Nullable Bundle extras) {
            mProvider.notifyChildrenChanged_impl(controller, parentId, childCount, extras);
        }

        /**
         * Notify subscribed controller about change in a parent's children.
         * Notify all controllers that subscribed to the parent about change in the parent's
         * children, regardless of the extra bundle supplied by
         * {@link MediaBrowser2#subscribe(String, Bundle)}.
         *
         * @param parentId parent id
         * @param extras extra bundle
         * @param childCount number of children
         * @param extras extra information from session to controller
         */
        // This is for the backward compatibility.
        public void notifyChildrenChanged(@NonNull String parentId, @Nullable Bundle extras) {
            mProvider.notifyChildrenChanged_impl(parentId, extras);
        public void notifyChildrenChanged(@NonNull String parentId, int childCount,
                @Nullable Bundle extras) {
            mProvider.notifyChildrenChanged_impl(parentId, childCount, extras);
        }

        /**
@@ -176,25 +186,27 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
        }

        /**
         * Called when a controller subscribes to the parent.
         * Called when a controller subscribed to the parent.
         * <p>
         * It's your responsibility to keep subscriptions by your own and call
         * {@link MediaLibrarySession#notifyChildrenChanged(ControllerInfo, String, Bundle)} when
         * the parent is changed.
         *
         * @param controller controller
         * @param parentId parent id
         * @param extras extra bundle
         */
        public void onSubscribed(@NonNull ControllerInfo controller, String parentId,
        public void onSubscribed(@NonNull ControllerInfo controller, @NonNull String parentId,
                @Nullable Bundle extras) {
        }

        /**
         * Called when a controller unsubscribes to the parent.
         * Called when a controller unsubscribed to the parent.
         *
         * @param controller controller
         * @param parentId parent id
         * @param extras extra bundle
         */
        public void onUnsubscribed(@NonNull ControllerInfo controller, String parentId,
                @Nullable Bundle extras) {
        public void onUnsubscribed(@NonNull ControllerInfo controller, @NonNull String parentId) {
        }

        /**
@@ -206,7 +218,6 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
         */
        public void onSearch(@NonNull ControllerInfo controllerInfo, @NonNull String query,
                @Nullable Bundle extras) {

        }

        /**
@@ -251,11 +262,6 @@ public abstract class MediaLibraryService2 extends MediaSessionService2 {
            return super.setVolumeProvider(volumeProvider);
        }

        @Override
        public MediaLibrarySessionBuilder setRatingType(int type) {
            return super.setRatingType(type);
        }

        @Override
        public MediaLibrarySessionBuilder setSessionActivity(@Nullable PendingIntent pi) {
            return super.setSessionActivity(pi);
+3 −0
Original line number Diff line number Diff line
@@ -436,6 +436,9 @@ public final class MediaMetadata2 {
    /**
     * Return a {@link Rating2} for the given key or null if no rating exists for
     * the given key.
     * <p>
     * For the {@link #METADATA_KEY_USER_RATING}, A {@code null} return value means that user rating
     * cannot be set by {@link MediaController2}.
     *
     * @param key The key the value is stored under
     * @return A {@link Rating2} or {@code null}
+55 −10
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.media;

import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.media.MediaSession2.PlaylistParams;
@@ -29,13 +30,56 @@ import java.util.concurrent.Executor;
 */
public interface MediaPlayerInterface {
    /**
     * Listens change in {@link PlaybackState2}.
     * Unspecified media player error.
     */
    interface PlaybackListener {
    int MEDIA_ERROR_UNKNOWN = MediaPlayer2.MEDIA_ERROR_UNKNOWN;

    /**
     * The video is streamed and its container is not valid for progressive
     * playback i.e the video's index (e.g moov atom) is not at the start of the
     * file.
     */
    int MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK =
            MediaPlayer2.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK;

    /**
     * File or network related operation errors.
     */
    int MEDIA_ERROR_IO = MediaPlayer2.MEDIA_ERROR_IO;

    /**
     * Bitstream is not conforming to the related coding standard or file spec.
     */
    int MEDIA_ERROR_MALFORMED = MediaPlayer2.MEDIA_ERROR_MALFORMED;

    /**
     * Bitstream is conforming to the related coding standard or file spec, but
     * the media framework does not support the feature.
     */
    int MEDIA_ERROR_UNSUPPORTED = MediaPlayer2.MEDIA_ERROR_UNSUPPORTED;

    /**
     * Some operation takes too long to complete, usually more than 3-5 seconds.
     */
    int MEDIA_ERROR_TIMED_OUT = MediaPlayer2.MEDIA_ERROR_TIMED_OUT;

    /**
     * Callbacks to listens to the changes in {@link PlaybackState2} and error.
     */
    interface EventCallback {
        /**
         * Called when {@link PlaybackState2} for this player is changed.
         */
        void onPlaybackChanged(PlaybackState2 state);
        default void onPlaybackStateChanged(PlaybackState2 state) { }

        /**
         * Called to indicate an error.
         *
         * @param mediaId optional mediaId to indicate error
         * @param what what
         * @param extra
         */
        default void onError(@Nullable String mediaId, int what, int extra) { }
    }

    // Transport controls that session will send command directly to this player.
@@ -75,17 +119,18 @@ public interface MediaPlayerInterface {
    PlaylistParams getPlaylistParams();

    /**
     * Add a {@link PlaybackListener} to be invoked when the playback state is changed.
     * Register a {@link EventCallback}.
     *
     * @param executor the Handler that will receive the listener
     * @param listener the listener that will be run
     * @param executor a callback executor
     * @param callback a EventCallback
     */
    void addPlaybackListener(Executor executor, PlaybackListener listener);
    void registerEventCallback(@NonNull @CallbackExecutor Executor executor,
            @NonNull EventCallback callback);

    /**
     * Remove previously added {@link PlaybackListener}.
     * Unregister previously registered {@link EventCallback}.
     *
     * @param listener the listener to be removed
     * @param callback a EventCallback
     */
    void removePlaybackListener(PlaybackListener listener);
    void unregisterEventCallback(@NonNull EventCallback callback);
}
Loading