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

Commit 91574773 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Public APIs for media position in RemoteControlClient

New APIs in android.media.RemoteControlClient to support application
 exposing their current media playback position and speed, and
 let the framework request position changes.

Bug 8120740

Change-Id: Ibfc41f60e279413c26147e3276d96f28b7f506e7
parent b7e6a443
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -12255,13 +12255,17 @@ package android.media {
    ctor public RemoteControlClient(android.app.PendingIntent);
    ctor public RemoteControlClient(android.app.PendingIntent, android.os.Looper);
    method public android.media.RemoteControlClient.MetadataEditor editMetadata(boolean);
    method public void setOnGetPlaybackPositionListener(android.media.RemoteControlClient.OnGetPlaybackPositionListener);
    method public void setPlaybackPositionUpdateListener(android.media.RemoteControlClient.OnPlaybackPositionUpdateListener);
    method public void setPlaybackState(int);
    method public void setPlaybackState(int, long, float);
    method public void setTransportControlFlags(int);
    field public static final int FLAG_KEY_MEDIA_FAST_FORWARD = 64; // 0x40
    field public static final int FLAG_KEY_MEDIA_NEXT = 128; // 0x80
    field public static final int FLAG_KEY_MEDIA_PAUSE = 16; // 0x10
    field public static final int FLAG_KEY_MEDIA_PLAY = 4; // 0x4
    field public static final int FLAG_KEY_MEDIA_PLAY_PAUSE = 8; // 0x8
    field public static final int FLAG_KEY_MEDIA_POSITION_UPDATE = 256; // 0x100
    field public static final int FLAG_KEY_MEDIA_PREVIOUS = 1; // 0x1
    field public static final int FLAG_KEY_MEDIA_REWIND = 2; // 0x2
    field public static final int FLAG_KEY_MEDIA_STOP = 32; // 0x20
@@ -12285,6 +12289,14 @@ package android.media {
    field public static final int BITMAP_KEY_ARTWORK = 100; // 0x64
  }
  public static abstract interface RemoteControlClient.OnGetPlaybackPositionListener {
    method public abstract long onGetPlaybackPosition();
  }
  public static abstract interface RemoteControlClient.OnPlaybackPositionUpdateListener {
    method public abstract void onPlaybackPositionUpdate(long);
  }
  public class Ringtone {
    method public int getStreamType();
    method public java.lang.String getTitle(android.content.Context);
+9 −20
Original line number Diff line number Diff line
@@ -277,14 +277,12 @@ public class RemoteControlClient
     */
    public final static int FLAG_KEY_MEDIA_NEXT = 1 << 7;
    /**
     * @hide
     * TODO un-hide and add in javadoc of setTransportControlFlags(int)
     * Flag indicating a RemoteControlClient can receive changes in the media playback position
     * through the {@link #OnPlaybackPositionUpdateListener} interface. This flag must be set
     * in order for components that display the RemoteControlClient information, to display and
     * let the user control media playback position.
     * @see #setTransportControlFlags(int)
     * @see #setPlaybackPositionProvider(PlaybackPositionProvider)
     * @see #setOnGetPlaybackPositionListener(OnGetPlaybackPositionListener)
     * @see #setPlaybackPositionUpdateListener(OnPlaybackPositionUpdateListener)
     */
    public final static int FLAG_KEY_MEDIA_POSITION_UPDATE = 1 << 8;
@@ -607,8 +605,6 @@ public class RemoteControlClient
    }

    /**
     * @hide
     * TODO un-hide
     * Sets the current playback state and the matching media position for the current playback
     *   speed.
     * @param state The current playback state, one of the following values:
@@ -660,7 +656,8 @@ public class RemoteControlClient
     *      {@link #FLAG_KEY_MEDIA_PAUSE},
     *      {@link #FLAG_KEY_MEDIA_STOP},
     *      {@link #FLAG_KEY_MEDIA_FAST_FORWARD},
     *      {@link #FLAG_KEY_MEDIA_NEXT}
     *      {@link #FLAG_KEY_MEDIA_NEXT},
     *      {@link #FLAG_KEY_MEDIA_POSITION_UPDATE}
     */
    public void setTransportControlFlags(int transportControlFlags) {
        synchronized(mCacheLock) {
@@ -673,8 +670,6 @@ public class RemoteControlClient
    }

    /**
     * @hide
     * TODO un-hide
     * Interface definition for a callback to be invoked when the media playback position is
     * requested to be updated.
     * @see RemoteControlClient#FLAG_KEY_MEDIA_POSITION_UPDATE
@@ -695,30 +690,26 @@ public class RemoteControlClient
    }

    /**
     * @hide
     * TODO un-hide
     * Interface definition for a callback to be invoked when the media playback position is
     * queried.
     * @see RemoteControlClient#FLAG_KEY_MEDIA_POSITION_UPDATE
     */
    public interface PlaybackPositionProvider {
    public interface OnGetPlaybackPositionListener {
        /**
         * Called on the implementer of the interface to query the current playback position.
         * @return a negative value if the current playback position (or the last valid playback
         *     position) is not known, or a zero or positive value expressed in ms indicating the
         *     current position, or the last valid known position.
         */
        long getPlaybackPosition();
        long onGetPlaybackPosition();
    }

    /**
     * @hide
     * TODO un-hide
     * Sets the listener to be called whenever the media playback position is requested
     * to be updated.
     * Notifications will be received in the same thread as the one in which RemoteControlClient
     * was created.
     * @param l
     * @param l the position update listener to be called
     */
    public void setPlaybackPositionUpdateListener(OnPlaybackPositionUpdateListener l) {
        synchronized(mCacheLock) {
@@ -737,14 +728,12 @@ public class RemoteControlClient
    }

    /**
     * @hide
     * TODO un-hide
     * Sets the listener to be called whenever the media current playback position is needed.
     * Queries will be received in the same thread as the one in which RemoteControlClient
     * was created.
     * @param l
     * @param l the listener to be called to retrieve the playback position
     */
    public void setPlaybackPositionProvider(PlaybackPositionProvider l) {
    public void setOnGetPlaybackPositionListener(OnGetPlaybackPositionListener l) {
        synchronized(mCacheLock) {
            int oldCapa = mPlaybackPositionCapabilities;
            if (l != null) {
@@ -942,7 +931,7 @@ public class RemoteControlClient
    /**
     * Provider registered by user of RemoteControlClient to provide the current playback position.
     */
    private PlaybackPositionProvider mPositionProvider;
    private OnGetPlaybackPositionListener mPositionProvider;
    /**
     * The current remote control client generation ID across the system, as known by this object
     */