mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Remove media1 public API dependencies from session module
This is the preparation to import the media1 classes as private copies into media3. - Reword Javadoc to use @code instead of @link to media1 types. This avoids accidentally linking to the future internal types. - Use fully qualified names for the converter methods to and from MediaSessionCompat.Token to ensure they keep the publicly available type. - Add new public variable that is directly referenced from our code instead of referring the the media1 equivalent. - Clean up tests that are using media1 types to make assertions on media3 fields and vice versa (mostly when using LegacyConversions in the test method). This also makes the tests more DAMP than DRY. (also moved LegacyConversionsTest to a unit test as it doesn't test cross-process communication) PiperOrigin-RevId: 626000082
This commit is contained in:
parent
34c31b0a33
commit
e1c62df256
1
api.txt
1
api.txt
@ -1761,6 +1761,7 @@ package androidx.media3.session {
|
|||||||
method public int getControllerVersion();
|
method public int getControllerVersion();
|
||||||
method public String getPackageName();
|
method public String getPackageName();
|
||||||
method public int getUid();
|
method public int getUid();
|
||||||
|
field public static final String LEGACY_CONTROLLER_PACKAGE_NAME = "android.media.session.MediaController";
|
||||||
field public static final int LEGACY_CONTROLLER_VERSION = 0; // 0x0
|
field public static final int LEGACY_CONTROLLER_VERSION = 0; // 0x0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,8 +23,6 @@ import static java.lang.annotation.ElementType.TYPE_USE;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.support.v4.media.session.MediaControllerCompat;
|
|
||||||
import android.support.v4.media.session.MediaSessionCompat;
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.BundleCompat;
|
import androidx.core.app.BundleCompat;
|
||||||
@ -78,8 +76,9 @@ public final class LibraryResult<V> implements Bundleable {
|
|||||||
* Result code representing that the command is successfully completed.
|
* Result code representing that the command is successfully completed.
|
||||||
*
|
*
|
||||||
* <p>Interoperability: This code is also used to tell that the command was successfully sent, but
|
* <p>Interoperability: This code is also used to tell that the command was successfully sent, but
|
||||||
* the result is unknown when connected with {@link MediaSessionCompat} or {@link
|
* the result is unknown when connected with {@code
|
||||||
* MediaControllerCompat}.
|
* android.support.v4.media.session.MediaSessionCompat} or {@code
|
||||||
|
* android.support.v4.media.session.MediaControllerCompat}.
|
||||||
*/
|
*/
|
||||||
public static final int RESULT_SUCCESS = 0;
|
public static final int RESULT_SUCCESS = 0;
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ import android.content.Context;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.support.v4.media.session.MediaSessionCompat;
|
|
||||||
import androidx.annotation.IntRange;
|
import androidx.annotation.IntRange;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
@ -87,7 +86,7 @@ public final class MediaBrowser extends MediaController {
|
|||||||
* of this bundle may affect the connection result.
|
* of this bundle may affect the connection result.
|
||||||
*
|
*
|
||||||
* <p>The hints are only used when connecting to the {@link MediaSession}. They will be ignored
|
* <p>The hints are only used when connecting to the {@link MediaSession}. They will be ignored
|
||||||
* when connecting to {@link MediaSessionCompat}.
|
* when connecting to {@code android.support.v4.media.session.MediaSessionCompat}.
|
||||||
*
|
*
|
||||||
* @param connectionHints A bundle containing the connection hints.
|
* @param connectionHints A bundle containing the connection hints.
|
||||||
* @return The builder to allow chaining.
|
* @return The builder to allow chaining.
|
||||||
|
@ -19,9 +19,6 @@ import android.app.PendingIntent;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.v4.media.MediaDescriptionCompat;
|
|
||||||
import android.support.v4.media.session.MediaControllerCompat;
|
|
||||||
import android.support.v4.media.session.MediaSessionCompat;
|
|
||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
import androidx.media3.common.MediaMetadata;
|
import androidx.media3.common.MediaMetadata;
|
||||||
@ -108,9 +105,7 @@ public final class MediaConstants {
|
|||||||
* androidx.media3.common.Player#COMMAND_SEEK_TO_NEXT} by design.
|
* androidx.media3.common.Player#COMMAND_SEEK_TO_NEXT} by design.
|
||||||
*
|
*
|
||||||
* @see MediaSession#setSessionExtras(Bundle)
|
* @see MediaSession#setSessionExtras(Bundle)
|
||||||
* @see MediaSessionCompat#setExtras(Bundle)
|
|
||||||
* @see MediaController.Listener#onExtrasChanged(MediaController, Bundle)
|
* @see MediaController.Listener#onExtrasChanged(MediaController, Bundle)
|
||||||
* @see MediaControllerCompat.Callback#onExtrasChanged(Bundle)
|
|
||||||
* @see androidx.media3.common.Player#COMMAND_SEEK_TO_NEXT
|
* @see androidx.media3.common.Player#COMMAND_SEEK_TO_NEXT
|
||||||
* @see androidx.media3.common.Player#COMMAND_SEEK_TO_NEXT_MEDIA_ITEM
|
* @see androidx.media3.common.Player#COMMAND_SEEK_TO_NEXT_MEDIA_ITEM
|
||||||
*/
|
*/
|
||||||
@ -126,9 +121,7 @@ public final class MediaConstants {
|
|||||||
* androidx.media3.common.Player#COMMAND_SEEK_TO_PREVIOUS} by design.
|
* androidx.media3.common.Player#COMMAND_SEEK_TO_PREVIOUS} by design.
|
||||||
*
|
*
|
||||||
* @see MediaSession#setSessionExtras(Bundle)
|
* @see MediaSession#setSessionExtras(Bundle)
|
||||||
* @see MediaSessionCompat#setExtras(Bundle)
|
|
||||||
* @see MediaController.Listener#onExtrasChanged(MediaController, Bundle)
|
* @see MediaController.Listener#onExtrasChanged(MediaController, Bundle)
|
||||||
* @see MediaControllerCompat.Callback#onExtrasChanged(Bundle)
|
|
||||||
* @see androidx.media3.common.Player#COMMAND_SEEK_TO_PREVIOUS
|
* @see androidx.media3.common.Player#COMMAND_SEEK_TO_PREVIOUS
|
||||||
* @see androidx.media3.common.Player#COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM
|
* @see androidx.media3.common.Player#COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM
|
||||||
*/
|
*/
|
||||||
@ -457,9 +450,9 @@ public final class MediaConstants {
|
|||||||
.BROWSER_SERVICE_EXTRAS_KEY_APPLICATION_PREFERENCES_USING_CAR_APP_LIBRARY_INTENT;
|
.BROWSER_SERVICE_EXTRAS_KEY_APPLICATION_PREFERENCES_USING_CAR_APP_LIBRARY_INTENT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Bundle} key used to indicate the {@link MediaMetadata.MediaType} in the legacy {@link
|
* {@link Bundle} key used to indicate the {@link MediaMetadata.MediaType} in the legacy {@code
|
||||||
* MediaDescriptionCompat} as a long {@link MediaDescriptionCompat#getExtras() extra} and as a
|
* android.support.v4.media.MediaDescriptionCompat} as a long extra and as a long value in {@code
|
||||||
* long value in {@link android.support.v4.media.MediaMetadataCompat}.
|
* android.support.v4.media.MediaMetadataCompat}.
|
||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public static final String EXTRAS_KEY_MEDIA_TYPE_COMPAT =
|
public static final String EXTRAS_KEY_MEDIA_TYPE_COMPAT =
|
||||||
|
@ -28,8 +28,6 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.support.v4.media.MediaBrowserCompat;
|
import android.support.v4.media.MediaBrowserCompat;
|
||||||
import android.support.v4.media.session.MediaControllerCompat;
|
|
||||||
import android.support.v4.media.session.MediaSessionCompat;
|
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
@ -119,7 +117,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
*
|
*
|
||||||
* <p>The app targeting API level 30 or higher must include a {@code <queries>} element in their
|
* <p>The app targeting API level 30 or higher must include a {@code <queries>} element in their
|
||||||
* manifest to connect to a service component of another app like {@link MediaSessionService},
|
* manifest to connect to a service component of another app like {@link MediaSessionService},
|
||||||
* {@link MediaLibraryService}, or {@link androidx.media.MediaBrowserServiceCompat}). See the
|
* {@link MediaLibraryService}, or {@code androidx.media.MediaBrowserServiceCompat}). See the
|
||||||
* following example and <a href="//developer.android.com/training/package-visibility">this
|
* following example and <a href="//developer.android.com/training/package-visibility">this
|
||||||
* guide</a> for more information.
|
* guide</a> for more information.
|
||||||
*
|
*
|
||||||
@ -141,28 +139,29 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
* <h2 id="BackwardCompatibility">Backward Compatibility with legacy media sessions</h2>
|
* <h2 id="BackwardCompatibility">Backward Compatibility with legacy media sessions</h2>
|
||||||
*
|
*
|
||||||
* <p>In addition to {@link MediaSession}, the controller also supports connecting to a legacy media
|
* <p>In addition to {@link MediaSession}, the controller also supports connecting to a legacy media
|
||||||
* session - {@linkplain android.media.session.MediaSession framework session} and {@linkplain
|
* session - {@link android.media.session.MediaSession} and {@code
|
||||||
* MediaSessionCompat AndroidX session compat}.
|
* android.support.v4.media.session.MediaSessionCompat}.
|
||||||
*
|
*
|
||||||
* <p>To request legacy sessions to play media, use one of the {@link #setMediaItem} methods and set
|
* <p>To request legacy sessions to play media, use one of the {@link #setMediaItem} methods and set
|
||||||
* either {@link MediaItem#mediaId}, {@link MediaItem.RequestMetadata#mediaUri} or {@link
|
* either {@link MediaItem#mediaId}, {@link MediaItem.RequestMetadata#mediaUri} or {@link
|
||||||
* MediaItem.RequestMetadata#searchQuery}. Once the controller is {@linkplain #prepare() prepared},
|
* MediaItem.RequestMetadata#searchQuery}. Once the controller is {@linkplain #prepare() prepared},
|
||||||
* the controller triggers one of the following callbacks depending on the provided information and
|
* the controller triggers one of the following methods on {@code
|
||||||
* the value of {@link #getPlayWhenReady()}:
|
* android.support.v4.media.session.MediaSessionCompat.Callback} depending on the provided
|
||||||
|
* information and the value of {@link #getPlayWhenReady()}:
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link MediaSessionCompat.Callback#onPrepareFromUri onPrepareFromUri}
|
* <li>{@code onPrepareFromUri}
|
||||||
* <li>{@link MediaSessionCompat.Callback#onPlayFromUri onPlayFromUri}
|
* <li>{@code onPlayFromUri}
|
||||||
* <li>{@link MediaSessionCompat.Callback#onPrepareFromMediaId onPrepareFromMediaId}
|
* <li>{@code onPrepareFromMediaId}
|
||||||
* <li>{@link MediaSessionCompat.Callback#onPlayFromMediaId onPlayFromMediaId}
|
* <li>{@code onPlayFromMediaId}
|
||||||
* <li>{@link MediaSessionCompat.Callback#onPrepareFromSearch onPrepareFromSearch}
|
* <li>{@code onPrepareFromSearch}
|
||||||
* <li>{@link MediaSessionCompat.Callback#onPlayFromSearch onPlayFromSearch}
|
* <li>{@code onPlayFromSearch}
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* Other playlist change methods, like {@link #addMediaItem} or {@link #removeMediaItem}, trigger
|
* Other playlist change methods, like {@link #addMediaItem} or {@link #removeMediaItem}, trigger
|
||||||
* the {@link MediaSessionCompat.Callback#onAddQueueItem onAddQueueItem} and {@link
|
* the {@code MediaSessionCompat.Callback.onAddQueueItem} and {@code
|
||||||
* MediaSessionCompat.Callback#onRemoveQueueItem} onRemoveQueueItem} callbacks. Check {@link
|
* MediaSessionCompat.Callback.onRemoveQueueItem} callbacks. Check {@link #getAvailableCommands()}
|
||||||
* #getAvailableCommands()} to see if playlist modifications are {@linkplain
|
* to see if playlist modifications are {@linkplain
|
||||||
* androidx.media3.common.Player#COMMAND_CHANGE_MEDIA_ITEMS supported} by the legacy session.
|
* androidx.media3.common.Player#COMMAND_CHANGE_MEDIA_ITEMS supported} by the legacy session.
|
||||||
*/
|
*/
|
||||||
@DoNotMock
|
@DoNotMock
|
||||||
@ -247,7 +246,7 @@ public class MediaController implements Player {
|
|||||||
* of this bundle may affect the connection result.
|
* of this bundle may affect the connection result.
|
||||||
*
|
*
|
||||||
* <p>The hints are only used when connecting to the {@link MediaSession}. They will be ignored
|
* <p>The hints are only used when connecting to the {@link MediaSession}. They will be ignored
|
||||||
* when connecting to {@link MediaSessionCompat}.
|
* when connecting to {@code android.support.v4.media.session.MediaSessionCompat}.
|
||||||
*
|
*
|
||||||
* @param connectionHints A bundle containing the connection hints.
|
* @param connectionHints A bundle containing the connection hints.
|
||||||
* @return The builder to allow chaining.
|
* @return The builder to allow chaining.
|
||||||
@ -664,7 +663,8 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link MediaSessionCompat}, it returns {code 0}.
|
* <p>Interoperability: When connected to {@code
|
||||||
|
* android.support.v4.media.session.MediaSessionCompat}, it returns {code 0}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final long getSeekBackIncrement() {
|
public final long getSeekBackIncrement() {
|
||||||
@ -675,8 +675,9 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link MediaSessionCompat}, it calls {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* MediaControllerCompat.TransportControls#rewind()}.
|
* android.support.v4.media.session.MediaSessionCompat}, it calls {@code
|
||||||
|
* android.support.v4.media.session.MediaControllerCompat.TransportControls.rewind()}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void seekBack() {
|
public final void seekBack() {
|
||||||
@ -691,7 +692,8 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link MediaSessionCompat}, it returns {code 0}.
|
* <p>Interoperability: When connected to {@code
|
||||||
|
* android.support.v4.media.session.MediaSessionCompat}, it returns {code 0}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final long getSeekForwardIncrement() {
|
public final long getSeekForwardIncrement() {
|
||||||
@ -702,8 +704,9 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link MediaSessionCompat}, it calls {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* MediaControllerCompat.TransportControls#fastForward()}.
|
* android.support.v4.media.session.MediaSessionCompat}, it calls {@code
|
||||||
|
* android.support.v4.media.session.MediaControllerCompat.TransportControls.fastForward()}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void seekForward() {
|
public final void seekForward() {
|
||||||
@ -808,7 +811,7 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, it's the same as {@link #getDuration()}
|
* android.support.v4.media.session.MediaSessionCompat}, it's the same as {@link #getDuration()}
|
||||||
* to match the behavior with {@link #getContentPosition()} and {@link
|
* to match the behavior with {@link #getContentPosition()} and {@link
|
||||||
* #getContentBufferedPosition()}.
|
* #getContentBufferedPosition()}.
|
||||||
@ -822,7 +825,7 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, it's the same as {@link
|
* android.support.v4.media.session.MediaSessionCompat}, it's the same as {@link
|
||||||
* #getCurrentPosition()} because content position isn't available.
|
* #getCurrentPosition()} because content position isn't available.
|
||||||
*/
|
*/
|
||||||
@ -835,7 +838,7 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, it's the same as {@link
|
* android.support.v4.media.session.MediaSessionCompat}, it's the same as {@link
|
||||||
* #getBufferedPosition()} because content buffered position isn't available.
|
* #getBufferedPosition()} because content buffered position isn't available.
|
||||||
*/
|
*/
|
||||||
@ -950,7 +953,7 @@ public class MediaController implements Player {
|
|||||||
* <p>A command is not accepted if it is not a custom command or the command is not in the list of
|
* <p>A command is not accepted if it is not a custom command or the command is not in the list of
|
||||||
* {@linkplain #getAvailableSessionCommands() available session commands}.
|
* {@linkplain #getAvailableSessionCommands() available session commands}.
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, {@link SessionResult#resultCode} will
|
* android.support.v4.media.session.MediaSessionCompat}, {@link SessionResult#resultCode} will
|
||||||
* return the custom result code from the {@code android.os.ResultReceiver#onReceiveResult(int,
|
* return the custom result code from the {@code android.os.ResultReceiver#onReceiveResult(int,
|
||||||
* Bundle)} instead of the standard result codes defined in the {@link SessionResult}.
|
* Bundle)} instead of the standard result codes defined in the {@link SessionResult}.
|
||||||
@ -1345,7 +1348,7 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, this will always return {@link
|
* android.support.v4.media.session.MediaSessionCompat}, this will always return {@link
|
||||||
* C#INDEX_UNSET} even when {@link #hasPreviousMediaItem()} is {@code true}.
|
* C#INDEX_UNSET} even when {@link #hasPreviousMediaItem()} is {@code true}.
|
||||||
*/
|
*/
|
||||||
@ -1368,7 +1371,7 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, this will always return {@link
|
* android.support.v4.media.session.MediaSessionCompat}, this will always return {@link
|
||||||
* C#INDEX_UNSET} even when {@link #hasNextMediaItem()} is {@code true}.
|
* C#INDEX_UNSET} even when {@link #hasNextMediaItem()} is {@code true}.
|
||||||
*/
|
*/
|
||||||
@ -1463,7 +1466,7 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, it's the same as {@link #seekToPrevious}.
|
* android.support.v4.media.session.MediaSessionCompat}, it's the same as {@link #seekToPrevious}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -1489,7 +1492,7 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, it's the same as {@link #seekToNext}.
|
* android.support.v4.media.session.MediaSessionCompat}, it's the same as {@link #seekToNext}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -1505,7 +1508,7 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, it won't update the current media item
|
* android.support.v4.media.session.MediaSessionCompat}, it won't update the current media item
|
||||||
* index immediately because the previous media item index is unknown.
|
* index immediately because the previous media item index is unknown.
|
||||||
*/
|
*/
|
||||||
@ -1522,7 +1525,7 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, it always returns {@code 0}.
|
* android.support.v4.media.session.MediaSessionCompat}, it always returns {@code 0}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -1534,7 +1537,7 @@ public class MediaController implements Player {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*
|
*
|
||||||
* <p>Interoperability: When connected to {@link
|
* <p>Interoperability: When connected to {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat}, it won't update the current media item
|
* android.support.v4.media.session.MediaSessionCompat}, it won't update the current media item
|
||||||
* index immediately because the previous media item index is unknown.
|
* index immediately because the previous media item index is unknown.
|
||||||
*/
|
*/
|
||||||
|
@ -30,7 +30,6 @@ import android.os.Bundle;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import androidx.annotation.IntRange;
|
import androidx.annotation.IntRange;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media.MediaSessionManager.RemoteUserInfo;
|
|
||||||
import androidx.media3.common.Bundleable;
|
import androidx.media3.common.Bundleable;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
import androidx.media3.common.MediaMetadata;
|
import androidx.media3.common.MediaMetadata;
|
||||||
@ -63,7 +62,7 @@ import java.util.List;
|
|||||||
* }</pre>
|
* }</pre>
|
||||||
*
|
*
|
||||||
* <p>You may also declare {@code android.media.browse.MediaBrowserService} for compatibility with
|
* <p>You may also declare {@code android.media.browse.MediaBrowserService} for compatibility with
|
||||||
* {@link android.support.v4.media.MediaBrowserCompat} so that this service can handle the case.
|
* {@code android.support.v4.media.MediaBrowserCompat} so that this service can handle the case.
|
||||||
*
|
*
|
||||||
* @see MediaSessionService
|
* @see MediaSessionService
|
||||||
*/
|
*/
|
||||||
@ -78,7 +77,7 @@ public abstract class MediaLibraryService extends MediaSessionService {
|
|||||||
*
|
*
|
||||||
* <h2 id="BackwardCompatibility">Backward compatibility with legacy media browser APIs</h2>
|
* <h2 id="BackwardCompatibility">Backward compatibility with legacy media browser APIs</h2>
|
||||||
*
|
*
|
||||||
* <p>A library session supports connection from both {@link MediaBrowser} and {@link
|
* <p>A library session supports connection from both {@link MediaBrowser} and {@code
|
||||||
* android.support.v4.media.MediaBrowserCompat}, but the {@link ControllerInfo} may not be
|
* android.support.v4.media.MediaBrowserCompat}, but the {@link ControllerInfo} may not be
|
||||||
* precise. Here are the details.
|
* precise. Here are the details.
|
||||||
*
|
*
|
||||||
@ -107,7 +106,7 @@ public abstract class MediaLibraryService extends MediaSessionService {
|
|||||||
* {@code 21 <= SDK_INT < 28}<br>
|
* {@code 21 <= SDK_INT < 28}<br>
|
||||||
* for other {@link Callback callbacks}
|
* for other {@link Callback callbacks}
|
||||||
* </td>
|
* </td>
|
||||||
* <td>{@link RemoteUserInfo#LEGACY_CONTROLLER}</td>
|
* <td>{@link ControllerInfo#LEGACY_CONTROLLER_PACKAGE_NAME}</td>
|
||||||
* <td>Negative value</td>
|
* <td>Negative value</td>
|
||||||
* </tr>
|
* </tr>
|
||||||
* <tr>
|
* <tr>
|
||||||
@ -144,10 +143,10 @@ public abstract class MediaLibraryService extends MediaSessionService {
|
|||||||
* MediaItem#mediaId}. The media id is required for the browser to get the children under the
|
* MediaItem#mediaId}. The media id is required for the browser to get the children under the
|
||||||
* root.
|
* root.
|
||||||
*
|
*
|
||||||
* <p>Interoperability: If this callback is called because a legacy {@link
|
* <p>Interoperability: If this callback is called because a legacy {@code
|
||||||
* android.support.v4.media.MediaBrowserCompat} has requested a {@link
|
* android.support.v4.media.MediaBrowserCompat} has requested a {@code
|
||||||
* androidx.media.MediaBrowserServiceCompat.BrowserRoot}, then the main thread may be blocked
|
* androidx.media.MediaBrowserServiceCompat.BrowserRoot}, then the main thread may be blocked
|
||||||
* until the returned future is done. If your service may be queried by a legacy {@link
|
* until the returned future is done. If your service may be queried by a legacy {@code
|
||||||
* android.support.v4.media.MediaBrowserCompat}, you should ensure that the future completes
|
* android.support.v4.media.MediaBrowserCompat}, you should ensure that the future completes
|
||||||
* quickly to avoid blocking the main thread for a long period of time.
|
* quickly to avoid blocking the main thread for a long period of time.
|
||||||
*
|
*
|
||||||
@ -246,8 +245,8 @@ public abstract class MediaLibraryService extends MediaSessionService {
|
|||||||
* <p>The {@link LibraryResult#params} returned to the caller should be the same as the {@link
|
* <p>The {@link LibraryResult#params} returned to the caller should be the same as the {@link
|
||||||
* LibraryParams params} passed into this method.
|
* LibraryParams params} passed into this method.
|
||||||
*
|
*
|
||||||
* <p>Interoperability: This will be called by {@link
|
* <p>Interoperability: This will be called by {@code
|
||||||
* android.support.v4.media.MediaBrowserCompat#subscribe}, but won't be called by {@link
|
* android.support.v4.media.MediaBrowserCompat.subscribe()}, but won't be called by {@link
|
||||||
* android.media.browse.MediaBrowser#subscribe}.
|
* android.media.browse.MediaBrowser#subscribe}.
|
||||||
*
|
*
|
||||||
* @param session The session for this event.
|
* @param session The session for this event.
|
||||||
@ -300,8 +299,8 @@ public abstract class MediaLibraryService extends MediaSessionService {
|
|||||||
* #getSubscribedControllers(String)} to get subscribed controllers for which to call {@link
|
* #getSubscribedControllers(String)} to get subscribed controllers for which to call {@link
|
||||||
* #notifyChildrenChanged}.
|
* #notifyChildrenChanged}.
|
||||||
*
|
*
|
||||||
* <p>Interoperability: This will be called by {@link
|
* <p>Interoperability: This will be called by {@code
|
||||||
* android.support.v4.media.MediaBrowserCompat#unsubscribe}, but won't be called by {@link
|
* android.support.v4.media.MediaBrowserCompat.unsubscribe()}, but won't be called by {@link
|
||||||
* android.media.browse.MediaBrowser#unsubscribe}.
|
* android.media.browse.MediaBrowser#unsubscribe}.
|
||||||
*
|
*
|
||||||
* @param session The session for this event.
|
* @param session The session for this event.
|
||||||
@ -363,8 +362,8 @@ public abstract class MediaLibraryService extends MediaSessionService {
|
|||||||
* list for no children rather than using error codes.
|
* list for no children rather than using error codes.
|
||||||
*
|
*
|
||||||
* <p>Typically, the {@code query} is requested through {@link #onSearch(MediaLibrarySession,
|
* <p>Typically, the {@code query} is requested through {@link #onSearch(MediaLibrarySession,
|
||||||
* ControllerInfo, String, LibraryParams)} before, but it may not especially when {@link
|
* ControllerInfo, String, LibraryParams)} before, but it may not especially when {@code
|
||||||
* android.support.v4.media.MediaBrowserCompat#search} is used.
|
* android.support.v4.media.MediaBrowserCompat.search()} is used.
|
||||||
*
|
*
|
||||||
* @param session The session for this event.
|
* @param session The session for this event.
|
||||||
* @param browser The browser information.
|
* @param browser The browser information.
|
||||||
|
@ -211,17 +211,17 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
*
|
*
|
||||||
* <h2 id="BackwardCompatibility">Backward Compatibility with Legacy Session APIs</h2>
|
* <h2 id="BackwardCompatibility">Backward Compatibility with Legacy Session APIs</h2>
|
||||||
*
|
*
|
||||||
* <p>An active {@link MediaSessionCompat} is internally created with the session for backwards
|
* <p>An active {@code android.support.v4.media.session.MediaSessionCompat} is internally created
|
||||||
* compatibility. It's used to handle incoming connections and commands from {@link
|
* with the session for backwards compatibility. It's used to handle incoming connections and
|
||||||
* MediaControllerCompat} instances, and helps to utilize existing APIs that are built with legacy
|
* commands from {@code android.support.v4.media.session.MediaControllerCompat} instances, and helps
|
||||||
* media session APIs.
|
* to utilize existing APIs that are built with legacy media session APIs.
|
||||||
*
|
*
|
||||||
* <h2 id="CompatibilityController">Backward Compatibility with Legacy Controller APIs</h2>
|
* <h2 id="CompatibilityController">Backward Compatibility with Legacy Controller APIs</h2>
|
||||||
*
|
*
|
||||||
* <p>In addition to {@link MediaController}, the session also supports connections from the legacy
|
* <p>In addition to {@link MediaController}, the session also supports connections from the legacy
|
||||||
* controller APIs - {@linkplain android.media.session.MediaController framework controller} and
|
* controller APIs - {@link android.media.session.MediaController} and {@code
|
||||||
* {@linkplain MediaControllerCompat AndroidX controller compat}. However, {@link ControllerInfo}
|
* android.support.v4.media.session.MediaControllerCompat}. However, {@link ControllerInfo} may not
|
||||||
* may not be precise for legacy controllers. See {@link ControllerInfo} for the details.
|
* be precise for legacy controllers. See {@link ControllerInfo} for the details.
|
||||||
*
|
*
|
||||||
* <p>Neither an unknown package name nor an unknown UID mean that you should disallow a connection
|
* <p>Neither an unknown package name nor an unknown UID mean that you should disallow a connection
|
||||||
* or commands per se. For SDK levels where such issues happen, session tokens can only be obtained
|
* or commands per se. For SDK levels where such issues happen, session tokens can only be obtained
|
||||||
@ -466,6 +466,12 @@ public class MediaSession {
|
|||||||
/** The {@linkplain #getInterfaceVersion()} interface version} of legacy controllers. */
|
/** The {@linkplain #getInterfaceVersion()} interface version} of legacy controllers. */
|
||||||
@UnstableApi public static final int LEGACY_CONTROLLER_INTERFACE_VERSION = 0;
|
@UnstableApi public static final int LEGACY_CONTROLLER_INTERFACE_VERSION = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link #getPackageName()} of legacy controllers if a more precise package cannot be
|
||||||
|
* obtained.
|
||||||
|
*/
|
||||||
|
public static final String LEGACY_CONTROLLER_PACKAGE_NAME = RemoteUserInfo.LEGACY_CONTROLLER;
|
||||||
|
|
||||||
private final RemoteUserInfo remoteUserInfo;
|
private final RemoteUserInfo remoteUserInfo;
|
||||||
private final int libraryVersion;
|
private final int libraryVersion;
|
||||||
private final int interfaceVersion;
|
private final int interfaceVersion;
|
||||||
@ -478,9 +484,10 @@ public class MediaSession {
|
|||||||
*
|
*
|
||||||
* @param remoteUserInfo The remote user info.
|
* @param remoteUserInfo The remote user info.
|
||||||
* @param trusted {@code true} if trusted, {@code false} otherwise.
|
* @param trusted {@code true} if trusted, {@code false} otherwise.
|
||||||
* @param cb ControllerCb. Can be {@code null} only when a MediaBrowserCompat connects to
|
* @param cb ControllerCb. Can be {@code null} only when a {@code
|
||||||
* MediaSessionService and ControllerInfo is needed for {@link
|
* android.support.v4.media.MediaBrowserCompat} connects to {@link MediaSessionService} and
|
||||||
* MediaSession.Callback#onConnect(MediaSession, ControllerInfo)}.
|
* {@link ControllerInfo} is needed for {@link MediaSession.Callback#onConnect(MediaSession,
|
||||||
|
* ControllerInfo)}.
|
||||||
* @param connectionHints A session-specific argument sent from the controller for the
|
* @param connectionHints A session-specific argument sent from the controller for the
|
||||||
* connection. The contents of this bundle may affect the connection result.
|
* connection. The contents of this bundle may affect the connection result.
|
||||||
*/
|
*/
|
||||||
@ -520,7 +527,7 @@ public class MediaSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the package name. Can be {@link RemoteUserInfo#LEGACY_CONTROLLER} for
|
* Returns the package name. Can be {@link #LEGACY_CONTROLLER_PACKAGE_NAME} for
|
||||||
* interoperability.
|
* interoperability.
|
||||||
*
|
*
|
||||||
* <p>Interoperability: Package name may not be precisely obtained for legacy controller API on
|
* <p>Interoperability: Package name may not be precisely obtained for legacy controller API on
|
||||||
@ -535,7 +542,7 @@ public class MediaSession {
|
|||||||
* It's sufficient for most cases, but doesn't precisely distinguish caller if it
|
* It's sufficient for most cases, but doesn't precisely distinguish caller if it
|
||||||
* uses shared user ID.</td>
|
* uses shared user ID.</td>
|
||||||
* <tr><td>{@code 21 <= SDK_INT < 24}</td>
|
* <tr><td>{@code 21 <= SDK_INT < 24}</td>
|
||||||
* <td>{@link RemoteUserInfo#LEGACY_CONTROLLER}</td>
|
* <td>{@link #LEGACY_CONTROLLER_PACKAGE_NAME}</td>
|
||||||
* </table>
|
* </table>
|
||||||
*/
|
*/
|
||||||
public String getPackageName() {
|
public String getPackageName() {
|
||||||
@ -616,16 +623,40 @@ public class MediaSession {
|
|||||||
/* connectionHints= */ Bundle.EMPTY);
|
/* connectionHints= */ Bundle.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a {@link ControllerInfo} suitable for use when testing client code. */
|
/**
|
||||||
|
* @deprecated Use {@link #createTestOnlyControllerInfo(String, int, int, int, int, boolean,
|
||||||
|
* Bundle)} instead.
|
||||||
|
*/
|
||||||
@VisibleForTesting(otherwise = PRIVATE)
|
@VisibleForTesting(otherwise = PRIVATE)
|
||||||
|
@Deprecated
|
||||||
public static ControllerInfo createTestOnlyControllerInfo(
|
public static ControllerInfo createTestOnlyControllerInfo(
|
||||||
RemoteUserInfo remoteUserInfo,
|
RemoteUserInfo remoteUserInfo,
|
||||||
int libraryVersion,
|
int libraryVersion,
|
||||||
int interfaceVersion,
|
int interfaceVersion,
|
||||||
boolean trusted,
|
boolean trusted,
|
||||||
Bundle connectionHints) {
|
Bundle connectionHints) {
|
||||||
|
return createTestOnlyControllerInfo(
|
||||||
|
remoteUserInfo.getPackageName(),
|
||||||
|
remoteUserInfo.getPid(),
|
||||||
|
remoteUserInfo.getUid(),
|
||||||
|
libraryVersion,
|
||||||
|
interfaceVersion,
|
||||||
|
trusted,
|
||||||
|
connectionHints);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns a {@link ControllerInfo} suitable for use when testing client code. */
|
||||||
|
@VisibleForTesting(otherwise = PRIVATE)
|
||||||
|
public static ControllerInfo createTestOnlyControllerInfo(
|
||||||
|
String packageName,
|
||||||
|
int pid,
|
||||||
|
int uid,
|
||||||
|
int libraryVersion,
|
||||||
|
int interfaceVersion,
|
||||||
|
boolean trusted,
|
||||||
|
Bundle connectionHints) {
|
||||||
return new MediaSession.ControllerInfo(
|
return new MediaSession.ControllerInfo(
|
||||||
remoteUserInfo,
|
new RemoteUserInfo(packageName, pid, uid),
|
||||||
libraryVersion,
|
libraryVersion,
|
||||||
interfaceVersion,
|
interfaceVersion,
|
||||||
trusted,
|
trusted,
|
||||||
@ -1111,8 +1142,8 @@ public class MediaSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link MediaSessionCompat.Token} of the {@link MediaSessionCompat} created
|
* Returns the legacy {@code android.support.v4.media.session.MediaSessionCompat.Token} of the
|
||||||
* internally by this session.
|
* {@code android.support.v4.media.session.MediaSessionCompat} created internally by this session.
|
||||||
*/
|
*/
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public final MediaSessionCompat.Token getSessionCompatToken() {
|
public final MediaSessionCompat.Token getSessionCompatToken() {
|
||||||
@ -1309,9 +1340,9 @@ public class MediaSession {
|
|||||||
* been added to the {@link MediaSession.ConnectionResult#availableSessionCommands list of
|
* been added to the {@link MediaSession.ConnectionResult#availableSessionCommands list of
|
||||||
* available session commands} in {@link #onConnect} or set via {@link #setAvailableCommands}.
|
* available session commands} in {@link #onConnect} or set via {@link #setAvailableCommands}.
|
||||||
*
|
*
|
||||||
* <p>Interoperability: This will be also called by {@link
|
* <p>Interoperability: This will be also called by {@code
|
||||||
* android.support.v4.media.MediaBrowserCompat#sendCustomAction}. If so, {@code extras} from
|
* android.support.v4.media.MediaBrowserCompat.sendCustomAction()}. If so, {@code extras} from
|
||||||
* {@link android.support.v4.media.MediaBrowserCompat#sendCustomAction} will be considered as
|
* {@code android.support.v4.media.MediaBrowserCompat.sendCustomAction()} will be considered as
|
||||||
* {@code args} and the custom command will have {@code null} {@link
|
* {@code args} and the custom command will have {@code null} {@link
|
||||||
* SessionCommand#customExtras}.
|
* SessionCommand#customExtras}.
|
||||||
*
|
*
|
||||||
@ -1340,9 +1371,10 @@ public class MediaSession {
|
|||||||
* Callback#onSetMediaItems} will direct {@code Player.setMediaItem(s)} to this method as well.
|
* Callback#onSetMediaItems} will direct {@code Player.setMediaItem(s)} to this method as well.
|
||||||
*
|
*
|
||||||
* <p>In addition, unless {@link Callback#onSetMediaItems} is overridden, this callback is also
|
* <p>In addition, unless {@link Callback#onSetMediaItems} is overridden, this callback is also
|
||||||
* called when an app is using a legacy {@link MediaControllerCompat.TransportControls} to
|
* called when an app is using a legacy {@link
|
||||||
* prepare or play media (for instance when browsing the catalogue and then selecting an item
|
* android.support.v4.media.session.MediaControllerCompat.TransportControls} to prepare or play
|
||||||
* for preparation from Android Auto that is using the legacy Media1 library).
|
* media (for instance when browsing the catalogue and then selecting an item for preparation
|
||||||
|
* from Android Auto that is using the legacy Media1 library).
|
||||||
*
|
*
|
||||||
* <p>By default, if and only if each of the provided {@linkplain MediaItem media items} has a
|
* <p>By default, if and only if each of the provided {@linkplain MediaItem media items} has a
|
||||||
* set {@link MediaItem.LocalConfiguration} (for example, a URI), then the callback returns the
|
* set {@link MediaItem.LocalConfiguration} (for example, a URI), then the callback returns the
|
||||||
@ -1361,16 +1393,17 @@ public class MediaSession {
|
|||||||
* Player#setMediaItems} or {@link Player#addMediaItems} as requested.
|
* Player#setMediaItems} or {@link Player#addMediaItems} as requested.
|
||||||
*
|
*
|
||||||
* <p>Interoperability: This method will be called, unless {@link Callback#onSetMediaItems} is
|
* <p>Interoperability: This method will be called, unless {@link Callback#onSetMediaItems} is
|
||||||
* overridden, in response to the following {@link MediaControllerCompat} methods:
|
* overridden, in response to the following {@link
|
||||||
|
* android.support.v4.media.session.MediaControllerCompat} methods:
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link MediaControllerCompat.TransportControls#prepareFromUri prepareFromUri}
|
* <li>{@code prepareFromUri}
|
||||||
* <li>{@link MediaControllerCompat.TransportControls#playFromUri playFromUri}
|
* <li>{@code playFromUri}
|
||||||
* <li>{@link MediaControllerCompat.TransportControls#prepareFromMediaId prepareFromMediaId}
|
* <li>{@code prepareFromMediaId}
|
||||||
* <li>{@link MediaControllerCompat.TransportControls#playFromMediaId playFromMediaId}
|
* <li>{@code playFromMediaId}
|
||||||
* <li>{@link MediaControllerCompat.TransportControls#prepareFromSearch prepareFromSearch}
|
* <li>{@code prepareFromSearch}
|
||||||
* <li>{@link MediaControllerCompat.TransportControls#playFromSearch playFromSearch}
|
* <li>{@code playFromSearch}
|
||||||
* <li>{@link MediaControllerCompat#addQueueItem addQueueItem}
|
* <li>{@code addQueueItem}
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* The values of {@link MediaItem#mediaId}, {@link MediaItem.RequestMetadata#mediaUri}, {@link
|
* The values of {@link MediaItem#mediaId}, {@link MediaItem.RequestMetadata#mediaUri}, {@link
|
||||||
|
@ -77,7 +77,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
* }</pre>
|
* }</pre>
|
||||||
*
|
*
|
||||||
* <p>You may also declare the action {@code android.media.browse.MediaBrowserService} for
|
* <p>You may also declare the action {@code android.media.browse.MediaBrowserService} for
|
||||||
* compatibility with {@link android.support.v4.media.MediaBrowserCompat}. This service can handle
|
* compatibility with {@code android.support.v4.media.MediaBrowserCompat}. This service can handle
|
||||||
* the case automatically.
|
* the case automatically.
|
||||||
*
|
*
|
||||||
* <p>It's recommended for an app to have a single service declared in the manifest. Otherwise, your
|
* <p>It's recommended for an app to have a single service declared in the manifest. Otherwise, your
|
||||||
@ -227,10 +227,10 @@ public abstract class MediaSessionService extends Service {
|
|||||||
* <li>When the service is started by a media button event, the package name will be {@link
|
* <li>When the service is started by a media button event, the package name will be {@link
|
||||||
* Intent#ACTION_MEDIA_BUTTON}. If you want to allow the service to be started by media
|
* Intent#ACTION_MEDIA_BUTTON}. If you want to allow the service to be started by media
|
||||||
* button events, do not return {@code null}.
|
* button events, do not return {@code null}.
|
||||||
* <li>When a legacy {@link android.media.browse.MediaBrowser} or a {@link
|
* <li>When a legacy {@link android.media.browse.MediaBrowser} or a {@code
|
||||||
* android.support.v4.media.MediaBrowserCompat} tries to connect, the package name will be
|
* android.support.v4.media.MediaBrowserCompat} tries to connect, the package name will be
|
||||||
* {@link MediaBrowserServiceCompat#SERVICE_INTERFACE}. If you want to allow the service to
|
* {@link android.service.media.MediaBrowserService#SERVICE_INTERFACE}. If you want to allow
|
||||||
* be bound by the legacy media browsers, do not return {@code null}.
|
* the service to be bound by the legacy media browsers, do not return {@code null}.
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* <p>For those special cases, the values returned by {@link ControllerInfo#getUid()} and {@link
|
* <p>For those special cases, the values returned by {@link ControllerInfo#getUid()} and {@link
|
||||||
|
@ -32,7 +32,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of {@link MediaBrowserServiceCompat} for interoperability between {@link
|
* Implementation of {@link MediaBrowserServiceCompat} for interoperability between {@link
|
||||||
* MediaLibraryService} and {@link android.support.v4.media.MediaBrowserCompat}.
|
* MediaLibraryService} and {@code android.support.v4.media.MediaBrowserCompat}.
|
||||||
*/
|
*/
|
||||||
/* package */ class MediaSessionServiceLegacyStub extends MediaBrowserServiceCompat {
|
/* package */ class MediaSessionServiceLegacyStub extends MediaBrowserServiceCompat {
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public class MediaStyleNotificationHelper {
|
|||||||
*
|
*
|
||||||
* <pre class="prettyprint">
|
* <pre class="prettyprint">
|
||||||
* Notification noti = new NotificationCompat.Builder()
|
* Notification noti = new NotificationCompat.Builder()
|
||||||
* .setSmallIcon(androidx.media.R.drawable.ic_stat_player)
|
* .setSmallIcon(androidx.media3.R.drawable.media3_notification_small_icon)
|
||||||
* .setContentTitle("Track title")
|
* .setContentTitle("Track title")
|
||||||
* .setContentText("Artist - Album")
|
* .setContentText("Artist - Album")
|
||||||
* .setLargeIcon(albumArtBitmap)
|
* .setLargeIcon(albumArtBitmap)
|
||||||
@ -386,7 +386,7 @@ public class MediaStyleNotificationHelper {
|
|||||||
*
|
*
|
||||||
* <pre class="prettyprint">
|
* <pre class="prettyprint">
|
||||||
* Notification noti = new NotificationCompat.Builder()
|
* Notification noti = new NotificationCompat.Builder()
|
||||||
* .setSmallIcon(androidx.media.R.drawable.ic_stat_player)
|
* .setSmallIcon(androidx.media3.R.drawable.media3_notification_small_icon)
|
||||||
* .setLargeIcon(albumArtBitmap))
|
* .setLargeIcon(albumArtBitmap))
|
||||||
* .setCustomContentView(contentView)
|
* .setCustomContentView(contentView)
|
||||||
* .setStyle(<b>new NotificationCompat.DecoratedMediaCustomViewStyle()</b>
|
* .setStyle(<b>new NotificationCompat.DecoratedMediaCustomViewStyle()</b>
|
||||||
@ -566,7 +566,7 @@ public class MediaStyleNotificationHelper {
|
|||||||
if (actionsToShowInCompact != null) {
|
if (actionsToShowInCompact != null) {
|
||||||
setShowActionsInCompactView(style, actionsToShowInCompact);
|
setShowActionsInCompactView(style, actionsToShowInCompact);
|
||||||
}
|
}
|
||||||
MediaSessionCompat.Token legacyToken = session.getSessionCompatToken();
|
MediaSessionCompat.Token legacyToken = session.getSessionCompat().getSessionToken();
|
||||||
style.setMediaSession((android.media.session.MediaSession.Token) legacyToken.getToken());
|
style.setMediaSession((android.media.session.MediaSession.Token) legacyToken.getToken());
|
||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
@ -124,8 +124,8 @@ public final class SessionCommand implements Bundleable {
|
|||||||
/**
|
/**
|
||||||
* The extra bundle of a custom command. It will be {@link Bundle#EMPTY} for a predefined command.
|
* The extra bundle of a custom command. It will be {@link Bundle#EMPTY} for a predefined command.
|
||||||
*
|
*
|
||||||
* <p>Interoperability: This value is not used when the command is sent to a legacy {@link
|
* <p>Interoperability: This value is not used when the command is sent to a legacy {@code
|
||||||
* android.support.v4.media.session.MediaSessionCompat} or {@link
|
* android.support.v4.media.session.MediaSessionCompat} or {@code
|
||||||
* android.support.v4.media.session.MediaControllerCompat}.
|
* android.support.v4.media.session.MediaControllerCompat}.
|
||||||
*/
|
*/
|
||||||
public final Bundle customExtras;
|
public final Bundle customExtras;
|
||||||
@ -148,7 +148,7 @@ public final class SessionCommand implements Bundleable {
|
|||||||
*
|
*
|
||||||
* @param action The action of this custom command.
|
* @param action The action of this custom command.
|
||||||
* @param extras An extra bundle for this custom command. This value is not used when the command
|
* @param extras An extra bundle for this custom command. This value is not used when the command
|
||||||
* is sent to a legacy {@link android.support.v4.media.session.MediaSessionCompat} or {@link
|
* is sent to a legacy {@code android.support.v4.media.session.MediaSessionCompat} or {@code
|
||||||
* android.support.v4.media.session.MediaControllerCompat}.
|
* android.support.v4.media.session.MediaControllerCompat}.
|
||||||
*/
|
*/
|
||||||
public SessionCommand(String action, Bundle extras) {
|
public SessionCommand(String action, Bundle extras) {
|
||||||
|
@ -19,8 +19,6 @@ import static java.lang.annotation.ElementType.TYPE_USE;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.support.v4.media.session.MediaControllerCompat;
|
|
||||||
import android.support.v4.media.session.MediaSessionCompat;
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.Bundleable;
|
import androidx.media3.common.Bundleable;
|
||||||
@ -81,8 +79,9 @@ public final class SessionResult implements Bundleable {
|
|||||||
* Result code representing that the command is successfully completed.
|
* Result code representing that the command is successfully completed.
|
||||||
*
|
*
|
||||||
* <p>Interoperability: This code is also used to tell that the command was successfully sent, but
|
* <p>Interoperability: This code is also used to tell that the command was successfully sent, but
|
||||||
* the result is unknown when connected with {@link MediaSessionCompat} or {@link
|
* the result is unknown when connected with {@code
|
||||||
* MediaControllerCompat}.
|
* android.support.v4.media.session.MediaSessionCompat} or {@code
|
||||||
|
* android.support.v4.media.session.MediaControllerCompat}.
|
||||||
*/
|
*/
|
||||||
public static final int RESULT_SUCCESS = 0;
|
public static final int RESULT_SUCCESS = 0;
|
||||||
|
|
||||||
|
@ -55,8 +55,8 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A token that represents an ongoing {@link MediaSession} or a service ({@link
|
* A token that represents an ongoing {@link MediaSession} or a service ({@link
|
||||||
* MediaSessionService}, {@link MediaLibraryService}, or {@link MediaBrowserServiceCompat}). If it
|
* MediaSessionService}, {@link MediaLibraryService}, or {@code
|
||||||
* represents a service, it may not be ongoing.
|
* androix.media.MediaBrowserServiceCompat}). If it represents a service, it may not be ongoing.
|
||||||
*
|
*
|
||||||
* <p>This may be passed to apps by the session owner to allow them to create a {@link
|
* <p>This may be passed to apps by the session owner to allow them to create a {@link
|
||||||
* MediaController} or a {@link MediaBrowser} to communicate with the session.
|
* MediaController} or a {@link MediaBrowser} to communicate with the session.
|
||||||
@ -93,14 +93,15 @@ public final class SessionToken implements Bundleable {
|
|||||||
/** Type for {@link MediaSessionCompat}. */
|
/** Type for {@link MediaSessionCompat}. */
|
||||||
/* package */ static final int TYPE_SESSION_LEGACY = 100;
|
/* package */ static final int TYPE_SESSION_LEGACY = 100;
|
||||||
|
|
||||||
/** Type for {@link MediaBrowserServiceCompat}. */
|
/** Type for {@code androidx.media.MediaBrowserServiceCompat}. */
|
||||||
/* package */ static final int TYPE_BROWSER_SERVICE_LEGACY = 101;
|
/* package */ static final int TYPE_BROWSER_SERVICE_LEGACY = 101;
|
||||||
|
|
||||||
private final SessionTokenImpl impl;
|
private final SessionTokenImpl impl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a token for {@link MediaController} or {@link MediaBrowser} to connect to one of {@link
|
* Creates a token for {@link MediaController} or {@link MediaBrowser} to connect to one of {@link
|
||||||
* MediaSessionService}, {@link MediaLibraryService}, or {@link MediaBrowserServiceCompat}.
|
* MediaSessionService}, {@link MediaLibraryService}, or {@code
|
||||||
|
* androidx.media.MediaBrowserServiceCompat}.
|
||||||
*
|
*
|
||||||
* @param context The context.
|
* @param context The context.
|
||||||
* @param serviceComponent The component name of the service.
|
* @param serviceComponent The component name of the service.
|
||||||
@ -294,15 +295,16 @@ public final class SessionToken implements Bundleable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a token from a {@link MediaSessionCompat.Token}.
|
* Creates a token from a {@link android.support.v4.media.session.MediaSessionCompat.Token}.
|
||||||
*
|
*
|
||||||
* @param context A {@link Context}.
|
* @param context A {@link Context}.
|
||||||
* @param compatToken The {@link MediaSessionCompat.Token}.
|
* @param compatToken The {@code android.support.v4.media.session.MediaSessionCompat.Token}.
|
||||||
* @return A {@link ListenableFuture} for the {@link SessionToken}.
|
* @return A {@link ListenableFuture} for the {@link SessionToken}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("UnnecessarilyFullyQualified") // Avoiding clash with Media3 MediaSession.
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public static ListenableFuture<SessionToken> createSessionToken(
|
public static ListenableFuture<SessionToken> createSessionToken(
|
||||||
Context context, MediaSessionCompat.Token compatToken) {
|
Context context, android.support.v4.media.session.MediaSessionCompat.Token compatToken) {
|
||||||
HandlerThread thread = new HandlerThread("SessionTokenThread");
|
HandlerThread thread = new HandlerThread("SessionTokenThread");
|
||||||
thread.start();
|
thread.start();
|
||||||
ListenableFuture<SessionToken> tokenFuture =
|
ListenableFuture<SessionToken> tokenFuture =
|
||||||
@ -312,18 +314,21 @@ public final class SessionToken implements Bundleable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a token from a {@link MediaSessionCompat.Token}.
|
* Creates a token from a {@link android.support.v4.media.session.MediaSessionCompat.Token}.
|
||||||
*
|
*
|
||||||
* @param context A {@link Context}.
|
* @param context A {@link Context}.
|
||||||
* @param compatToken The {@link MediaSessionCompat.Token}.
|
* @param compatToken The {@link android.support.v4.media.session.MediaSessionCompat.Token}.
|
||||||
* @param completionLooper The {@link Looper} on which the returned {@link ListenableFuture}
|
* @param completionLooper The {@link Looper} on which the returned {@link ListenableFuture}
|
||||||
* completes. This {@link Looper} can't be used to call {@code future.get()} on the returned
|
* completes. This {@link Looper} can't be used to call {@code future.get()} on the returned
|
||||||
* {@link ListenableFuture}.
|
* {@link ListenableFuture}.
|
||||||
* @return A {@link ListenableFuture} for the {@link SessionToken}.
|
* @return A {@link ListenableFuture} for the {@link SessionToken}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("UnnecessarilyFullyQualified") // Avoiding clash with Media3 MediaSession.
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public static ListenableFuture<SessionToken> createSessionToken(
|
public static ListenableFuture<SessionToken> createSessionToken(
|
||||||
Context context, MediaSessionCompat.Token compatToken, Looper completionLooper) {
|
Context context,
|
||||||
|
android.support.v4.media.session.MediaSessionCompat.Token compatToken,
|
||||||
|
Looper completionLooper) {
|
||||||
checkNotNull(context, "context must not be null");
|
checkNotNull(context, "context must not be null");
|
||||||
checkNotNull(compatToken, "compatToken must not be null");
|
checkNotNull(compatToken, "compatToken must not be null");
|
||||||
|
|
||||||
@ -364,7 +369,7 @@ public final class SessionToken implements Bundleable {
|
|||||||
/**
|
/**
|
||||||
* Returns an {@link ImmutableSet} of {@linkplain SessionToken session tokens} for media session
|
* Returns an {@link ImmutableSet} of {@linkplain SessionToken session tokens} for media session
|
||||||
* services; {@link MediaSessionService}, {@link MediaLibraryService}, and {@link
|
* services; {@link MediaSessionService}, {@link MediaLibraryService}, and {@link
|
||||||
* MediaBrowserServiceCompat} regardless of their activeness.
|
* androidx.media.MediaBrowserServiceCompat} regardless of their activeness.
|
||||||
*
|
*
|
||||||
* <p>The app targeting API level 30 or higher must include a {@code <queries>} element in their
|
* <p>The app targeting API level 30 or higher must include a {@code <queries>} element in their
|
||||||
* manifest to get service tokens of other apps. See the following example and <a
|
* manifest to get service tokens of other apps. See the following example and <a
|
||||||
|
@ -19,14 +19,16 @@ import static android.support.v4.media.MediaBrowserCompat.MediaItem.FLAG_BROWSAB
|
|||||||
import static android.support.v4.media.MediaBrowserCompat.MediaItem.FLAG_PLAYABLE;
|
import static android.support.v4.media.MediaBrowserCompat.MediaItem.FLAG_PLAYABLE;
|
||||||
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_DURATION;
|
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_DURATION;
|
||||||
import static androidx.media.utils.MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS;
|
import static androidx.media.utils.MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS;
|
||||||
|
import static androidx.media3.session.MediaConstants.EXTRAS_KEY_COMMAND_BUTTON_ICON_COMPAT;
|
||||||
import static androidx.media3.session.MediaConstants.EXTRAS_KEY_MEDIA_TYPE_COMPAT;
|
import static androidx.media3.session.MediaConstants.EXTRAS_KEY_MEDIA_TYPE_COMPAT;
|
||||||
import static androidx.media3.session.MediaConstants.EXTRA_KEY_ROOT_CHILDREN_BROWSABLE_ONLY;
|
import static androidx.media3.session.MediaConstants.EXTRA_KEY_ROOT_CHILDREN_BROWSABLE_ONLY;
|
||||||
import static androidx.media3.test.session.common.TestUtils.getCommandsAsList;
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.service.media.MediaBrowserService;
|
import android.service.media.MediaBrowserService;
|
||||||
@ -41,7 +43,6 @@ import android.text.SpannedString;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media.AudioAttributesCompat;
|
import androidx.media.AudioAttributesCompat;
|
||||||
import androidx.media.VolumeProviderCompat;
|
import androidx.media.VolumeProviderCompat;
|
||||||
import androidx.media.utils.MediaConstants;
|
|
||||||
import androidx.media3.common.AudioAttributes;
|
import androidx.media3.common.AudioAttributes;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.HeartRating;
|
import androidx.media3.common.HeartRating;
|
||||||
@ -56,18 +57,18 @@ import androidx.media3.common.util.BitmapLoader;
|
|||||||
import androidx.media3.datasource.DataSourceBitmapLoader;
|
import androidx.media3.datasource.DataSourceBitmapLoader;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.filters.SdkSuppress;
|
|
||||||
import androidx.test.filters.SmallTest;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
/** Tests for {@link LegacyConversions}. */
|
/** Tests for {@link LegacyConversions}. */
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@SmallTest
|
|
||||||
public final class LegacyConversionsTest {
|
public final class LegacyConversionsTest {
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
@ -108,19 +109,30 @@ public final class LegacyConversionsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertBrowserItemListToMediaItemList() {
|
public void convertBrowserItemListToMediaItemList() {
|
||||||
int size = 3;
|
ImmutableList<MediaBrowserCompat.MediaItem> browserItems =
|
||||||
List<MediaBrowserCompat.MediaItem> browserItems = MediaTestUtils.createBrowserItems(size);
|
ImmutableList.of(
|
||||||
|
new MediaBrowserCompat.MediaItem(
|
||||||
|
new MediaDescriptionCompat.Builder().setMediaId("browserItem_1").build(),
|
||||||
|
/* flags= */ 0),
|
||||||
|
new MediaBrowserCompat.MediaItem(
|
||||||
|
new MediaDescriptionCompat.Builder().setMediaId("browserItem_2").build(),
|
||||||
|
/* flags= */ 0),
|
||||||
|
new MediaBrowserCompat.MediaItem(
|
||||||
|
new MediaDescriptionCompat.Builder().setMediaId("browserItem_3").build(),
|
||||||
|
/* flags= */ 0));
|
||||||
|
|
||||||
List<MediaItem> mediaItems =
|
List<MediaItem> mediaItems =
|
||||||
LegacyConversions.convertBrowserItemListToMediaItemList(browserItems);
|
LegacyConversions.convertBrowserItemListToMediaItemList(browserItems);
|
||||||
assertThat(mediaItems).hasSize(size);
|
|
||||||
for (int i = 0; i < size; ++i) {
|
assertThat(mediaItems).hasSize(3);
|
||||||
assertThat(mediaItems.get(i).mediaId).isEqualTo(browserItems.get(i).getMediaId());
|
assertThat(mediaItems.get(0).mediaId).isEqualTo(browserItems.get(0).getMediaId());
|
||||||
}
|
assertThat(mediaItems.get(1).mediaId).isEqualTo(browserItems.get(1).getMediaId());
|
||||||
|
assertThat(mediaItems.get(2).mediaId).isEqualTo(browserItems.get(2).getMediaId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void convertToQueueItem_withArtworkData() throws Exception {
|
public void convertToQueueItem_withArtworkData() throws Exception {
|
||||||
MediaItem mediaItem = MediaTestUtils.createMediaItemWithArtworkData("testId");
|
MediaItem mediaItem = createMediaItemWithArtworkData("testId");
|
||||||
MediaMetadata mediaMetadata = mediaItem.mediaMetadata;
|
MediaMetadata mediaMetadata = mediaItem.mediaMetadata;
|
||||||
ListenableFuture<Bitmap> bitmapFuture = bitmapLoader.decodeBitmap(mediaMetadata.artworkData);
|
ListenableFuture<Bitmap> bitmapFuture = bitmapLoader.decodeBitmap(mediaMetadata.artworkData);
|
||||||
@Nullable Bitmap bitmap = bitmapFuture.get(10, SECONDS);
|
@Nullable Bitmap bitmap = bitmapFuture.get(10, SECONDS);
|
||||||
@ -200,7 +212,7 @@ public final class LegacyConversionsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void convertToMediaMetadata_roundTripViaMediaMetadataCompat_returnsEqualMediaItemMetadata()
|
public void convertToMediaMetadata_roundTripViaMediaMetadataCompat_returnsEqualMediaItemMetadata()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
MediaItem testMediaItem = MediaTestUtils.createMediaItemWithArtworkData("testZZZ");
|
MediaItem testMediaItem = createMediaItemWithArtworkData("testZZZ");
|
||||||
MediaMetadata testMediaMetadata = testMediaItem.mediaMetadata;
|
MediaMetadata testMediaMetadata = testMediaItem.mediaMetadata;
|
||||||
@Nullable Bitmap testArtworkBitmap = null;
|
@Nullable Bitmap testArtworkBitmap = null;
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -227,7 +239,7 @@ public final class LegacyConversionsTest {
|
|||||||
public void
|
public void
|
||||||
convertToMediaMetadata_roundTripViaMediaDescriptionCompat_returnsEqualMediaItemMetadata()
|
convertToMediaMetadata_roundTripViaMediaDescriptionCompat_returnsEqualMediaItemMetadata()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
MediaItem testMediaItem = MediaTestUtils.createMediaItemWithArtworkData("testZZZ");
|
MediaItem testMediaItem = createMediaItemWithArtworkData("testZZZ");
|
||||||
MediaMetadata testMediaMetadata = testMediaItem.mediaMetadata;
|
MediaMetadata testMediaMetadata = testMediaItem.mediaMetadata;
|
||||||
@Nullable Bitmap testArtworkBitmap = null;
|
@Nullable Bitmap testArtworkBitmap = null;
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -375,8 +387,7 @@ public final class LegacyConversionsTest {
|
|||||||
assertThat(LegacyConversions.convertToLibraryParams(context, null)).isNull();
|
assertThat(LegacyConversions.convertToLibraryParams(context, null)).isNull();
|
||||||
Bundle rootHints = new Bundle();
|
Bundle rootHints = new Bundle();
|
||||||
rootHints.putString("key", "value");
|
rootHints.putString("key", "value");
|
||||||
rootHints.putInt(
|
rootHints.putInt(BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS, FLAG_BROWSABLE);
|
||||||
MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS, FLAG_BROWSABLE);
|
|
||||||
rootHints.putBoolean(MediaBrowserService.BrowserRoot.EXTRA_OFFLINE, true);
|
rootHints.putBoolean(MediaBrowserService.BrowserRoot.EXTRA_OFFLINE, true);
|
||||||
rootHints.putBoolean(MediaBrowserService.BrowserRoot.EXTRA_RECENT, true);
|
rootHints.putBoolean(MediaBrowserService.BrowserRoot.EXTRA_RECENT, true);
|
||||||
rootHints.putBoolean(MediaBrowserService.BrowserRoot.EXTRA_SUGGESTED, true);
|
rootHints.putBoolean(MediaBrowserService.BrowserRoot.EXTRA_SUGGESTED, true);
|
||||||
@ -396,7 +407,7 @@ public final class LegacyConversionsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void convertToLibraryParams_rootHintsBrowsableNoFlagSet_browsableOnlyFalse() {
|
public void convertToLibraryParams_rootHintsBrowsableNoFlagSet_browsableOnlyFalse() {
|
||||||
Bundle rootHints = new Bundle();
|
Bundle rootHints = new Bundle();
|
||||||
rootHints.putInt(MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS, 0);
|
rootHints.putInt(BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS, 0);
|
||||||
|
|
||||||
MediaLibraryService.LibraryParams params =
|
MediaLibraryService.LibraryParams params =
|
||||||
LegacyConversions.convertToLibraryParams(context, rootHints);
|
LegacyConversions.convertToLibraryParams(context, rootHints);
|
||||||
@ -408,8 +419,7 @@ public final class LegacyConversionsTest {
|
|||||||
public void convertToLibraryParams_rootHintsPlayableFlagSet_browsableOnlyFalse() {
|
public void convertToLibraryParams_rootHintsPlayableFlagSet_browsableOnlyFalse() {
|
||||||
Bundle rootHints = new Bundle();
|
Bundle rootHints = new Bundle();
|
||||||
rootHints.putInt(
|
rootHints.putInt(
|
||||||
MediaConstants.BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS,
|
BROWSER_ROOT_HINTS_KEY_ROOT_CHILDREN_SUPPORTED_FLAGS, FLAG_PLAYABLE | FLAG_BROWSABLE);
|
||||||
FLAG_PLAYABLE | FLAG_BROWSABLE);
|
|
||||||
|
|
||||||
MediaLibraryService.LibraryParams params =
|
MediaLibraryService.LibraryParams params =
|
||||||
LegacyConversions.convertToLibraryParams(context, rootHints);
|
LegacyConversions.convertToLibraryParams(context, rootHints);
|
||||||
@ -490,7 +500,7 @@ public final class LegacyConversionsTest {
|
|||||||
.isTrue();
|
.isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SdkSuppress(minSdkVersion = 21)
|
@Config(minSdk = 21)
|
||||||
@Test
|
@Test
|
||||||
public void convertToSessionCommands_whenSessionIsNotReadyOnSdk21_disallowsRating() {
|
public void convertToSessionCommands_whenSessionIsNotReadyOnSdk21_disallowsRating() {
|
||||||
SessionCommands sessionCommands =
|
SessionCommands sessionCommands =
|
||||||
@ -941,9 +951,7 @@ public final class LegacyConversionsTest {
|
|||||||
String displayName = "display_name";
|
String displayName = "display_name";
|
||||||
int iconRes = 21;
|
int iconRes = 21;
|
||||||
Bundle extras = new Bundle();
|
Bundle extras = new Bundle();
|
||||||
extras.putInt(
|
extras.putInt(EXTRAS_KEY_COMMAND_BUTTON_ICON_COMPAT, CommandButton.ICON_FAST_FORWARD);
|
||||||
androidx.media3.session.MediaConstants.EXTRAS_KEY_COMMAND_BUTTON_ICON_COMPAT,
|
|
||||||
CommandButton.ICON_FAST_FORWARD);
|
|
||||||
PlaybackStateCompat.CustomAction action =
|
PlaybackStateCompat.CustomAction action =
|
||||||
new PlaybackStateCompat.CustomAction.Builder(actionStr, displayName, iconRes)
|
new PlaybackStateCompat.CustomAction.Builder(actionStr, displayName, iconRes)
|
||||||
.setExtras(extras)
|
.setExtras(extras)
|
||||||
@ -1133,4 +1141,40 @@ public final class LegacyConversionsTest {
|
|||||||
state, /* metadataCompat= */ null, /* timeDiffMs= */ C.INDEX_UNSET);
|
state, /* metadataCompat= */ null, /* timeDiffMs= */ C.INDEX_UNSET);
|
||||||
assertThat(totalBufferedDurationMs).isEqualTo(testTotalBufferedDurationMs);
|
assertThat(totalBufferedDurationMs).isEqualTo(testTotalBufferedDurationMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(b/254265256): Move this method to a central place.
|
||||||
|
private static ImmutableList<@Player.Command Integer> getCommandsAsList(
|
||||||
|
Player.Commands commands) {
|
||||||
|
ImmutableList.Builder<@Player.Command Integer> list = new ImmutableList.Builder<>();
|
||||||
|
for (int i = 0; i < commands.size(); i++) {
|
||||||
|
list.add(commands.get(i));
|
||||||
|
}
|
||||||
|
return list.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MediaItem createMediaItemWithArtworkData(String mediaId) {
|
||||||
|
MediaMetadata.Builder mediaMetadataBuilder =
|
||||||
|
new MediaMetadata.Builder()
|
||||||
|
.setMediaType(MediaMetadata.MEDIA_TYPE_PLAYLIST)
|
||||||
|
.setIsBrowsable(false)
|
||||||
|
.setIsPlayable(true);
|
||||||
|
try {
|
||||||
|
byte[] artworkData;
|
||||||
|
Bitmap bitmap =
|
||||||
|
BitmapFactory.decodeStream(
|
||||||
|
ApplicationProvider.getApplicationContext()
|
||||||
|
.getResources()
|
||||||
|
.getAssets()
|
||||||
|
.open("media/png/non-motion-photo-shortened.png"));
|
||||||
|
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
|
||||||
|
bitmap.compress(Bitmap.CompressFormat.PNG, /* ignored */ 0, stream);
|
||||||
|
artworkData = stream.toByteArray();
|
||||||
|
}
|
||||||
|
mediaMetadataBuilder.setArtworkData(artworkData, MediaMetadata.PICTURE_TYPE_FRONT_COVER);
|
||||||
|
} catch (IOException e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
MediaMetadata mediaMetadata = mediaMetadataBuilder.build();
|
||||||
|
return new MediaItem.Builder().setMediaId(mediaId).setMediaMetadata(mediaMetadata).build();
|
||||||
|
}
|
||||||
}
|
}
|
@ -39,7 +39,6 @@ import android.support.v4.media.session.MediaControllerCompat;
|
|||||||
import android.support.v4.media.session.MediaSessionCompat.QueueItem;
|
import android.support.v4.media.session.MediaSessionCompat.QueueItem;
|
||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import androidx.media.AudioAttributesCompat;
|
|
||||||
import androidx.media3.common.AudioAttributes;
|
import androidx.media3.common.AudioAttributes;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.DeviceInfo;
|
import androidx.media3.common.DeviceInfo;
|
||||||
@ -155,12 +154,8 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
|
|||||||
handler);
|
handler);
|
||||||
|
|
||||||
assertThat(latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)).isTrue();
|
assertThat(latch.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)).isTrue();
|
||||||
assertThat(
|
assertThat(controller.getPlaybackState().getState())
|
||||||
LegacyConversions.convertToPlaybackState(
|
.isEqualTo(PlaybackStateCompat.STATE_PLAYING);
|
||||||
controller.getPlaybackState(),
|
|
||||||
controller.getMetadata(),
|
|
||||||
/* timeDiffMs= */ C.TIME_UNSET))
|
|
||||||
.isEqualTo(testState);
|
|
||||||
assertThat(controller.getPlaybackState().getBufferedPosition())
|
assertThat(controller.getPlaybackState().getBufferedPosition())
|
||||||
.isEqualTo(testBufferingPosition);
|
.isEqualTo(testBufferingPosition);
|
||||||
assertThat(controller.getPlaybackState().getPlaybackSpeed()).isEqualTo(testSpeed);
|
assertThat(controller.getPlaybackState().getPlaybackSpeed()).isEqualTo(testSpeed);
|
||||||
@ -396,11 +391,7 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
|
|||||||
assertThat(metadataRef.get().getString(METADATA_KEY_MEDIA_ID))
|
assertThat(metadataRef.get().getString(METADATA_KEY_MEDIA_ID))
|
||||||
.isEqualTo(testMediaItems.get(testItemIndex).mediaId);
|
.isEqualTo(testMediaItems.get(testItemIndex).mediaId);
|
||||||
assertThat(metadataRef.get().getLong(METADATA_KEY_DURATION)).isEqualTo(testDurationMs);
|
assertThat(metadataRef.get().getLong(METADATA_KEY_DURATION)).isEqualTo(testDurationMs);
|
||||||
@PlaybackStateCompat.State
|
assertThat(playbackStateRef.get().getState()).isEqualTo(PlaybackStateCompat.STATE_PLAYING);
|
||||||
int playbackStateFromControllerCompat =
|
|
||||||
LegacyConversions.convertToPlaybackState(
|
|
||||||
playbackStateRef.get(), metadataRef.get(), /* timeDiffMs= */ C.TIME_UNSET);
|
|
||||||
assertThat(playbackStateFromControllerCompat).isEqualTo(testState);
|
|
||||||
assertThat(metadataRef.get().getRating(METADATA_KEY_USER_RATING).hasHeart()).isTrue();
|
assertThat(metadataRef.get().getRating(METADATA_KEY_USER_RATING).hasHeart()).isTrue();
|
||||||
assertThat(latchForQueue.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
assertThat(latchForQueue.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||||
List<QueueItem> queue = controllerCompat.getQueue();
|
List<QueueItem> queue = controllerCompat.getQueue();
|
||||||
@ -461,9 +452,11 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
|
|||||||
new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(10).build();
|
new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(10).build();
|
||||||
int legacyPlaybackTypeToUpdate = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_LOCAL;
|
int legacyPlaybackTypeToUpdate = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_LOCAL;
|
||||||
int legacyStream = AudioManager.STREAM_RING;
|
int legacyStream = AudioManager.STREAM_RING;
|
||||||
AudioAttributesCompat attrsCompat =
|
AudioAttributes attrs =
|
||||||
new AudioAttributesCompat.Builder().setLegacyStreamType(legacyStream).build();
|
new AudioAttributes.Builder()
|
||||||
AudioAttributes attrs = LegacyConversions.convertToAudioAttributes(attrsCompat);
|
.setContentType(C.AUDIO_CONTENT_TYPE_SONIFICATION)
|
||||||
|
.setUsage(C.USAGE_NOTIFICATION_RINGTONE)
|
||||||
|
.build();
|
||||||
CountDownLatch playbackInfoNotified = new CountDownLatch(1);
|
CountDownLatch playbackInfoNotified = new CountDownLatch(1);
|
||||||
MediaControllerCompat.Callback callback =
|
MediaControllerCompat.Callback callback =
|
||||||
new MediaControllerCompat.Callback() {
|
new MediaControllerCompat.Callback() {
|
||||||
@ -507,9 +500,11 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
|
|||||||
new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(10).build();
|
new DeviceInfo.Builder(DeviceInfo.PLAYBACK_TYPE_LOCAL).setMaxVolume(10).build();
|
||||||
int legacyPlaybackType = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_LOCAL;
|
int legacyPlaybackType = MediaControllerCompat.PlaybackInfo.PLAYBACK_TYPE_LOCAL;
|
||||||
int legacyStream = AudioManager.STREAM_RING;
|
int legacyStream = AudioManager.STREAM_RING;
|
||||||
AudioAttributesCompat attrsCompat =
|
AudioAttributes attrs =
|
||||||
new AudioAttributesCompat.Builder().setLegacyStreamType(legacyStream).build();
|
new AudioAttributes.Builder()
|
||||||
AudioAttributes attrs = LegacyConversions.convertToAudioAttributes(attrsCompat);
|
.setContentType(C.AUDIO_CONTENT_TYPE_SONIFICATION)
|
||||||
|
.setUsage(C.USAGE_NOTIFICATION_RINGTONE)
|
||||||
|
.build();
|
||||||
CountDownLatch playbackInfoNotified = new CountDownLatch(1);
|
CountDownLatch playbackInfoNotified = new CountDownLatch(1);
|
||||||
MediaControllerCompat.Callback callback =
|
MediaControllerCompat.Callback callback =
|
||||||
new MediaControllerCompat.Callback() {
|
new MediaControllerCompat.Callback() {
|
||||||
@ -961,13 +956,13 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
|
|||||||
.setIconResId(2)
|
.setIconResId(2)
|
||||||
.build()
|
.build()
|
||||||
.copyWithIsEnabled(true));
|
.copyWithIsEnabled(true));
|
||||||
List<ImmutableList<CommandButton>> reportedCustomLayouts = new ArrayList<>();
|
List<PlaybackStateCompat> reportedPlaybackStates = new ArrayList<>();
|
||||||
CountDownLatch latch1 = new CountDownLatch(2);
|
CountDownLatch latch1 = new CountDownLatch(2);
|
||||||
MediaControllerCompat.Callback callback =
|
MediaControllerCompat.Callback callback =
|
||||||
new MediaControllerCompat.Callback() {
|
new MediaControllerCompat.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
||||||
reportedCustomLayouts.add(LegacyConversions.convertToCustomLayout(state));
|
reportedPlaybackStates.add(state);
|
||||||
latch1.countDown();
|
latch1.countDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -979,8 +974,27 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
|
|||||||
Player.Commands.EMPTY);
|
Player.Commands.EMPTY);
|
||||||
|
|
||||||
assertThat(latch1.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
assertThat(latch1.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||||
assertThat(reportedCustomLayouts.get(0)).containsExactly(customLayout.get(0));
|
assertThat(reportedPlaybackStates).hasSize(2);
|
||||||
assertThat(reportedCustomLayouts.get(1)).isEqualTo(customLayout);
|
assertThat(reportedPlaybackStates.get(0).getCustomActions()).hasSize(1);
|
||||||
|
PlaybackStateCompat.CustomAction action0 =
|
||||||
|
reportedPlaybackStates.get(0).getCustomActions().get(0);
|
||||||
|
assertThat(action0.getAction()).isEqualTo("command1");
|
||||||
|
assertThat(action0.getExtras().getString("key")).isEqualTo("value-1");
|
||||||
|
assertThat(action0.getIcon()).isEqualTo(1);
|
||||||
|
assertThat(action0.getName().toString()).isEqualTo("command1");
|
||||||
|
assertThat(reportedPlaybackStates.get(1).getCustomActions()).hasSize(2);
|
||||||
|
PlaybackStateCompat.CustomAction action1 =
|
||||||
|
reportedPlaybackStates.get(1).getCustomActions().get(0);
|
||||||
|
assertThat(action1.getAction()).isEqualTo("command1");
|
||||||
|
assertThat(action1.getExtras().getString("key")).isEqualTo("value-1");
|
||||||
|
assertThat(action1.getIcon()).isEqualTo(1);
|
||||||
|
assertThat(action1.getName().toString()).isEqualTo("command1");
|
||||||
|
PlaybackStateCompat.CustomAction action2 =
|
||||||
|
reportedPlaybackStates.get(1).getCustomActions().get(1);
|
||||||
|
assertThat(action2.getAction()).isEqualTo("command2");
|
||||||
|
assertThat(action2.getExtras().getString("key")).isEqualTo("value-2");
|
||||||
|
assertThat(action2.getIcon()).isEqualTo(2);
|
||||||
|
assertThat(action2.getName().toString()).isEqualTo("command2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1128,10 +1142,8 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
|
|||||||
assertThat(latchForPlaybackState.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
assertThat(latchForPlaybackState.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||||
assertThat(playbackStateRef.get().getPosition()).isEqualTo(testPosition);
|
assertThat(playbackStateRef.get().getPosition()).isEqualTo(testPosition);
|
||||||
assertThat(controllerCompat.getPlaybackState().getPosition()).isEqualTo(testPosition);
|
assertThat(controllerCompat.getPlaybackState().getPosition()).isEqualTo(testPosition);
|
||||||
assertThat(playbackStateRef.get().getActiveQueueItemId())
|
assertThat(playbackStateRef.get().getActiveQueueItemId()).isEqualTo(testItemIndex);
|
||||||
.isEqualTo(LegacyConversions.convertToQueueItemId(testItemIndex));
|
assertThat(controllerCompat.getPlaybackState().getActiveQueueItemId()).isEqualTo(testItemIndex);
|
||||||
assertThat(controllerCompat.getPlaybackState().getActiveQueueItemId())
|
|
||||||
.isEqualTo(LegacyConversions.convertToQueueItemId(testItemIndex));
|
|
||||||
assertThat(callbackOrder)
|
assertThat(callbackOrder)
|
||||||
.containsExactly("onMetadataChanged", "onPlaybackStateChanged")
|
.containsExactly("onMetadataChanged", "onPlaybackStateChanged")
|
||||||
.inOrder();
|
.inOrder();
|
||||||
|
@ -45,6 +45,7 @@ import androidx.media3.common.util.Consumer;
|
|||||||
import androidx.media3.exoplayer.ExoPlayer;
|
import androidx.media3.exoplayer.ExoPlayer;
|
||||||
import androidx.media3.session.MediaSession.ConnectionResult;
|
import androidx.media3.session.MediaSession.ConnectionResult;
|
||||||
import androidx.media3.session.MediaSession.ConnectionResult.AcceptedResultBuilder;
|
import androidx.media3.session.MediaSession.ConnectionResult.AcceptedResultBuilder;
|
||||||
|
import androidx.media3.test.session.R;
|
||||||
import androidx.media3.test.session.common.HandlerThreadTestRule;
|
import androidx.media3.test.session.common.HandlerThreadTestRule;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
@ -1482,8 +1483,15 @@ public class MediaControllerCompatPlaybackStateCompatActionsWithMediaSessionTest
|
|||||||
connectMediaNotificationController(mediaSession);
|
connectMediaNotificationController(mediaSession);
|
||||||
MediaControllerCompat controllerCompat = createMediaControllerCompat(mediaSession);
|
MediaControllerCompat controllerCompat = createMediaControllerCompat(mediaSession);
|
||||||
|
|
||||||
assertThat(LegacyConversions.convertToCustomLayout(controllerCompat.getPlaybackState()))
|
assertThat(controllerCompat.getPlaybackState().getCustomActions()).hasSize(1);
|
||||||
.containsExactly(customLayout.get(0).copyWithIsEnabled(true));
|
PlaybackStateCompat.CustomAction customAction =
|
||||||
|
controllerCompat.getPlaybackState().getCustomActions().get(0);
|
||||||
|
assertThat(customAction.getAction()).isEqualTo("command1");
|
||||||
|
assertThat(customAction.getName().toString()).isEqualTo("button1");
|
||||||
|
assertThat(customAction.getIcon()).isEqualTo(R.drawable.media3_icon_play);
|
||||||
|
assertThat(customAction.getExtras().get("key1")).isEqualTo("value1");
|
||||||
|
assertThat(customAction.getExtras().get(MediaConstants.EXTRAS_KEY_COMMAND_BUTTON_ICON_COMPAT))
|
||||||
|
.isEqualTo(CommandButton.ICON_PLAY);
|
||||||
mediaSession.release();
|
mediaSession.release();
|
||||||
releasePlayer(player);
|
releasePlayer(player);
|
||||||
}
|
}
|
||||||
@ -1522,15 +1530,16 @@ public class MediaControllerCompatPlaybackStateCompatActionsWithMediaSessionTest
|
|||||||
MediaSession mediaSession = createMediaSession(player, callback);
|
MediaSession mediaSession = createMediaSession(player, callback);
|
||||||
connectMediaNotificationController(mediaSession);
|
connectMediaNotificationController(mediaSession);
|
||||||
MediaControllerCompat controllerCompat = createMediaControllerCompat(mediaSession);
|
MediaControllerCompat controllerCompat = createMediaControllerCompat(mediaSession);
|
||||||
ImmutableList<CommandButton> initialCustomLayout =
|
List<PlaybackStateCompat.CustomAction> initialCustomActions =
|
||||||
LegacyConversions.convertToCustomLayout(controllerCompat.getPlaybackState());
|
controllerCompat.getPlaybackState().getCustomActions();
|
||||||
AtomicReference<List<CommandButton>> reportedCustomLayout = new AtomicReference<>();
|
AtomicReference<List<PlaybackStateCompat.CustomAction>> reportedCustomActions =
|
||||||
|
new AtomicReference<>();
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
controllerCompat.registerCallback(
|
controllerCompat.registerCallback(
|
||||||
new MediaControllerCompat.Callback() {
|
new MediaControllerCompat.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
||||||
reportedCustomLayout.set(LegacyConversions.convertToCustomLayout(state));
|
reportedCustomActions.set(state.getCustomActions());
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1539,9 +1548,19 @@ public class MediaControllerCompatPlaybackStateCompatActionsWithMediaSessionTest
|
|||||||
getInstrumentation().runOnMainSync(() -> mediaSession.setCustomLayout(customLayout));
|
getInstrumentation().runOnMainSync(() -> mediaSession.setCustomLayout(customLayout));
|
||||||
|
|
||||||
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||||
assertThat(initialCustomLayout).isEmpty();
|
assertThat(initialCustomActions).isEmpty();
|
||||||
assertThat(reportedCustomLayout.get())
|
assertThat(reportedCustomActions.get()).hasSize(1);
|
||||||
.containsExactly(customLayout.get(0).copyWithIsEnabled(true));
|
assertThat(reportedCustomActions.get().get(0).getAction()).isEqualTo("command1");
|
||||||
|
assertThat(reportedCustomActions.get().get(0).getName().toString()).isEqualTo("button1");
|
||||||
|
assertThat(reportedCustomActions.get().get(0).getIcon()).isEqualTo(R.drawable.media3_icon_play);
|
||||||
|
assertThat(reportedCustomActions.get().get(0).getExtras().get("key1")).isEqualTo("value1");
|
||||||
|
assertThat(
|
||||||
|
reportedCustomActions
|
||||||
|
.get()
|
||||||
|
.get(0)
|
||||||
|
.getExtras()
|
||||||
|
.get(MediaConstants.EXTRAS_KEY_COMMAND_BUTTON_ICON_COMPAT))
|
||||||
|
.isEqualTo(CommandButton.ICON_PLAY);
|
||||||
mediaSession.release();
|
mediaSession.release();
|
||||||
releasePlayer(player);
|
releasePlayer(player);
|
||||||
}
|
}
|
||||||
@ -1581,15 +1600,16 @@ public class MediaControllerCompatPlaybackStateCompatActionsWithMediaSessionTest
|
|||||||
MediaSession mediaSession = createMediaSession(player, callback);
|
MediaSession mediaSession = createMediaSession(player, callback);
|
||||||
connectMediaNotificationController(mediaSession);
|
connectMediaNotificationController(mediaSession);
|
||||||
MediaControllerCompat controllerCompat = createMediaControllerCompat(mediaSession);
|
MediaControllerCompat controllerCompat = createMediaControllerCompat(mediaSession);
|
||||||
ImmutableList<CommandButton> initialCustomLayout =
|
List<PlaybackStateCompat.CustomAction> initialCustomActions =
|
||||||
LegacyConversions.convertToCustomLayout(controllerCompat.getPlaybackState());
|
controllerCompat.getPlaybackState().getCustomActions();
|
||||||
AtomicReference<List<CommandButton>> reportedCustomLayout = new AtomicReference<>();
|
AtomicReference<List<PlaybackStateCompat.CustomAction>> reportedCustomActions =
|
||||||
|
new AtomicReference<>();
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
controllerCompat.registerCallback(
|
controllerCompat.registerCallback(
|
||||||
new MediaControllerCompat.Callback() {
|
new MediaControllerCompat.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
public void onPlaybackStateChanged(PlaybackStateCompat state) {
|
||||||
reportedCustomLayout.set(LegacyConversions.convertToCustomLayout(state));
|
reportedCustomActions.set(state.getCustomActions());
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1602,9 +1622,19 @@ public class MediaControllerCompatPlaybackStateCompatActionsWithMediaSessionTest
|
|||||||
mediaSession.getMediaNotificationControllerInfo(), customLayout));
|
mediaSession.getMediaNotificationControllerInfo(), customLayout));
|
||||||
|
|
||||||
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||||
assertThat(initialCustomLayout).isEmpty();
|
assertThat(initialCustomActions).isEmpty();
|
||||||
assertThat(reportedCustomLayout.get())
|
assertThat(reportedCustomActions.get()).hasSize(1);
|
||||||
.containsExactly(customLayout.get(0).copyWithIsEnabled(true));
|
assertThat(reportedCustomActions.get().get(0).getAction()).isEqualTo("command1");
|
||||||
|
assertThat(reportedCustomActions.get().get(0).getName().toString()).isEqualTo("button1");
|
||||||
|
assertThat(reportedCustomActions.get().get(0).getIcon()).isEqualTo(R.drawable.media3_icon_play);
|
||||||
|
assertThat(reportedCustomActions.get().get(0).getExtras().get("key1")).isEqualTo("value1");
|
||||||
|
assertThat(
|
||||||
|
reportedCustomActions
|
||||||
|
.get()
|
||||||
|
.get(0)
|
||||||
|
.getExtras()
|
||||||
|
.get(MediaConstants.EXTRAS_KEY_COMMAND_BUTTON_ICON_COMPAT))
|
||||||
|
.isEqualTo(CommandButton.ICON_PLAY);
|
||||||
mediaSession.release();
|
mediaSession.release();
|
||||||
releasePlayer(player);
|
releasePlayer(player);
|
||||||
}
|
}
|
||||||
@ -1691,8 +1721,7 @@ public class MediaControllerCompatPlaybackStateCompatActionsWithMediaSessionTest
|
|||||||
|
|
||||||
private static MediaControllerCompat createMediaControllerCompat(MediaSession mediaSession) {
|
private static MediaControllerCompat createMediaControllerCompat(MediaSession mediaSession) {
|
||||||
return new MediaControllerCompat(
|
return new MediaControllerCompat(
|
||||||
ApplicationProvider.getApplicationContext(),
|
ApplicationProvider.getApplicationContext(), mediaSession.getSessionCompatToken());
|
||||||
mediaSession.getSessionCompat().getSessionToken());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Releases the {@code player} on the main thread. */
|
/** Releases the {@code player} on the main thread. */
|
||||||
|
@ -38,12 +38,10 @@ import static org.junit.Assert.assertThrows;
|
|||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.media.AudioManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.text.SpannedString;
|
import android.text.SpannedString;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media.AudioAttributesCompat;
|
|
||||||
import androidx.media3.common.AudioAttributes;
|
import androidx.media3.common.AudioAttributes;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.DeviceInfo;
|
import androidx.media3.common.DeviceInfo;
|
||||||
@ -189,7 +187,6 @@ public class MediaControllerListenerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void connection_sessionReleased() throws Exception {
|
public void connection_sessionReleased() throws Exception {
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
MediaController controller =
|
|
||||||
controllerTestRule.createController(
|
controllerTestRule.createController(
|
||||||
remoteSession.getToken(),
|
remoteSession.getToken(),
|
||||||
/* connectionHints= */ null,
|
/* connectionHints= */ null,
|
||||||
@ -236,7 +233,7 @@ public class MediaControllerListenerTest {
|
|||||||
@LargeTest
|
@LargeTest
|
||||||
public void noInteractionAfterSessionClose_session() throws Exception {
|
public void noInteractionAfterSessionClose_session() throws Exception {
|
||||||
SessionToken token = remoteSession.getToken();
|
SessionToken token = remoteSession.getToken();
|
||||||
MediaController controller = controllerTestRule.createController(token);
|
controllerTestRule.createController(token);
|
||||||
testControllerAfterSessionIsClosed(DEFAULT_TEST_NAME);
|
testControllerAfterSessionIsClosed(DEFAULT_TEST_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,10 +319,10 @@ public class MediaControllerListenerTest {
|
|||||||
Timeline testTimeline = MediaTestUtils.createTimeline(/* windowCount= */ 3);
|
Timeline testTimeline = MediaTestUtils.createTimeline(/* windowCount= */ 3);
|
||||||
MediaMetadata testPlaylistMetadata = new MediaMetadata.Builder().setTitle("title").build();
|
MediaMetadata testPlaylistMetadata = new MediaMetadata.Builder().setTitle("title").build();
|
||||||
AudioAttributes testAudioAttributes =
|
AudioAttributes testAudioAttributes =
|
||||||
LegacyConversions.convertToAudioAttributes(
|
new AudioAttributes.Builder()
|
||||||
new AudioAttributesCompat.Builder()
|
.setUsage(C.USAGE_ALARM)
|
||||||
.setLegacyStreamType(AudioManager.STREAM_RING)
|
.setContentType(C.AUDIO_CONTENT_TYPE_SONIFICATION)
|
||||||
.build());
|
.build();
|
||||||
boolean testShuffleModeEnabled = true;
|
boolean testShuffleModeEnabled = true;
|
||||||
@Player.RepeatMode int testRepeatMode = Player.REPEAT_MODE_ALL;
|
@Player.RepeatMode int testRepeatMode = Player.REPEAT_MODE_ALL;
|
||||||
int testCurrentAdGroupIndex = 33;
|
int testCurrentAdGroupIndex = 33;
|
||||||
@ -2173,7 +2170,6 @@ public class MediaControllerListenerTest {
|
|||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MediaController controller =
|
|
||||||
controllerTestRule.createController(
|
controllerTestRule.createController(
|
||||||
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
||||||
|
|
||||||
@ -2392,7 +2388,6 @@ public class MediaControllerListenerTest {
|
|||||||
return Futures.immediateFuture(new SessionResult(SessionResult.RESULT_SUCCESS));
|
return Futures.immediateFuture(new SessionResult(SessionResult.RESULT_SUCCESS));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MediaController controller =
|
|
||||||
controllerTestRule.createController(
|
controllerTestRule.createController(
|
||||||
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
||||||
|
|
||||||
@ -2448,9 +2443,7 @@ public class MediaControllerListenerTest {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
RemoteMediaSession session = createRemoteMediaSession(TEST_WITH_CUSTOM_COMMANDS);
|
RemoteMediaSession session = createRemoteMediaSession(TEST_WITH_CUSTOM_COMMANDS);
|
||||||
MediaController controller =
|
controllerTestRule.createController(session.getToken(), /* connectionHints= */ null, listener);
|
||||||
controllerTestRule.createController(
|
|
||||||
session.getToken(), /* connectionHints= */ null, listener);
|
|
||||||
|
|
||||||
session.setCustomLayout(buttons);
|
session.setCustomLayout(buttons);
|
||||||
|
|
||||||
@ -2480,7 +2473,6 @@ public class MediaControllerListenerTest {
|
|||||||
latch.countDown();
|
latch.countDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
MediaController controller =
|
|
||||||
controllerTestRule.createController(
|
controllerTestRule.createController(
|
||||||
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
remoteSession.getToken(), /* connectionHints= */ null, listener);
|
||||||
|
|
||||||
@ -2511,7 +2503,6 @@ public class MediaControllerListenerTest {
|
|||||||
};
|
};
|
||||||
Bundle connectionHints = new Bundle();
|
Bundle connectionHints = new Bundle();
|
||||||
connectionHints.putString(KEY_CONTROLLER, "controller_key_1");
|
connectionHints.putString(KEY_CONTROLLER, "controller_key_1");
|
||||||
MediaController controller =
|
|
||||||
controllerTestRule.createController(remoteSession.getToken(), connectionHints, listener);
|
controllerTestRule.createController(remoteSession.getToken(), connectionHints, listener);
|
||||||
|
|
||||||
remoteSession.setSessionExtras("controller_key_1", sessionExtras);
|
remoteSession.setSessionExtras("controller_key_1", sessionExtras);
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package androidx.media3.session;
|
package androidx.media3.session;
|
||||||
|
|
||||||
|
import static androidx.media3.common.MediaMetadata.MEDIA_TYPE_PLAYLIST;
|
||||||
import static androidx.media3.common.Player.DISCONTINUITY_REASON_AUTO_TRANSITION;
|
import static androidx.media3.common.Player.DISCONTINUITY_REASON_AUTO_TRANSITION;
|
||||||
import static androidx.media3.common.Player.EVENT_MEDIA_ITEM_TRANSITION;
|
import static androidx.media3.common.Player.EVENT_MEDIA_ITEM_TRANSITION;
|
||||||
import static androidx.media3.common.Player.EVENT_MEDIA_METADATA_CHANGED;
|
import static androidx.media3.common.Player.EVENT_MEDIA_METADATA_CHANGED;
|
||||||
@ -30,6 +31,7 @@ import static java.util.concurrent.TimeUnit.SECONDS;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.support.v4.media.MediaDescriptionCompat;
|
import android.support.v4.media.MediaDescriptionCompat;
|
||||||
import android.support.v4.media.MediaMetadataCompat;
|
import android.support.v4.media.MediaMetadataCompat;
|
||||||
import android.support.v4.media.RatingCompat;
|
import android.support.v4.media.RatingCompat;
|
||||||
@ -38,6 +40,7 @@ import android.support.v4.media.session.MediaSessionCompat.QueueItem;
|
|||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.FlagSet;
|
import androidx.media3.common.FlagSet;
|
||||||
|
import androidx.media3.common.HeartRating;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
import androidx.media3.common.MediaMetadata;
|
import androidx.media3.common.MediaMetadata;
|
||||||
import androidx.media3.common.Player;
|
import androidx.media3.common.Player;
|
||||||
@ -52,6 +55,7 @@ import androidx.media3.test.session.common.HandlerThreadTestRule;
|
|||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import androidx.test.filters.MediumTest;
|
import androidx.test.filters.MediumTest;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
@ -99,10 +103,22 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
|
|||||||
List<MediaItem> testMediaItems = MediaTestUtils.createMediaItemsWithArtworkData(testSize);
|
List<MediaItem> testMediaItems = MediaTestUtils.createMediaItemsWithArtworkData(testSize);
|
||||||
List<QueueItem> testQueue = convertToQueueItems(testMediaItems);
|
List<QueueItem> testQueue = convertToQueueItems(testMediaItems);
|
||||||
int testMediaItemIndex = 1;
|
int testMediaItemIndex = 1;
|
||||||
MediaMetadataCompat testMediaMetadataCompat = createMediaMetadataCompat();
|
MediaMetadataCompat testMediaMetadataCompat =
|
||||||
|
new MediaMetadataCompat.Builder()
|
||||||
|
.putText(MediaMetadataCompat.METADATA_KEY_ARTIST, "artist")
|
||||||
|
.putText(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, "title")
|
||||||
|
.putLong(MediaConstants.EXTRAS_KEY_MEDIA_TYPE_COMPAT, MEDIA_TYPE_PLAYLIST)
|
||||||
|
.build();
|
||||||
@RatingCompat.Style int testRatingType = RatingCompat.RATING_HEART;
|
@RatingCompat.Style int testRatingType = RatingCompat.RATING_HEART;
|
||||||
MediaMetadata testMediaMetadata =
|
MediaMetadata testMediaMetadata =
|
||||||
LegacyConversions.convertToMediaMetadata(testMediaMetadataCompat, testRatingType);
|
new MediaMetadata.Builder()
|
||||||
|
.setArtist("artist")
|
||||||
|
.setTitle("title")
|
||||||
|
.setUserRating(new HeartRating())
|
||||||
|
.setMediaType(MEDIA_TYPE_PLAYLIST)
|
||||||
|
.setIsBrowsable(false)
|
||||||
|
.setIsPlayable(true)
|
||||||
|
.build();
|
||||||
MediaItem testCurrentMediaItem =
|
MediaItem testCurrentMediaItem =
|
||||||
new MediaItem.Builder()
|
new MediaItem.Builder()
|
||||||
.setMediaId(testMediaItems.get(testMediaItemIndex).mediaId)
|
.setMediaId(testMediaItems.get(testMediaItemIndex).mediaId)
|
||||||
@ -231,10 +247,20 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
|
|||||||
int testSize = 3;
|
int testSize = 3;
|
||||||
List<MediaItem> testMediaItems = MediaTestUtils.createMediaItems(testSize);
|
List<MediaItem> testMediaItems = MediaTestUtils.createMediaItems(testSize);
|
||||||
List<QueueItem> testQueue = MediaTestUtils.convertToQueueItemsWithoutBitmap(testMediaItems);
|
List<QueueItem> testQueue = MediaTestUtils.convertToQueueItemsWithoutBitmap(testMediaItems);
|
||||||
MediaMetadataCompat testMediaMetadataCompat = createMediaMetadataCompat();
|
MediaMetadataCompat testMediaMetadataCompat =
|
||||||
|
new MediaMetadataCompat.Builder()
|
||||||
|
.putText(MediaMetadataCompat.METADATA_KEY_ARTIST, "artist")
|
||||||
|
.putText(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, "title")
|
||||||
|
.build();
|
||||||
@RatingCompat.Style int testRatingType = RatingCompat.RATING_HEART;
|
@RatingCompat.Style int testRatingType = RatingCompat.RATING_HEART;
|
||||||
MediaMetadata testMediaMetadata =
|
MediaMetadata testMediaMetadata =
|
||||||
LegacyConversions.convertToMediaMetadata(testMediaMetadataCompat, testRatingType);
|
new MediaMetadata.Builder()
|
||||||
|
.setArtist("artist")
|
||||||
|
.setTitle("title")
|
||||||
|
.setUserRating(new HeartRating())
|
||||||
|
.setIsBrowsable(false)
|
||||||
|
.setIsPlayable(true)
|
||||||
|
.build();
|
||||||
Events testEvents =
|
Events testEvents =
|
||||||
new Events(
|
new Events(
|
||||||
new FlagSet.Builder()
|
new FlagSet.Builder()
|
||||||
@ -245,8 +271,7 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
|
|||||||
EVENT_TIMELINE_CHANGED)
|
EVENT_TIMELINE_CHANGED)
|
||||||
.build());
|
.build());
|
||||||
int testMediaItemIndex = testSize; // Index of fake item.
|
int testMediaItemIndex = testSize; // Index of fake item.
|
||||||
testMediaItems.add(
|
testMediaItems.add(new MediaItem.Builder().setMediaMetadata(testMediaMetadata).build());
|
||||||
LegacyConversions.convertToMediaItem(testMediaMetadataCompat, testRatingType));
|
|
||||||
|
|
||||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
CountDownLatch latch = new CountDownLatch(5);
|
CountDownLatch latch = new CountDownLatch(5);
|
||||||
@ -425,10 +450,20 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getters_withMetadata() throws Exception {
|
public void getters_withMetadata() throws Exception {
|
||||||
MediaMetadataCompat testMediaMetadataCompat = createMediaMetadataCompat();
|
MediaMetadataCompat testMediaMetadataCompat =
|
||||||
|
new MediaMetadataCompat.Builder()
|
||||||
|
.putText(MediaMetadataCompat.METADATA_KEY_ARTIST, "artist")
|
||||||
|
.putText(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, "title")
|
||||||
|
.build();
|
||||||
@RatingCompat.Style int testRatingType = RatingCompat.RATING_HEART;
|
@RatingCompat.Style int testRatingType = RatingCompat.RATING_HEART;
|
||||||
MediaMetadata testMediaMetadata =
|
MediaMetadata testMediaMetadata =
|
||||||
LegacyConversions.convertToMediaMetadata(testMediaMetadataCompat, testRatingType);
|
new MediaMetadata.Builder()
|
||||||
|
.setArtist("artist")
|
||||||
|
.setTitle("title")
|
||||||
|
.setUserRating(new HeartRating())
|
||||||
|
.setIsBrowsable(false)
|
||||||
|
.setIsPlayable(true)
|
||||||
|
.build();
|
||||||
Events testEvents =
|
Events testEvents =
|
||||||
new Events(
|
new Events(
|
||||||
new FlagSet.Builder()
|
new FlagSet.Builder()
|
||||||
@ -439,9 +474,8 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
|
|||||||
EVENT_TIMELINE_CHANGED)
|
EVENT_TIMELINE_CHANGED)
|
||||||
.build());
|
.build());
|
||||||
int testMediaItemIndex = 0;
|
int testMediaItemIndex = 0;
|
||||||
List<MediaItem> testMediaItems = new ArrayList<>();
|
ImmutableList<MediaItem> testMediaItems =
|
||||||
testMediaItems.add(
|
ImmutableList.of(new MediaItem.Builder().setMediaMetadata(testMediaMetadata).build());
|
||||||
LegacyConversions.convertToMediaItem(testMediaMetadataCompat, testRatingType));
|
|
||||||
|
|
||||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
CountDownLatch latch = new CountDownLatch(5);
|
CountDownLatch latch = new CountDownLatch(5);
|
||||||
@ -523,13 +557,6 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
|
|||||||
assertThat(currentMediaMetadata).isEqualTo(currentMediaItem.mediaMetadata);
|
assertThat(currentMediaMetadata).isEqualTo(currentMediaItem.mediaMetadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MediaMetadataCompat createMediaMetadataCompat() {
|
|
||||||
return new MediaMetadataCompat.Builder()
|
|
||||||
.putText(MediaMetadataCompat.METADATA_KEY_ARTIST, "artist")
|
|
||||||
.putText(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, "title")
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void assertTimelineEqualsToMediaItems(
|
private static void assertTimelineEqualsToMediaItems(
|
||||||
Timeline currentTimeline, List<MediaItem> mediaItems) {
|
Timeline currentTimeline, List<MediaItem> mediaItems) {
|
||||||
assertThat(currentTimeline.getWindowCount()).isEqualTo(mediaItems.size());
|
assertThat(currentTimeline.getWindowCount()).isEqualTo(mediaItems.size());
|
||||||
@ -549,8 +576,14 @@ public class MediaControllerMediaSessionCompatCallbackAggregationTest {
|
|||||||
MediaItem item = mediaItems.get(i);
|
MediaItem item = mediaItems.get(i);
|
||||||
@Nullable
|
@Nullable
|
||||||
Bitmap bitmap = bitmapLoader.decodeBitmap(item.mediaMetadata.artworkData).get(10, SECONDS);
|
Bitmap bitmap = bitmapLoader.decodeBitmap(item.mediaMetadata.artworkData).get(10, SECONDS);
|
||||||
|
Bundle extras = new Bundle();
|
||||||
|
extras.putLong(MediaConstants.EXTRAS_KEY_MEDIA_TYPE_COMPAT, item.mediaMetadata.mediaType);
|
||||||
MediaDescriptionCompat description =
|
MediaDescriptionCompat description =
|
||||||
LegacyConversions.convertToMediaDescriptionCompat(item, bitmap);
|
new MediaDescriptionCompat.Builder()
|
||||||
|
.setMediaId(item.mediaId)
|
||||||
|
.setIconBitmap(bitmap)
|
||||||
|
.setExtras(extras)
|
||||||
|
.build();
|
||||||
long id = LegacyConversions.convertToQueueItemId(i);
|
long id = LegacyConversions.convertToQueueItemId(i);
|
||||||
list.add(new MediaSessionCompat.QueueItem(description, id));
|
list.add(new MediaSessionCompat.QueueItem(description, id));
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
package androidx.media3.session;
|
package androidx.media3.session;
|
||||||
|
|
||||||
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_ADVERTISEMENT;
|
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_ADVERTISEMENT;
|
||||||
|
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_ALBUM_ART;
|
||||||
|
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_ARTIST;
|
||||||
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION;
|
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION;
|
||||||
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI;
|
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON_URI;
|
||||||
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE;
|
import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE;
|
||||||
@ -31,6 +33,7 @@ import static androidx.media3.session.MediaConstants.ARGUMENT_CAPTIONING_ENABLED
|
|||||||
import static androidx.media3.session.MediaConstants.SESSION_COMMAND_ON_CAPTIONING_ENABLED_CHANGED;
|
import static androidx.media3.session.MediaConstants.SESSION_COMMAND_ON_CAPTIONING_ENABLED_CHANGED;
|
||||||
import static androidx.media3.session.SessionResult.RESULT_SUCCESS;
|
import static androidx.media3.session.SessionResult.RESULT_SUCCESS;
|
||||||
import static androidx.media3.test.session.common.CommonConstants.DEFAULT_TEST_NAME;
|
import static androidx.media3.test.session.common.CommonConstants.DEFAULT_TEST_NAME;
|
||||||
|
import static androidx.media3.test.session.common.CommonConstants.KEY_DURATION;
|
||||||
import static androidx.media3.test.session.common.CommonConstants.METADATA_ALBUM_TITLE;
|
import static androidx.media3.test.session.common.CommonConstants.METADATA_ALBUM_TITLE;
|
||||||
import static androidx.media3.test.session.common.CommonConstants.METADATA_ARTIST;
|
import static androidx.media3.test.session.common.CommonConstants.METADATA_ARTIST;
|
||||||
import static androidx.media3.test.session.common.CommonConstants.METADATA_DESCRIPTION;
|
import static androidx.media3.test.session.common.CommonConstants.METADATA_DESCRIPTION;
|
||||||
@ -818,14 +821,8 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
List<MediaItem> testList = MediaTestUtils.createMediaItems(3);
|
List<MediaItem> testList = MediaTestUtils.createMediaItems(3);
|
||||||
List<QueueItem> testQueue = MediaTestUtils.convertToQueueItemsWithoutBitmap(testList);
|
List<QueueItem> testQueue = MediaTestUtils.convertToQueueItemsWithoutBitmap(testList);
|
||||||
MediaItem testRemoveMediaItem = MediaTestUtils.createMediaItem("removed");
|
|
||||||
MediaMetadataCompat testMetadataCompat =
|
MediaMetadataCompat testMetadataCompat =
|
||||||
LegacyConversions.convertToMediaMetadataCompat(
|
new MediaMetadataCompat.Builder().putString(METADATA_KEY_MEDIA_ID, "mediaId").build();
|
||||||
testRemoveMediaItem.mediaMetadata,
|
|
||||||
"mediaId",
|
|
||||||
Uri.parse("http://example.com"),
|
|
||||||
/* durationMs= */ 100L,
|
|
||||||
/* artworkBitmap= */ null);
|
|
||||||
session.setQueue(testQueue);
|
session.setQueue(testQueue);
|
||||||
session.setMetadata(testMetadataCompat);
|
session.setMetadata(testMetadataCompat);
|
||||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
@ -840,14 +837,8 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
List<MediaItem> testList = MediaTestUtils.createMediaItems(3);
|
List<MediaItem> testList = MediaTestUtils.createMediaItems(3);
|
||||||
List<QueueItem> testQueue = MediaTestUtils.convertToQueueItemsWithoutBitmap(testList);
|
List<QueueItem> testQueue = MediaTestUtils.convertToQueueItemsWithoutBitmap(testList);
|
||||||
MediaItem testRemoveMediaItem = MediaTestUtils.createMediaItem("removed");
|
|
||||||
MediaMetadataCompat testMetadataCompat =
|
MediaMetadataCompat testMetadataCompat =
|
||||||
LegacyConversions.convertToMediaMetadataCompat(
|
new MediaMetadataCompat.Builder().putString(METADATA_KEY_MEDIA_ID, "mediaId").build();
|
||||||
testRemoveMediaItem.mediaMetadata,
|
|
||||||
"mediaId",
|
|
||||||
Uri.parse("http://example.com"),
|
|
||||||
/* durationMs= */ 100L,
|
|
||||||
/* artworkBitmap= */ null);
|
|
||||||
session.setQueue(testQueue);
|
session.setQueue(testQueue);
|
||||||
session.setMetadata(testMetadataCompat);
|
session.setMetadata(testMetadataCompat);
|
||||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
@ -879,14 +870,8 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
List<MediaItem> testList = MediaTestUtils.createMediaItems(3);
|
List<MediaItem> testList = MediaTestUtils.createMediaItems(3);
|
||||||
List<QueueItem> testQueue = MediaTestUtils.convertToQueueItemsWithoutBitmap(testList);
|
List<QueueItem> testQueue = MediaTestUtils.convertToQueueItemsWithoutBitmap(testList);
|
||||||
MediaItem testRemoveMediaItem = MediaTestUtils.createMediaItem("removed");
|
|
||||||
MediaMetadataCompat testMetadataCompat =
|
MediaMetadataCompat testMetadataCompat =
|
||||||
LegacyConversions.convertToMediaMetadataCompat(
|
new MediaMetadataCompat.Builder().putString(METADATA_KEY_MEDIA_ID, "mediaId").build();
|
||||||
testRemoveMediaItem.mediaMetadata,
|
|
||||||
"mediaId",
|
|
||||||
Uri.parse("http://example.com"),
|
|
||||||
/* durationMs= */ 100L,
|
|
||||||
/* artworkBitmap= */ null);
|
|
||||||
session.setQueue(testQueue);
|
session.setQueue(testQueue);
|
||||||
session.setMetadata(testMetadataCompat);
|
session.setMetadata(testMetadataCompat);
|
||||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
@ -900,22 +885,15 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getMediaMetadata_withMediaMetadataCompat_returnsConvertedMediaMetadata()
|
public void getMediaMetadata_withMediaMetadataCompat_returnsConvertedMediaMetadata()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
MediaItem testMediaItem = MediaTestUtils.createMediaItem("test");
|
|
||||||
MediaMetadata testMediaMetadata = testMediaItem.mediaMetadata;
|
|
||||||
MediaMetadataCompat testMediaMetadataCompat =
|
MediaMetadataCompat testMediaMetadataCompat =
|
||||||
LegacyConversions.convertToMediaMetadataCompat(
|
new MediaMetadataCompat.Builder().putString(METADATA_KEY_ARTIST, "artist").build();
|
||||||
testMediaMetadata,
|
|
||||||
"mediaId",
|
|
||||||
Uri.parse("http://example.com"),
|
|
||||||
/* durationMs= */ 100L,
|
|
||||||
/* artworkBitmap= */ null);
|
|
||||||
session.setMetadata(testMediaMetadataCompat);
|
session.setMetadata(testMediaMetadataCompat);
|
||||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
|
|
||||||
MediaMetadata mediaMetadata =
|
MediaMetadata mediaMetadata =
|
||||||
threadTestRule.getHandler().postAndSync(controller::getMediaMetadata);
|
threadTestRule.getHandler().postAndSync(controller::getMediaMetadata);
|
||||||
|
|
||||||
assertThat(mediaMetadata).isEqualTo(testMediaMetadata);
|
assertThat(mediaMetadata.artist.toString()).isEqualTo("artist");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -925,12 +903,7 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
MediaMetadata testMediaMetadata = testMediaItem.mediaMetadata;
|
MediaMetadata testMediaMetadata = testMediaItem.mediaMetadata;
|
||||||
@Nullable Bitmap artworkBitmap = getBitmapFromMetadata(testMediaMetadata);
|
@Nullable Bitmap artworkBitmap = getBitmapFromMetadata(testMediaMetadata);
|
||||||
MediaMetadataCompat testMediaMetadataCompat =
|
MediaMetadataCompat testMediaMetadataCompat =
|
||||||
LegacyConversions.convertToMediaMetadataCompat(
|
new MediaMetadataCompat.Builder().putBitmap(METADATA_KEY_ALBUM_ART, artworkBitmap).build();
|
||||||
testMediaMetadata,
|
|
||||||
"mediaId",
|
|
||||||
Uri.parse("http://example.com"),
|
|
||||||
/* durationMs= */ 100L,
|
|
||||||
artworkBitmap);
|
|
||||||
session.setMetadata(testMediaMetadataCompat);
|
session.setMetadata(testMediaMetadataCompat);
|
||||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
|
|
||||||
@ -951,7 +924,7 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
.setArtworkData(/* artworkData= */ null, /* artworkDataType= */ null)
|
.setArtworkData(/* artworkData= */ null, /* artworkDataType= */ null)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
assertThat(mediaMetadata).isEqualTo(testMediaMetadata);
|
assertThat(mediaMetadata.artworkData).isEqualTo(testMediaMetadata.artworkData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -1004,7 +977,7 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
.putText(
|
.putText(
|
||||||
MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION,
|
MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION,
|
||||||
testMediaMetadataCompatDescription)
|
testMediaMetadataCompatDescription)
|
||||||
.putText(MediaMetadataCompat.METADATA_KEY_ARTIST, METADATA_ARTIST)
|
.putText(METADATA_KEY_ARTIST, METADATA_ARTIST)
|
||||||
.putText(MediaMetadataCompat.METADATA_KEY_ALBUM, METADATA_ALBUM_TITLE)
|
.putText(MediaMetadataCompat.METADATA_KEY_ALBUM, METADATA_ALBUM_TITLE)
|
||||||
.build();
|
.build();
|
||||||
long testActiveQueueId = 0;
|
long testActiveQueueId = 0;
|
||||||
@ -1269,15 +1242,8 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setPlaybackState_fromStateBufferingToPlaying_notifiesReadyState() throws Exception {
|
public void setPlaybackState_fromStateBufferingToPlaying_notifiesReadyState() throws Exception {
|
||||||
List<MediaItem> testPlaylist = MediaTestUtils.createMediaItems(/* size= */ 1);
|
|
||||||
MediaItem firstMediaItemInPlaylist = testPlaylist.get(0);
|
|
||||||
MediaMetadataCompat metadata =
|
MediaMetadataCompat metadata =
|
||||||
LegacyConversions.convertToMediaMetadataCompat(
|
new MediaMetadataCompat.Builder().putLong(KEY_DURATION, 50_000L).build();
|
||||||
firstMediaItemInPlaylist.mediaMetadata,
|
|
||||||
"mediaId",
|
|
||||||
Uri.parse("http://example.com"),
|
|
||||||
/* durationMs= */ 50_000,
|
|
||||||
/* artworkBitmap= */ null);
|
|
||||||
long testBufferedPosition = 5_000;
|
long testBufferedPosition = 5_000;
|
||||||
session.setMetadata(metadata);
|
session.setMetadata(metadata);
|
||||||
session.setPlaybackState(
|
session.setPlaybackState(
|
||||||
@ -1319,15 +1285,12 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
@Test
|
@Test
|
||||||
public void setPlaybackState_fromStatePlayingToBuffering_notifiesBufferingState()
|
public void setPlaybackState_fromStatePlayingToBuffering_notifiesBufferingState()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
List<MediaItem> testPlaylist = MediaTestUtils.createMediaItems(1);
|
|
||||||
MediaItem firstMediaItemInPlaylist = testPlaylist.get(0);
|
|
||||||
MediaMetadataCompat metadata =
|
MediaMetadataCompat metadata =
|
||||||
LegacyConversions.convertToMediaMetadataCompat(
|
new MediaMetadataCompat.Builder()
|
||||||
firstMediaItemInPlaylist.mediaMetadata,
|
.putString(METADATA_KEY_MEDIA_ID, "mediaId")
|
||||||
"mediaId",
|
.putString(METADATA_KEY_MEDIA_URI, "http://example.com")
|
||||||
Uri.parse("http://example.com"),
|
.putLong(KEY_DURATION, 1000L)
|
||||||
/* durationMs= */ 1_000,
|
.build();
|
||||||
/* artworkBitmap= */ null);
|
|
||||||
long testBufferingPosition = 0;
|
long testBufferingPosition = 0;
|
||||||
session.setMetadata(metadata);
|
session.setMetadata(metadata);
|
||||||
session.setPlaybackState(
|
session.setPlaybackState(
|
||||||
@ -2001,7 +1964,7 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, "mediaItem_2")
|
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, "mediaItem_2")
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, "Title")
|
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, "Title")
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, "Subtitle")
|
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, "Subtitle")
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "Artist")
|
.putString(METADATA_KEY_ARTIST, "Artist")
|
||||||
.build());
|
.build());
|
||||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
CountDownLatch countDownLatch = new CountDownLatch(1);
|
CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||||
@ -2044,7 +2007,7 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, "mediaItem_2")
|
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, "mediaItem_2")
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, "Title")
|
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, "Title")
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, "Subtitle")
|
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, "Subtitle")
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "Artist")
|
.putString(METADATA_KEY_ARTIST, "Artist")
|
||||||
.build());
|
.build());
|
||||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
CountDownLatch countDownLatch = new CountDownLatch(1);
|
CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||||
@ -2163,7 +2126,7 @@ public class MediaControllerWithMediaSessionCompatTest {
|
|||||||
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, "mediaItem_2")
|
.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, "mediaItem_2")
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, "Title")
|
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, "Title")
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, "Subtitle")
|
.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, "Subtitle")
|
||||||
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "Artist")
|
.putString(METADATA_KEY_ARTIST, "Artist")
|
||||||
.build());
|
.build());
|
||||||
session.setQueue(testQueue);
|
session.setQueue(testQueue);
|
||||||
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
MediaController controller = controllerTestRule.createController(session.getSessionToken());
|
||||||
|
@ -42,7 +42,6 @@ import android.support.v4.media.session.MediaControllerCompat;
|
|||||||
import android.support.v4.media.session.MediaSessionCompat.QueueItem;
|
import android.support.v4.media.session.MediaSessionCompat.QueueItem;
|
||||||
import android.support.v4.media.session.PlaybackStateCompat;
|
import android.support.v4.media.session.PlaybackStateCompat;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import androidx.media.AudioAttributesCompat;
|
|
||||||
import androidx.media.AudioManagerCompat;
|
import androidx.media.AudioManagerCompat;
|
||||||
import androidx.media3.common.AudioAttributes;
|
import androidx.media3.common.AudioAttributes;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
@ -51,6 +50,7 @@ import androidx.media3.common.ForwardingPlayer;
|
|||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
import androidx.media3.common.Player;
|
import androidx.media3.common.Player;
|
||||||
import androidx.media3.common.Rating;
|
import androidx.media3.common.Rating;
|
||||||
|
import androidx.media3.common.StarRating;
|
||||||
import androidx.media3.common.util.Log;
|
import androidx.media3.common.util.Log;
|
||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.session.MediaSession.ControllerInfo;
|
import androidx.media3.session.MediaSession.ControllerInfo;
|
||||||
@ -161,7 +161,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
|
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
// Invoke any command for session to recognize the controller compat.
|
// Invoke any command for session to recognize the controller compat.
|
||||||
controller.getTransportControls().seekTo(111);
|
controller.getTransportControls().seekTo(111);
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
session.setLegacyControllerConnectionTimeoutMs(0);
|
session.setLegacyControllerConnectionTimeoutMs(0);
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
// Invoke any command for session to recognize the controller compat.
|
// Invoke any command for session to recognize the controller compat.
|
||||||
controller.getTransportControls().seekTo(111);
|
controller.getTransportControls().seekTo(111);
|
||||||
assertThat(disconnectedLatch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
assertThat(disconnectedLatch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||||
@ -223,7 +223,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().play();
|
controller.getTransportControls().play();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_PLAY, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_PLAY, TIMEOUT_MS);
|
||||||
@ -242,7 +242,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().play();
|
controller.getTransportControls().play();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_PREPARE, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_PREPARE, TIMEOUT_MS);
|
||||||
@ -263,7 +263,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().play();
|
controller.getTransportControls().play();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_PLAY, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_PLAY, TIMEOUT_MS);
|
||||||
@ -282,7 +282,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().play();
|
controller.getTransportControls().play();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_DEFAULT_POSITION, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_DEFAULT_POSITION, TIMEOUT_MS);
|
||||||
@ -307,7 +307,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().play();
|
controller.getTransportControls().play();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_PLAY, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_PLAY, TIMEOUT_MS);
|
||||||
@ -325,7 +325,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().pause();
|
controller.getTransportControls().pause();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_PAUSE, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_PAUSE, TIMEOUT_MS);
|
||||||
@ -340,7 +340,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().stop();
|
controller.getTransportControls().stop();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_STOP, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_STOP, TIMEOUT_MS);
|
||||||
@ -355,7 +355,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().prepare();
|
controller.getTransportControls().prepare();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_PREPARE, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_PREPARE, TIMEOUT_MS);
|
||||||
@ -370,7 +370,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
long seekPosition = 12125L;
|
long seekPosition = 12125L;
|
||||||
|
|
||||||
controller.getTransportControls().seekTo(seekPosition);
|
controller.getTransportControls().seekTo(seekPosition);
|
||||||
@ -388,7 +388,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
float testSpeed = 2.0f;
|
float testSpeed = 2.0f;
|
||||||
|
|
||||||
controller.getTransportControls().setPlaybackSpeed(testSpeed);
|
controller.getTransportControls().setPlaybackSpeed(testSpeed);
|
||||||
@ -406,7 +406,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().setPlaybackSpeed(-0.0001f);
|
controller.getTransportControls().setPlaybackSpeed(-0.0001f);
|
||||||
controller.getTransportControls().setPlaybackSpeed(Float.NaN);
|
controller.getTransportControls().setPlaybackSpeed(Float.NaN);
|
||||||
@ -437,7 +437,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
handler.postAndSync(
|
handler.postAndSync(
|
||||||
() -> {
|
() -> {
|
||||||
@ -483,7 +483,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
handler.postAndSync(
|
handler.postAndSync(
|
||||||
() -> {
|
() -> {
|
||||||
@ -529,7 +529,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
handler.postAndSync(
|
handler.postAndSync(
|
||||||
() -> {
|
() -> {
|
||||||
@ -561,7 +561,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(/* size= */ 10);
|
List<MediaItem> mediaItems = MediaTestUtils.createMediaItems(/* size= */ 10);
|
||||||
handler.postAndSync(
|
handler.postAndSync(
|
||||||
@ -591,7 +591,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().skipToPrevious();
|
controller.getTransportControls().skipToPrevious();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_PREVIOUS, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_PREVIOUS, TIMEOUT_MS);
|
||||||
@ -612,7 +612,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().skipToPrevious();
|
controller.getTransportControls().skipToPrevious();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_PREVIOUS_MEDIA_ITEM, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_PREVIOUS_MEDIA_ITEM, TIMEOUT_MS);
|
||||||
@ -627,7 +627,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().skipToNext();
|
controller.getTransportControls().skipToNext();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_NEXT, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_NEXT, TIMEOUT_MS);
|
||||||
@ -645,7 +645,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().skipToNext();
|
controller.getTransportControls().skipToNext();
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_NEXT_MEDIA_ITEM, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_SEEK_TO_NEXT_MEDIA_ITEM, TIMEOUT_MS);
|
||||||
@ -660,7 +660,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
handler.postAndSync(
|
handler.postAndSync(
|
||||||
() -> {
|
() -> {
|
||||||
@ -669,7 +669,8 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Get Queue from local MediaControllerCompat.
|
// Get Queue from local MediaControllerCompat.
|
||||||
List<QueueItem> queue = session.getSessionCompat().getController().getQueue();
|
List<QueueItem> queue =
|
||||||
|
new MediaControllerCompat(context, session.getSessionCompatToken()).getQueue();
|
||||||
int targetIndex = 3;
|
int targetIndex = 3;
|
||||||
controller.getTransportControls().skipToQueueItem(queue.get(targetIndex).getQueueId());
|
controller.getTransportControls().skipToQueueItem(queue.get(targetIndex).getQueueId());
|
||||||
player.awaitMethodCalled(
|
player.awaitMethodCalled(
|
||||||
@ -687,7 +688,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
handler.postAndSync(
|
handler.postAndSync(
|
||||||
() -> {
|
() -> {
|
||||||
player.timeline = MediaTestUtils.createTimeline(/* windowCount= */ 10);
|
player.timeline = MediaTestUtils.createTimeline(/* windowCount= */ 10);
|
||||||
@ -726,9 +727,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build()));
|
.build()));
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context,
|
context, session.get().getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
session.get().getSessionCompat().getSessionToken(),
|
|
||||||
/* waitForConnection= */ true);
|
|
||||||
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
||||||
|
|
||||||
session.get().getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
session.get().getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
||||||
@ -758,7 +757,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
session = new MediaSession.Builder(context, player).setId("dispatchMediaButtonEvent").build();
|
session = new MediaSession.Builder(context, player).setId("dispatchMediaButtonEvent").build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
||||||
|
|
||||||
session.getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
session.getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
||||||
@ -782,7 +781,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
session = new MediaSession.Builder(context, player).setId("dispatchMediaButtonEvent").build();
|
session = new MediaSession.Builder(context, player).setId("dispatchMediaButtonEvent").build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
||||||
|
|
||||||
session.getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
session.getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
||||||
@ -821,7 +820,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
||||||
|
|
||||||
session.getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
session.getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
||||||
@ -860,9 +859,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build()));
|
.build()));
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context,
|
context, session.get().getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
session.get().getSessionCompat().getSessionToken(),
|
|
||||||
/* waitForConnection= */ true);
|
|
||||||
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
||||||
Bundle connectionHints = new Bundle();
|
Bundle connectionHints = new Bundle();
|
||||||
connectionHints.putBoolean(MediaController.KEY_MEDIA_NOTIFICATION_CONTROLLER_FLAG, true);
|
connectionHints.putBoolean(MediaController.KEY_MEDIA_NOTIFICATION_CONTROLLER_FLAG, true);
|
||||||
@ -909,7 +906,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY);
|
||||||
|
|
||||||
session.getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
session.getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
||||||
@ -940,9 +937,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build()));
|
.build()));
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context,
|
context, session.get().getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
session.get().getSessionCompat().getSessionToken(),
|
|
||||||
/* waitForConnection= */ true);
|
|
||||||
|
|
||||||
session.get().getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
session.get().getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
||||||
player.awaitMethodCalled(MockPlayer.METHOD_PLAY, TIMEOUT_MS);
|
player.awaitMethodCalled(MockPlayer.METHOD_PLAY, TIMEOUT_MS);
|
||||||
@ -982,9 +977,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.get();
|
.get();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context,
|
context, session.get().getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
session.get().getSessionCompat().getSessionToken(),
|
|
||||||
/* waitForConnection= */ true);
|
|
||||||
|
|
||||||
session.get().getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
session.get().getSessionCompat().getController().dispatchMediaButtonEvent(keyEvent);
|
||||||
|
|
||||||
@ -1008,7 +1001,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
@PlaybackStateCompat.ShuffleMode int testShuffleMode = PlaybackStateCompat.SHUFFLE_MODE_GROUP;
|
@PlaybackStateCompat.ShuffleMode int testShuffleMode = PlaybackStateCompat.SHUFFLE_MODE_GROUP;
|
||||||
|
|
||||||
controller.getTransportControls().setShuffleMode(testShuffleMode);
|
controller.getTransportControls().setShuffleMode(testShuffleMode);
|
||||||
@ -1026,7 +1019,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
int testRepeatMode = Player.REPEAT_MODE_ALL;
|
int testRepeatMode = Player.REPEAT_MODE_ALL;
|
||||||
|
|
||||||
controller.getTransportControls().setRepeatMode(testRepeatMode);
|
controller.getTransportControls().setRepeatMode(testRepeatMode);
|
||||||
@ -1044,7 +1037,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
MockPlayer remotePlayer =
|
MockPlayer remotePlayer =
|
||||||
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
||||||
remotePlayer.commands =
|
remotePlayer.commands =
|
||||||
@ -1076,7 +1069,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
MockPlayer remotePlayer =
|
MockPlayer remotePlayer =
|
||||||
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
||||||
remotePlayer.commands = new Player.Commands.Builder().addAllCommands().build();
|
remotePlayer.commands = new Player.Commands.Builder().addAllCommands().build();
|
||||||
@ -1104,7 +1097,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
MockPlayer remotePlayer =
|
MockPlayer remotePlayer =
|
||||||
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
||||||
remotePlayer.commands =
|
remotePlayer.commands =
|
||||||
@ -1133,7 +1126,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
MockPlayer remotePlayer =
|
MockPlayer remotePlayer =
|
||||||
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
||||||
handler.postAndSync(
|
handler.postAndSync(
|
||||||
@ -1157,7 +1150,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
MockPlayer remotePlayer =
|
MockPlayer remotePlayer =
|
||||||
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
||||||
remotePlayer.commands =
|
remotePlayer.commands =
|
||||||
@ -1186,7 +1179,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
MockPlayer remotePlayer =
|
MockPlayer remotePlayer =
|
||||||
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
new MockPlayer.Builder().setApplicationLooper(handler.getLooper()).build();
|
||||||
remotePlayer.commands = new Player.Commands.Builder().addAllCommands().build();
|
remotePlayer.commands = new Player.Commands.Builder().addAllCommands().build();
|
||||||
@ -1216,7 +1209,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
// Here, we intentionally choose STREAM_ALARM in order not to consider
|
// Here, we intentionally choose STREAM_ALARM in order not to consider
|
||||||
// 'Do Not Disturb' or 'Volume limit'.
|
// 'Do Not Disturb' or 'Volume limit'.
|
||||||
@ -1232,8 +1225,10 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
() -> {
|
() -> {
|
||||||
// Set stream of the session.
|
// Set stream of the session.
|
||||||
AudioAttributes attrs =
|
AudioAttributes attrs =
|
||||||
LegacyConversions.convertToAudioAttributes(
|
new AudioAttributes.Builder()
|
||||||
new AudioAttributesCompat.Builder().setLegacyStreamType(stream).build());
|
.setUsage(C.USAGE_ALARM)
|
||||||
|
.setContentType(C.AUDIO_CONTENT_TYPE_SONIFICATION)
|
||||||
|
.build();
|
||||||
player.audioAttributes = attrs;
|
player.audioAttributes = attrs;
|
||||||
player.notifyAudioAttributesChanged(attrs);
|
player.notifyAudioAttributesChanged(attrs);
|
||||||
});
|
});
|
||||||
@ -1264,7 +1259,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
// Here, we intentionally choose STREAM_ALARM in order not to consider
|
// Here, we intentionally choose STREAM_ALARM in order not to consider
|
||||||
// 'Do Not Disturb' or 'Volume limit'.
|
// 'Do Not Disturb' or 'Volume limit'.
|
||||||
@ -1280,8 +1275,10 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
() -> {
|
() -> {
|
||||||
// Set stream of the session.
|
// Set stream of the session.
|
||||||
AudioAttributes attrs =
|
AudioAttributes attrs =
|
||||||
LegacyConversions.convertToAudioAttributes(
|
new AudioAttributes.Builder()
|
||||||
new AudioAttributesCompat.Builder().setLegacyStreamType(stream).build());
|
.setUsage(C.USAGE_ALARM)
|
||||||
|
.setContentType(C.AUDIO_CONTENT_TYPE_SONIFICATION)
|
||||||
|
.build();
|
||||||
player.audioAttributes = attrs;
|
player.audioAttributes = attrs;
|
||||||
player.notifyAudioAttributesChanged(attrs);
|
player.notifyAudioAttributesChanged(attrs);
|
||||||
});
|
});
|
||||||
@ -1345,7 +1342,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.sendCommand(testCommand, testArgs, /* cb= */ null);
|
controller.sendCommand(testCommand, testArgs, /* cb= */ null);
|
||||||
|
|
||||||
@ -1397,7 +1394,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.sendCustomCommand(customCommand, testArgs);
|
controller.sendCustomCommand(customCommand, testArgs);
|
||||||
|
|
||||||
@ -1422,7 +1419,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
// Session will not accept the controller's commands.
|
// Session will not accept the controller's commands.
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().play();
|
controller.getTransportControls().play();
|
||||||
|
|
||||||
@ -1454,7 +1451,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().prepareFromUri(mediaUri, bundle);
|
controller.getTransportControls().prepareFromUri(mediaUri, bundle);
|
||||||
|
|
||||||
@ -1490,7 +1487,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().playFromUri(request, bundle);
|
controller.getTransportControls().playFromUri(request, bundle);
|
||||||
|
|
||||||
@ -1527,7 +1524,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().prepareFromMediaId(request, bundle);
|
controller.getTransportControls().prepareFromMediaId(request, bundle);
|
||||||
|
|
||||||
@ -1571,7 +1568,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().prepareFromMediaId(request, bundle);
|
controller.getTransportControls().prepareFromMediaId(request, bundle);
|
||||||
|
|
||||||
@ -1609,7 +1606,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().playFromMediaId(mediaId, bundle);
|
controller.getTransportControls().playFromMediaId(mediaId, bundle);
|
||||||
|
|
||||||
@ -1652,7 +1649,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().playFromMediaId(mediaId, bundle);
|
controller.getTransportControls().playFromMediaId(mediaId, bundle);
|
||||||
|
|
||||||
@ -1688,7 +1685,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().prepareFromSearch(query, bundle);
|
controller.getTransportControls().prepareFromSearch(query, bundle);
|
||||||
|
|
||||||
@ -1724,7 +1721,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().playFromSearch(query, bundle);
|
controller.getTransportControls().playFromSearch(query, bundle);
|
||||||
|
|
||||||
@ -1758,7 +1755,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().prepareFromUri(Uri.parse("foo://bar"), Bundle.EMPTY);
|
controller.getTransportControls().prepareFromUri(Uri.parse("foo://bar"), Bundle.EMPTY);
|
||||||
|
|
||||||
@ -1788,7 +1785,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().playFromUri(Uri.parse("foo://bar"), Bundle.EMPTY);
|
controller.getTransportControls().playFromUri(Uri.parse("foo://bar"), Bundle.EMPTY);
|
||||||
|
|
||||||
@ -1822,7 +1819,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().playFromUri(Uri.parse("foo://bar"), Bundle.EMPTY);
|
controller.getTransportControls().playFromUri(Uri.parse("foo://bar"), Bundle.EMPTY);
|
||||||
|
|
||||||
@ -1849,7 +1846,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
String mediaIdOut,
|
String mediaIdOut,
|
||||||
Rating ratingOut) {
|
Rating ratingOut) {
|
||||||
assertThat(mediaIdOut).isEqualTo(mediaId);
|
assertThat(mediaIdOut).isEqualTo(mediaId);
|
||||||
assertThat(ratingOut).isEqualTo(LegacyConversions.convertToRating(rating));
|
assertThat(ratingOut).isEqualTo(new StarRating(5, 3.5f));
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
return Futures.immediateFuture(new SessionResult(RESULT_SUCCESS));
|
return Futures.immediateFuture(new SessionResult(RESULT_SUCCESS));
|
||||||
}
|
}
|
||||||
@ -1863,7 +1860,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
new MediaSession.Builder(context, player).setId("setRating").setCallback(callback).build();
|
new MediaSession.Builder(context, player).setId("setRating").setCallback(callback).build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().setRating(rating);
|
controller.getTransportControls().setRating(rating);
|
||||||
|
|
||||||
@ -1896,7 +1893,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
|
|
||||||
controller.getTransportControls().pause();
|
controller.getTransportControls().pause();
|
||||||
|
|
||||||
@ -1925,7 +1922,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
// This may hang if deadlock happens.
|
// This may hang if deadlock happens.
|
||||||
handler.postAndSync(
|
handler.postAndSync(
|
||||||
() -> {
|
() -> {
|
||||||
@ -1960,7 +1957,7 @@ public class MediaSessionCallbackWithMediaControllerCompatTest {
|
|||||||
.build();
|
.build();
|
||||||
controller =
|
controller =
|
||||||
new RemoteMediaControllerCompat(
|
new RemoteMediaControllerCompat(
|
||||||
context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */ true);
|
context, session.getSessionCompatToken(), /* waitForConnection= */ true);
|
||||||
session.release();
|
session.release();
|
||||||
session = null;
|
session = null;
|
||||||
|
|
||||||
|
@ -717,7 +717,8 @@ public class MediaSessionCompatCallbackWithMediaControllerTest {
|
|||||||
controller.setRating(mediaId, rating);
|
controller.setRating(mediaId, rating);
|
||||||
assertThat(sessionCallback.await(TIMEOUT_MS)).isTrue();
|
assertThat(sessionCallback.await(TIMEOUT_MS)).isTrue();
|
||||||
assertThat(sessionCallback.onSetRatingCalled).isTrue();
|
assertThat(sessionCallback.onSetRatingCalled).isTrue();
|
||||||
assertThat(LegacyConversions.convertToRating(sessionCallback.rating)).isEqualTo(rating);
|
assertThat(sessionCallback.rating.getRatingStyle()).isEqualTo(RatingCompat.RATING_5_STARS);
|
||||||
|
assertThat(sessionCallback.rating.getStarRating()).isEqualTo(3.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -730,7 +731,8 @@ public class MediaSessionCompatCallbackWithMediaControllerTest {
|
|||||||
controller.setRating(rating);
|
controller.setRating(rating);
|
||||||
assertThat(sessionCallback.await(TIMEOUT_MS)).isTrue();
|
assertThat(sessionCallback.await(TIMEOUT_MS)).isTrue();
|
||||||
assertThat(sessionCallback.onSetRatingCalled).isTrue();
|
assertThat(sessionCallback.onSetRatingCalled).isTrue();
|
||||||
assertThat(LegacyConversions.convertToRating(sessionCallback.rating)).isEqualTo(rating);
|
assertThat(sessionCallback.rating.getRatingStyle()).isEqualTo(RatingCompat.RATING_5_STARS);
|
||||||
|
assertThat(sessionCallback.rating.getStarRating()).isEqualTo(3.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1082,7 +1082,8 @@ public class MediaSessionPlayerTest {
|
|||||||
Context context = ApplicationProvider.getApplicationContext();
|
Context context = ApplicationProvider.getApplicationContext();
|
||||||
MediaSession session = new MediaSession.Builder(context, player).setId("test").build();
|
MediaSession session = new MediaSession.Builder(context, player).setId("test").build();
|
||||||
sessionReference.set(session);
|
sessionReference.set(session);
|
||||||
MediaControllerCompat controller = session.getSessionCompat().getController();
|
MediaControllerCompat controller =
|
||||||
|
new MediaControllerCompat(context, session.getSessionCompatToken());
|
||||||
|
|
||||||
controller.getTransportControls().play();
|
controller.getTransportControls().play();
|
||||||
eventHandled.await();
|
eventHandled.await();
|
||||||
@ -1136,7 +1137,8 @@ public class MediaSessionPlayerTest {
|
|||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
sessionReference.set(session);
|
sessionReference.set(session);
|
||||||
MediaControllerCompat controller = session.getSessionCompat().getController();
|
MediaControllerCompat controller =
|
||||||
|
new MediaControllerCompat(context, session.getSessionCompatToken());
|
||||||
|
|
||||||
controller.getTransportControls().playFromUri(Uri.parse("test://"), Bundle.EMPTY);
|
controller.getTransportControls().playFromUri(Uri.parse("test://"), Bundle.EMPTY);
|
||||||
eventHandled.await();
|
eventHandled.await();
|
||||||
@ -1192,7 +1194,8 @@ public class MediaSessionPlayerTest {
|
|||||||
|
|
||||||
MainLooperTestRule.runOnMainSync(
|
MainLooperTestRule.runOnMainSync(
|
||||||
() -> {
|
() -> {
|
||||||
MediaControllerCompat controller = session.getSessionCompat().getController();
|
MediaControllerCompat controller =
|
||||||
|
new MediaControllerCompat(context, session.getSessionCompatToken());
|
||||||
controller.addQueueItem(new MediaDescriptionCompat.Builder().setMediaId("id").build());
|
controller.addQueueItem(new MediaDescriptionCompat.Builder().setMediaId("id").build());
|
||||||
});
|
});
|
||||||
eventHandled.await();
|
eventHandled.await();
|
||||||
|
@ -298,9 +298,19 @@ public class MediaSessionServiceTest {
|
|||||||
TestServiceRegistry.getInstance().setOnGetSessionHandler(controllerInfo -> mediaSession);
|
TestServiceRegistry.getInstance().setOnGetSessionHandler(controllerInfo -> mediaSession);
|
||||||
MediaControllerCompat mediaControllerCompat =
|
MediaControllerCompat mediaControllerCompat =
|
||||||
new MediaControllerCompat(
|
new MediaControllerCompat(
|
||||||
ApplicationProvider.getApplicationContext(), mediaSession.getSessionCompat());
|
ApplicationProvider.getApplicationContext(), mediaSession.getSessionCompatToken());
|
||||||
ImmutableList<CommandButton> initialCustomLayoutInControllerCompat =
|
CountDownLatch controllerReady = new CountDownLatch(1);
|
||||||
LegacyConversions.convertToCustomLayout(mediaControllerCompat.getPlaybackState());
|
mediaControllerCompat.registerCallback(
|
||||||
|
new MediaControllerCompat.Callback() {
|
||||||
|
@Override
|
||||||
|
public void onSessionReady() {
|
||||||
|
controllerReady.countDown();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Handler(Looper.getMainLooper()));
|
||||||
|
controllerReady.await();
|
||||||
|
List<PlaybackStateCompat.CustomAction> initialCustomActionsInControllerCompat =
|
||||||
|
mediaControllerCompat.getPlaybackState().getCustomActions();
|
||||||
|
|
||||||
// Start the service by creating a remote controller.
|
// Start the service by creating a remote controller.
|
||||||
RemoteMediaController remoteController =
|
RemoteMediaController remoteController =
|
||||||
@ -322,10 +332,18 @@ public class MediaSessionServiceTest {
|
|||||||
assertThat(remoteController.getCustomLayout())
|
assertThat(remoteController.getCustomLayout())
|
||||||
.containsExactly(button1.copyWithIsEnabled(false), button2.copyWithIsEnabled(false))
|
.containsExactly(button1.copyWithIsEnabled(false), button2.copyWithIsEnabled(false))
|
||||||
.inOrder();
|
.inOrder();
|
||||||
assertThat(initialCustomLayoutInControllerCompat).isEmpty();
|
assertThat(initialCustomActionsInControllerCompat).isEmpty();
|
||||||
assertThat(LegacyConversions.convertToCustomLayout(mediaControllerCompat.getPlaybackState()))
|
assertThat(mediaControllerCompat.getPlaybackState().getCustomActions()).hasSize(2);
|
||||||
.containsExactly(button1.copyWithIsEnabled(true), button3.copyWithIsEnabled(true))
|
PlaybackStateCompat.CustomAction customAction1 =
|
||||||
.inOrder();
|
mediaControllerCompat.getPlaybackState().getCustomActions().get(0);
|
||||||
|
PlaybackStateCompat.CustomAction customAction2 =
|
||||||
|
mediaControllerCompat.getPlaybackState().getCustomActions().get(1);
|
||||||
|
assertThat(customAction1.getAction()).isEqualTo("command1");
|
||||||
|
assertThat(customAction1.getName().toString()).isEqualTo("button1");
|
||||||
|
assertThat(customAction1.getIcon()).isEqualTo(R.drawable.media3_notification_small_icon);
|
||||||
|
assertThat(customAction2.getAction()).isEqualTo("command3");
|
||||||
|
assertThat(customAction2.getName().toString()).isEqualTo("button3");
|
||||||
|
assertThat(customAction2.getIcon()).isEqualTo(R.drawable.media3_notification_small_icon);
|
||||||
mediaSession.release();
|
mediaSession.release();
|
||||||
((MockMediaSessionService) TestServiceRegistry.getInstance().getServiceInstance())
|
((MockMediaSessionService) TestServiceRegistry.getInstance().getServiceInstance())
|
||||||
.blockUntilAllControllersUnbind(TIMEOUT_MS);
|
.blockUntilAllControllersUnbind(TIMEOUT_MS);
|
||||||
|
@ -990,15 +990,13 @@ public class MediaSessionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static ControllerInfo createMediaButtonCaller() {
|
private static ControllerInfo createMediaButtonCaller() {
|
||||||
return new ControllerInfo(
|
return ControllerInfo.createTestOnlyControllerInfo(
|
||||||
new MediaSessionManager.RemoteUserInfo(
|
|
||||||
"RANDOM_MEDIA_BUTTON_CALLER_PACKAGE",
|
"RANDOM_MEDIA_BUTTON_CALLER_PACKAGE",
|
||||||
MediaSessionManager.RemoteUserInfo.UNKNOWN_PID,
|
MediaSessionManager.RemoteUserInfo.UNKNOWN_PID,
|
||||||
MediaSessionManager.RemoteUserInfo.UNKNOWN_UID),
|
MediaSessionManager.RemoteUserInfo.UNKNOWN_UID,
|
||||||
MediaLibraryInfo.VERSION_INT,
|
MediaLibraryInfo.VERSION_INT,
|
||||||
MediaControllerStub.VERSION_INT,
|
MediaControllerStub.VERSION_INT,
|
||||||
/* trusted= */ false,
|
/* trusted= */ false,
|
||||||
/* cb= */ null,
|
|
||||||
/* connectionHints= */ Bundle.EMPTY);
|
/* connectionHints= */ Bundle.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,8 +87,7 @@ public class MediaSessionWithMediaControllerCompatTest {
|
|||||||
sessionTestRule.ensureReleaseAfterTest(
|
sessionTestRule.ensureReleaseAfterTest(
|
||||||
new MediaSession.Builder(context, player).setId(TAG).setCallback(callback).build());
|
new MediaSession.Builder(context, player).setId(TAG).setCallback(callback).build());
|
||||||
RemoteMediaControllerCompat controllerCompat =
|
RemoteMediaControllerCompat controllerCompat =
|
||||||
remoteControllerTestRule.createRemoteControllerCompat(
|
remoteControllerTestRule.createRemoteControllerCompat(session.getSessionCompatToken());
|
||||||
session.getSessionCompat().getSessionToken());
|
|
||||||
// Invoke any command for session to recognize the controller compat.
|
// Invoke any command for session to recognize the controller compat.
|
||||||
controllerCompat.getTransportControls().prepare();
|
controllerCompat.getTransportControls().prepare();
|
||||||
|
|
||||||
@ -131,8 +130,7 @@ public class MediaSessionWithMediaControllerCompatTest {
|
|||||||
.get();
|
.get();
|
||||||
|
|
||||||
RemoteMediaControllerCompat controllerCompat =
|
RemoteMediaControllerCompat controllerCompat =
|
||||||
remoteControllerTestRule.createRemoteControllerCompat(
|
remoteControllerTestRule.createRemoteControllerCompat(session.getSessionCompatToken());
|
||||||
session.getSessionCompat().getSessionToken());
|
|
||||||
controllerCompat.transportControls.play();
|
controllerCompat.transportControls.play();
|
||||||
|
|
||||||
assertThat(connectedLatch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
assertThat(connectedLatch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
|
||||||
@ -143,8 +141,7 @@ public class MediaSessionWithMediaControllerCompatTest {
|
|||||||
SessionCommands.EMPTY,
|
SessionCommands.EMPTY,
|
||||||
Player.Commands.EMPTY.buildUpon().add(Player.COMMAND_GET_TIMELINE).build());
|
Player.Commands.EMPTY.buildUpon().add(Player.COMMAND_GET_TIMELINE).build());
|
||||||
RemoteMediaControllerCompat controllerCompat2 =
|
RemoteMediaControllerCompat controllerCompat2 =
|
||||||
remoteControllerTestRule.createRemoteControllerCompat(
|
remoteControllerTestRule.createRemoteControllerCompat(session.getSessionCompatToken());
|
||||||
session.getSessionCompat().getSessionToken());
|
|
||||||
controllerCompat2.transportControls.pause();
|
controllerCompat2.transportControls.pause();
|
||||||
|
|
||||||
assertThat(controllerCompat.getQueueSize()).isEqualTo(2);
|
assertThat(controllerCompat.getQueueSize()).isEqualTo(2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user