mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Formatting fixes and additional plumbin in legacy controller
This commit is contained in:
parent
63103978be
commit
cd2250b5fa
@ -6,6 +6,9 @@
|
|||||||
* ExoPlayer:
|
* ExoPlayer:
|
||||||
* Add `ExoPlayer.isReleased()` to check whether `Exoplayer.release()` has
|
* Add `ExoPlayer.isReleased()` to check whether `Exoplayer.release()` has
|
||||||
been called.
|
been called.
|
||||||
|
* Add `ExoPlayer.Builder.setMaxSeekToPreviousPositionMs` to configure the
|
||||||
|
maximum position for which `seekToPrevious()` seeks to the previous item
|
||||||
|
([#1425](https://github.com/androidx/media/issues/1425)).
|
||||||
* Transformer:
|
* Transformer:
|
||||||
* Remove `ExportResult.processedInputs` field. If you use this field for
|
* Remove `ExportResult.processedInputs` field. If you use this field for
|
||||||
codec details, then use `DefaultDecoderFactory.listener` instead. In
|
codec details, then use `DefaultDecoderFactory.listener` instead. In
|
||||||
|
@ -217,7 +217,7 @@ public final class CastPlayer extends BasePlayer {
|
|||||||
* @param seekBackIncrementMs The {@link #seekBack()} increment, in milliseconds.
|
* @param seekBackIncrementMs The {@link #seekBack()} increment, in milliseconds.
|
||||||
* @param seekForwardIncrementMs The {@link #seekForward()} increment, in milliseconds.
|
* @param seekForwardIncrementMs The {@link #seekForward()} increment, in milliseconds.
|
||||||
* @param maxSeekToPreviousPositionMs The maximum position for which {@link #seekToPrevious()}
|
* @param maxSeekToPreviousPositionMs The maximum position for which {@link #seekToPrevious()}
|
||||||
* seeks to the previous {@link MediaItem}, in milliseconds.
|
* seeks to the previous {@link MediaItem}, in milliseconds.
|
||||||
* @throws IllegalArgumentException If {@code seekBackIncrementMs} or {@code
|
* @throws IllegalArgumentException If {@code seekBackIncrementMs} or {@code
|
||||||
* seekForwardIncrementMs} is non-positive, or if {@code maxSeekToPreviousPositionMs} is
|
* seekForwardIncrementMs} is non-positive, or if {@code maxSeekToPreviousPositionMs} is
|
||||||
* negative.
|
* negative.
|
||||||
|
@ -543,6 +543,7 @@ public interface ExoPlayer extends Player {
|
|||||||
* <li>{@link SeekParameters}: {@link SeekParameters#DEFAULT}
|
* <li>{@link SeekParameters}: {@link SeekParameters#DEFAULT}
|
||||||
* <li>{@code seekBackIncrementMs}: {@link C#DEFAULT_SEEK_BACK_INCREMENT_MS}
|
* <li>{@code seekBackIncrementMs}: {@link C#DEFAULT_SEEK_BACK_INCREMENT_MS}
|
||||||
* <li>{@code seekForwardIncrementMs}: {@link C#DEFAULT_SEEK_FORWARD_INCREMENT_MS}
|
* <li>{@code seekForwardIncrementMs}: {@link C#DEFAULT_SEEK_FORWARD_INCREMENT_MS}
|
||||||
|
* <li>{@code maxSeekToPreviousPositionMs}: {@link C#DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS}
|
||||||
* <li>{@code releaseTimeoutMs}: {@link #DEFAULT_RELEASE_TIMEOUT_MS}
|
* <li>{@code releaseTimeoutMs}: {@link #DEFAULT_RELEASE_TIMEOUT_MS}
|
||||||
* <li>{@code detachSurfaceTimeoutMs}: {@link #DEFAULT_DETACH_SURFACE_TIMEOUT_MS}
|
* <li>{@code detachSurfaceTimeoutMs}: {@link #DEFAULT_DETACH_SURFACE_TIMEOUT_MS}
|
||||||
* <li>{@code pauseAtEndOfMediaItems}: {@code false}
|
* <li>{@code pauseAtEndOfMediaItems}: {@code false}
|
||||||
@ -1137,7 +1138,8 @@ public interface ExoPlayer extends Player {
|
|||||||
*/
|
*/
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public Builder setMaxSeekToPreviousPosition(long maxSeekToPreviousPositionMs) {
|
public Builder setMaxSeekToPreviousPositionMs(
|
||||||
|
@IntRange(from = 0) long maxSeekToPreviousPositionMs) {
|
||||||
checkArgument(maxSeekToPreviousPositionMs >= 0L);
|
checkArgument(maxSeekToPreviousPositionMs >= 0L);
|
||||||
checkState(!buildCalled);
|
checkState(!buildCalled);
|
||||||
this.maxSeekToPreviousPositionMs = maxSeekToPreviousPositionMs;
|
this.maxSeekToPreviousPositionMs = maxSeekToPreviousPositionMs;
|
||||||
|
@ -12990,9 +12990,12 @@ public class ExoPlayerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void seekToPrevious_withPreviousWindowAndCloseToStart_seeksToPreviousWindow() {
|
public void seekToPrevious_withPreviousWindowAndCloseToStart_seeksToPreviousWindow() {
|
||||||
ExoPlayer player = parameterizeTestExoPlayerBuilder(new TestExoPlayerBuilder(context)).build();
|
ExoPlayer player =
|
||||||
|
parameterizeTestExoPlayerBuilder(
|
||||||
|
new TestExoPlayerBuilder(context).setMaxSeekToPreviousPositionMs(10_000))
|
||||||
|
.build();
|
||||||
player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()));
|
player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()));
|
||||||
player.seekTo(/* mediaItemIndex= */ 1, C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS);
|
player.seekTo(/* mediaItemIndex= */ 1, 10_000);
|
||||||
|
|
||||||
player.seekToPrevious();
|
player.seekToPrevious();
|
||||||
|
|
||||||
@ -13004,9 +13007,12 @@ public class ExoPlayerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void seekToPrevious_notCloseToStart_seeksToZero() {
|
public void seekToPrevious_notCloseToStart_seeksToZero() {
|
||||||
ExoPlayer player = parameterizeTestExoPlayerBuilder(new TestExoPlayerBuilder(context)).build();
|
ExoPlayer player =
|
||||||
|
parameterizeTestExoPlayerBuilder(
|
||||||
|
new TestExoPlayerBuilder(context).setMaxSeekToPreviousPositionMs(10_000))
|
||||||
|
.build();
|
||||||
player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()));
|
player.addMediaSources(ImmutableList.of(new FakeMediaSource(), new FakeMediaSource()));
|
||||||
player.seekTo(/* mediaItemIndex= */ 1, C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS + 1);
|
player.seekTo(/* mediaItemIndex= */ 1, 10_001);
|
||||||
|
|
||||||
player.seekToPrevious();
|
player.seekToPrevious();
|
||||||
|
|
||||||
|
@ -173,7 +173,9 @@ import java.util.List;
|
|||||||
@Nullable Bundle sessionExtras = bundle.getBundle(FIELD_SESSION_EXTRAS);
|
@Nullable Bundle sessionExtras = bundle.getBundle(FIELD_SESSION_EXTRAS);
|
||||||
@Nullable Bundle playerInfoBundle = bundle.getBundle(FIELD_PLAYER_INFO);
|
@Nullable Bundle playerInfoBundle = bundle.getBundle(FIELD_PLAYER_INFO);
|
||||||
PlayerInfo playerInfo =
|
PlayerInfo playerInfo =
|
||||||
playerInfoBundle == null ? PlayerInfo.DEFAULT : PlayerInfo.fromBundle(playerInfoBundle);
|
playerInfoBundle == null
|
||||||
|
? PlayerInfo.DEFAULT
|
||||||
|
: PlayerInfo.fromBundle(playerInfoBundle, sessionInterfaceVersion);
|
||||||
return new ConnectionState(
|
return new ConnectionState(
|
||||||
libraryVersion,
|
libraryVersion,
|
||||||
sessionInterfaceVersion,
|
sessionInterfaceVersion,
|
||||||
|
@ -2132,6 +2132,7 @@ import org.checkerframework.checker.initialization.qual.UnderInitialization;
|
|||||||
LegacyConversions.convertToIsDeviceMuted(newLegacyPlayerInfo.playbackInfoCompat);
|
LegacyConversions.convertToIsDeviceMuted(newLegacyPlayerInfo.playbackInfoCompat);
|
||||||
long seekBackIncrementMs = oldControllerInfo.playerInfo.seekBackIncrementMs;
|
long seekBackIncrementMs = oldControllerInfo.playerInfo.seekBackIncrementMs;
|
||||||
long seekForwardIncrementMs = oldControllerInfo.playerInfo.seekForwardIncrementMs;
|
long seekForwardIncrementMs = oldControllerInfo.playerInfo.seekForwardIncrementMs;
|
||||||
|
long maxSeekToPreviousPositionMs = oldControllerInfo.playerInfo.maxSeekToPreviousPositionMs;
|
||||||
|
|
||||||
return createControllerInfo(
|
return createControllerInfo(
|
||||||
currentTimeline,
|
currentTimeline,
|
||||||
@ -2161,7 +2162,8 @@ import org.checkerframework.checker.initialization.qual.UnderInitialization;
|
|||||||
deviceVolume,
|
deviceVolume,
|
||||||
deviceMuted,
|
deviceMuted,
|
||||||
seekBackIncrementMs,
|
seekBackIncrementMs,
|
||||||
seekForwardIncrementMs);
|
seekForwardIncrementMs,
|
||||||
|
maxSeekToPreviousPositionMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2330,7 +2332,8 @@ import org.checkerframework.checker.initialization.qual.UnderInitialization;
|
|||||||
int deviceVolume,
|
int deviceVolume,
|
||||||
boolean deviceMuted,
|
boolean deviceMuted,
|
||||||
long seekBackIncrementMs,
|
long seekBackIncrementMs,
|
||||||
long seekForwardIncrementMs) {
|
long seekForwardIncrementMs,
|
||||||
|
long maxSeekToPreviousPositionMs) {
|
||||||
|
|
||||||
@Nullable MediaItem currentMediaItem = currentTimeline.getMediaItemAt(currentMediaItemIndex);
|
@Nullable MediaItem currentMediaItem = currentTimeline.getMediaItemAt(currentMediaItemIndex);
|
||||||
PositionInfo positionInfo =
|
PositionInfo positionInfo =
|
||||||
@ -2379,7 +2382,7 @@ import org.checkerframework.checker.initialization.qual.UnderInitialization;
|
|||||||
/* mediaMetadata= */ mediaMetadata,
|
/* mediaMetadata= */ mediaMetadata,
|
||||||
seekBackIncrementMs,
|
seekBackIncrementMs,
|
||||||
seekForwardIncrementMs,
|
seekForwardIncrementMs,
|
||||||
/* maxSeekToPreviousPositionMs= */ 0L,
|
maxSeekToPreviousPositionMs,
|
||||||
/* currentTracks= */ Tracks.EMPTY,
|
/* currentTracks= */ Tracks.EMPTY,
|
||||||
/* parameters= */ TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT);
|
/* parameters= */ TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT);
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import android.os.Handler;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.Player.Commands;
|
import androidx.media3.common.Player.Commands;
|
||||||
import androidx.media3.common.util.BundleCollectionUtil;
|
import androidx.media3.common.util.BundleCollectionUtil;
|
||||||
import androidx.media3.common.util.Log;
|
import androidx.media3.common.util.Log;
|
||||||
@ -38,7 +39,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
private static final String TAG = "MediaControllerStub";
|
private static final String TAG = "MediaControllerStub";
|
||||||
|
|
||||||
/** The version of the IMediaController interface. */
|
/** The version of the IMediaController interface. */
|
||||||
public static final int VERSION_INT = 5;
|
public static final int VERSION_INT = 6;
|
||||||
|
|
||||||
private final WeakReference<MediaControllerImplBase> controller;
|
private final WeakReference<MediaControllerImplBase> controller;
|
||||||
|
|
||||||
@ -112,14 +113,11 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
}
|
}
|
||||||
List<CommandButton> layout;
|
List<CommandButton> layout;
|
||||||
try {
|
try {
|
||||||
@Nullable MediaControllerImplBase controller = this.controller.get();
|
int sessionInterfaceVersion = getSessionInterfaceVersion();
|
||||||
@Nullable
|
if (sessionInterfaceVersion == C.INDEX_UNSET) {
|
||||||
SessionToken connectedToken = controller == null ? null : controller.getConnectedToken();
|
|
||||||
if (connectedToken == null) {
|
|
||||||
// Stale event.
|
// Stale event.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int sessionInterfaceVersion = connectedToken.getInterfaceVersion();
|
|
||||||
layout =
|
layout =
|
||||||
BundleCollectionUtil.fromBundleList(
|
BundleCollectionUtil.fromBundleList(
|
||||||
bundle -> CommandButton.fromBundle(bundle, sessionInterfaceVersion),
|
bundle -> CommandButton.fromBundle(bundle, sessionInterfaceVersion),
|
||||||
@ -239,7 +237,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
}
|
}
|
||||||
PlayerInfo playerInfo;
|
PlayerInfo playerInfo;
|
||||||
try {
|
try {
|
||||||
playerInfo = PlayerInfo.fromBundle(playerInfoBundle);
|
int sessionInterfaceVersion = getSessionInterfaceVersion();
|
||||||
|
if (sessionInterfaceVersion == C.INDEX_UNSET) {
|
||||||
|
// Stale event.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
playerInfo = PlayerInfo.fromBundle(playerInfoBundle, sessionInterfaceVersion);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
Log.w(TAG, "Ignoring malformed Bundle for PlayerInfo", e);
|
Log.w(TAG, "Ignoring malformed Bundle for PlayerInfo", e);
|
||||||
return;
|
return;
|
||||||
@ -375,6 +378,20 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns session interface version or {@link C#INDEX_UNSET} for stale events. */
|
||||||
|
private int getSessionInterfaceVersion() {
|
||||||
|
@Nullable MediaControllerImplBase controller = this.controller.get();
|
||||||
|
if (controller == null) {
|
||||||
|
return C.INDEX_UNSET;
|
||||||
|
}
|
||||||
|
@Nullable SessionToken connectedToken = controller.getConnectedToken();
|
||||||
|
if (connectedToken == null) {
|
||||||
|
// Stale event.
|
||||||
|
return C.INDEX_UNSET;
|
||||||
|
}
|
||||||
|
return connectedToken.getInterfaceVersion();
|
||||||
|
}
|
||||||
|
|
||||||
/* @FunctionalInterface */
|
/* @FunctionalInterface */
|
||||||
private interface ControllerTask<T extends MediaControllerImplBase> {
|
private interface ControllerTask<T extends MediaControllerImplBase> {
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
private static final String TAG = "MediaSessionStub";
|
private static final String TAG = "MediaSessionStub";
|
||||||
|
|
||||||
/** The version of the IMediaSession interface. */
|
/** The version of the IMediaSession interface. */
|
||||||
public static final int VERSION_INT = 3;
|
public static final int VERSION_INT = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sequence number used when a controller method is triggered on the sesison side that wasn't
|
* Sequence number used when a controller method is triggered on the sesison side that wasn't
|
||||||
|
@ -30,6 +30,7 @@ import androidx.annotation.FloatRange;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.media3.common.AudioAttributes;
|
import androidx.media3.common.AudioAttributes;
|
||||||
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.DeviceInfo;
|
import androidx.media3.common.DeviceInfo;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
import androidx.media3.common.MediaMetadata;
|
import androidx.media3.common.MediaMetadata;
|
||||||
@ -457,9 +458,9 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
|||||||
/* isPlaying= */ false,
|
/* isPlaying= */ false,
|
||||||
/* isLoading= */ false,
|
/* isLoading= */ false,
|
||||||
MediaMetadata.EMPTY,
|
MediaMetadata.EMPTY,
|
||||||
/* seekBackIncrementMs= */ 0,
|
/* seekBackIncrementMs= */ C.DEFAULT_SEEK_BACK_INCREMENT_MS,
|
||||||
/* seekForwardIncrementMs= */ 0,
|
/* seekForwardIncrementMs= */ C.DEFAULT_SEEK_FORWARD_INCREMENT_MS,
|
||||||
/* maxSeekToPreviousPositionMs= */ 0,
|
/* maxSeekToPreviousPositionMs= */ C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS,
|
||||||
/* currentTracks= */ Tracks.EMPTY,
|
/* currentTracks= */ Tracks.EMPTY,
|
||||||
TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT);
|
TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT);
|
||||||
|
|
||||||
@ -816,9 +817,16 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
|||||||
private static final String FIELD_DISCONTINUITY_REASON = Util.intToStringMaxRadix(23);
|
private static final String FIELD_DISCONTINUITY_REASON = Util.intToStringMaxRadix(23);
|
||||||
private static final String FIELD_CUE_GROUP = Util.intToStringMaxRadix(24);
|
private static final String FIELD_CUE_GROUP = Util.intToStringMaxRadix(24);
|
||||||
private static final String FIELD_MEDIA_METADATA = Util.intToStringMaxRadix(25);
|
private static final String FIELD_MEDIA_METADATA = Util.intToStringMaxRadix(25);
|
||||||
private static final String FIELD_SEEK_BACK_INCREMENT_MS = Util.intToStringMaxRadix(26);
|
|
||||||
private static final String FIELD_SEEK_FORWARD_INCREMENT_MS = Util.intToStringMaxRadix(27);
|
@VisibleForTesting
|
||||||
private static final String FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS = Util.intToStringMaxRadix(28);
|
static final String FIELD_SEEK_BACK_INCREMENT_MS = Util.intToStringMaxRadix(26);
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String FIELD_SEEK_FORWARD_INCREMENT_MS = Util.intToStringMaxRadix(27);
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS = Util.intToStringMaxRadix(28);
|
||||||
|
|
||||||
private static final String FIELD_TRACK_SELECTION_PARAMETERS = Util.intToStringMaxRadix(29);
|
private static final String FIELD_TRACK_SELECTION_PARAMETERS = Util.intToStringMaxRadix(29);
|
||||||
private static final String FIELD_CURRENT_TRACKS = Util.intToStringMaxRadix(30);
|
private static final String FIELD_CURRENT_TRACKS = Util.intToStringMaxRadix(30);
|
||||||
private static final String FIELD_TIMELINE_CHANGE_REASON = Util.intToStringMaxRadix(31);
|
private static final String FIELD_TIMELINE_CHANGE_REASON = Util.intToStringMaxRadix(31);
|
||||||
@ -977,13 +985,19 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
|||||||
if (!mediaMetadata.equals(MediaMetadata.EMPTY)) {
|
if (!mediaMetadata.equals(MediaMetadata.EMPTY)) {
|
||||||
bundle.putBundle(FIELD_MEDIA_METADATA, mediaMetadata.toBundle());
|
bundle.putBundle(FIELD_MEDIA_METADATA, mediaMetadata.toBundle());
|
||||||
}
|
}
|
||||||
if (seekBackIncrementMs != 0) {
|
long defaultSeekBackIncrementMs =
|
||||||
|
controllerInterfaceVersion < 6 ? 0 : C.DEFAULT_SEEK_BACK_INCREMENT_MS;
|
||||||
|
if (seekBackIncrementMs != defaultSeekBackIncrementMs) {
|
||||||
bundle.putLong(FIELD_SEEK_BACK_INCREMENT_MS, seekBackIncrementMs);
|
bundle.putLong(FIELD_SEEK_BACK_INCREMENT_MS, seekBackIncrementMs);
|
||||||
}
|
}
|
||||||
if (seekForwardIncrementMs != 0) {
|
long defaultSeekForwardIncrementMs =
|
||||||
|
controllerInterfaceVersion < 6 ? 0 : C.DEFAULT_SEEK_FORWARD_INCREMENT_MS;
|
||||||
|
if (seekForwardIncrementMs != defaultSeekForwardIncrementMs) {
|
||||||
bundle.putLong(FIELD_SEEK_FORWARD_INCREMENT_MS, seekForwardIncrementMs);
|
bundle.putLong(FIELD_SEEK_FORWARD_INCREMENT_MS, seekForwardIncrementMs);
|
||||||
}
|
}
|
||||||
if (maxSeekToPreviousPositionMs != 0) {
|
long defaultMaxSeekToPreviousPositionMs =
|
||||||
|
controllerInterfaceVersion < 6 ? 0 : C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS;
|
||||||
|
if (maxSeekToPreviousPositionMs != defaultMaxSeekToPreviousPositionMs) {
|
||||||
bundle.putLong(FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS, maxSeekToPreviousPositionMs);
|
bundle.putLong(FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS, maxSeekToPreviousPositionMs);
|
||||||
}
|
}
|
||||||
if (!currentTracks.equals(Tracks.EMPTY)) {
|
if (!currentTracks.equals(Tracks.EMPTY)) {
|
||||||
@ -996,7 +1010,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Restores a {@code PlayerInfo} from a {@link Bundle}. */
|
/** Restores a {@code PlayerInfo} from a {@link Bundle}. */
|
||||||
public static PlayerInfo fromBundle(Bundle bundle) {
|
public static PlayerInfo fromBundle(Bundle bundle, int sessionInterfaceVersion) {
|
||||||
@Nullable IBinder inProcessBinder = bundle.getBinder(FIELD_IN_PROCESS_BINDER);
|
@Nullable IBinder inProcessBinder = bundle.getBinder(FIELD_IN_PROCESS_BINDER);
|
||||||
if (inProcessBinder instanceof InProcessBinder) {
|
if (inProcessBinder instanceof InProcessBinder) {
|
||||||
return ((InProcessBinder) inProcessBinder).getPlayerInfo();
|
return ((InProcessBinder) inProcessBinder).getPlayerInfo();
|
||||||
@ -1080,11 +1094,22 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
|||||||
mediaMetadataBundle == null
|
mediaMetadataBundle == null
|
||||||
? MediaMetadata.EMPTY
|
? MediaMetadata.EMPTY
|
||||||
: MediaMetadata.fromBundle(mediaMetadataBundle);
|
: MediaMetadata.fromBundle(mediaMetadataBundle);
|
||||||
long seekBackIncrementMs = bundle.getLong(FIELD_SEEK_BACK_INCREMENT_MS, /* defaultValue= */ 0);
|
long seekBackIncrementMs =
|
||||||
|
bundle.getLong(
|
||||||
|
FIELD_SEEK_BACK_INCREMENT_MS,
|
||||||
|
/* defaultValue= */ sessionInterfaceVersion < 4 ? 0 : C.DEFAULT_SEEK_BACK_INCREMENT_MS);
|
||||||
long seekForwardIncrementMs =
|
long seekForwardIncrementMs =
|
||||||
bundle.getLong(FIELD_SEEK_FORWARD_INCREMENT_MS, /* defaultValue= */ 0);
|
bundle.getLong(
|
||||||
|
FIELD_SEEK_FORWARD_INCREMENT_MS,
|
||||||
|
/* defaultValue= */ sessionInterfaceVersion < 4
|
||||||
|
? 0
|
||||||
|
: C.DEFAULT_SEEK_FORWARD_INCREMENT_MS);
|
||||||
long maxSeekToPreviousPosition =
|
long maxSeekToPreviousPosition =
|
||||||
bundle.getLong(FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS, /* defaultValue= */ 0);
|
bundle.getLong(
|
||||||
|
FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS,
|
||||||
|
/* defaultValue= */ sessionInterfaceVersion < 4
|
||||||
|
? 0
|
||||||
|
: C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS);
|
||||||
Bundle currentTracksBundle = bundle.getBundle(FIELD_CURRENT_TRACKS);
|
Bundle currentTracksBundle = bundle.getBundle(FIELD_CURRENT_TRACKS);
|
||||||
Tracks currentTracks =
|
Tracks currentTracks =
|
||||||
currentTracksBundle == null ? Tracks.EMPTY : Tracks.fromBundle(currentTracksBundle);
|
currentTracksBundle == null ? Tracks.EMPTY : Tracks.fromBundle(currentTracksBundle);
|
||||||
|
@ -163,7 +163,8 @@ public class PlayerInfoTest {
|
|||||||
.setVideoSize(new VideoSize(/* width= */ 1024, /* height= */ 768))
|
.setVideoSize(new VideoSize(/* width= */ 1024, /* height= */ 768))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
PlayerInfo infoAfterBundling = PlayerInfo.fromBundle(playerInfo.toBundleInProcess());
|
PlayerInfo infoAfterBundling =
|
||||||
|
PlayerInfo.fromBundle(playerInfo.toBundleInProcess(), MediaSessionStub.VERSION_INT);
|
||||||
|
|
||||||
assertThat(infoAfterBundling.oldPositionInfo.mediaItemIndex).isEqualTo(5);
|
assertThat(infoAfterBundling.oldPositionInfo.mediaItemIndex).isEqualTo(5);
|
||||||
assertThat(infoAfterBundling.oldPositionInfo.periodIndex).isEqualTo(4);
|
assertThat(infoAfterBundling.oldPositionInfo.periodIndex).isEqualTo(4);
|
||||||
@ -292,7 +293,8 @@ public class PlayerInfoTest {
|
|||||||
.build(),
|
.build(),
|
||||||
/* excludeTimeline= */ false,
|
/* excludeTimeline= */ false,
|
||||||
/* excludeTracks= */ false)
|
/* excludeTracks= */ false)
|
||||||
.toBundleInProcess());
|
.toBundleInProcess(),
|
||||||
|
MediaSessionStub.VERSION_INT);
|
||||||
|
|
||||||
assertThat(infoAfterBundling.oldPositionInfo.mediaItemIndex).isEqualTo(5);
|
assertThat(infoAfterBundling.oldPositionInfo.mediaItemIndex).isEqualTo(5);
|
||||||
assertThat(infoAfterBundling.oldPositionInfo.periodIndex).isEqualTo(4);
|
assertThat(infoAfterBundling.oldPositionInfo.periodIndex).isEqualTo(4);
|
||||||
@ -413,7 +415,8 @@ public class PlayerInfoTest {
|
|||||||
.build(),
|
.build(),
|
||||||
/* excludeTimeline= */ true,
|
/* excludeTimeline= */ true,
|
||||||
/* excludeTracks= */ false)
|
/* excludeTracks= */ false)
|
||||||
.toBundleInProcess());
|
.toBundleInProcess(),
|
||||||
|
MediaSessionStub.VERSION_INT);
|
||||||
|
|
||||||
assertThat(infoAfterBundling.oldPositionInfo.mediaItemIndex).isEqualTo(0);
|
assertThat(infoAfterBundling.oldPositionInfo.mediaItemIndex).isEqualTo(0);
|
||||||
assertThat(infoAfterBundling.oldPositionInfo.periodIndex).isEqualTo(0);
|
assertThat(infoAfterBundling.oldPositionInfo.periodIndex).isEqualTo(0);
|
||||||
@ -482,7 +485,8 @@ public class PlayerInfoTest {
|
|||||||
.build(),
|
.build(),
|
||||||
/* excludeTimeline= */ false,
|
/* excludeTimeline= */ false,
|
||||||
/* excludeTracks= */ false)
|
/* excludeTracks= */ false)
|
||||||
.toBundleInProcess());
|
.toBundleInProcess(),
|
||||||
|
MediaSessionStub.VERSION_INT);
|
||||||
|
|
||||||
assertThat(infoAfterBundling.mediaMetadata).isEqualTo(MediaMetadata.EMPTY);
|
assertThat(infoAfterBundling.mediaMetadata).isEqualTo(MediaMetadata.EMPTY);
|
||||||
assertThat(infoAfterBundling.playlistMetadata).isEqualTo(MediaMetadata.EMPTY);
|
assertThat(infoAfterBundling.playlistMetadata).isEqualTo(MediaMetadata.EMPTY);
|
||||||
@ -502,7 +506,8 @@ public class PlayerInfoTest {
|
|||||||
.build(),
|
.build(),
|
||||||
/* excludeTimeline= */ false,
|
/* excludeTimeline= */ false,
|
||||||
/* excludeTracks= */ false)
|
/* excludeTracks= */ false)
|
||||||
.toBundleInProcess());
|
.toBundleInProcess(),
|
||||||
|
MediaSessionStub.VERSION_INT);
|
||||||
|
|
||||||
assertThat(infoAfterBundling.volume).isEqualTo(1f);
|
assertThat(infoAfterBundling.volume).isEqualTo(1f);
|
||||||
}
|
}
|
||||||
@ -522,7 +527,8 @@ public class PlayerInfoTest {
|
|||||||
.build(),
|
.build(),
|
||||||
/* excludeTimeline= */ false,
|
/* excludeTimeline= */ false,
|
||||||
/* excludeTracks= */ false)
|
/* excludeTracks= */ false)
|
||||||
.toBundleInProcess());
|
.toBundleInProcess(),
|
||||||
|
MediaSessionStub.VERSION_INT);
|
||||||
|
|
||||||
assertThat(infoAfterBundling.deviceVolume).isEqualTo(0);
|
assertThat(infoAfterBundling.deviceVolume).isEqualTo(0);
|
||||||
assertThat(infoAfterBundling.deviceMuted).isFalse();
|
assertThat(infoAfterBundling.deviceMuted).isFalse();
|
||||||
@ -546,7 +552,8 @@ public class PlayerInfoTest {
|
|||||||
.build(),
|
.build(),
|
||||||
/* excludeTimeline= */ false,
|
/* excludeTimeline= */ false,
|
||||||
/* excludeTracks= */ false)
|
/* excludeTracks= */ false)
|
||||||
.toBundleInProcess());
|
.toBundleInProcess(),
|
||||||
|
MediaSessionStub.VERSION_INT);
|
||||||
|
|
||||||
assertThat(infoAfterBundling.audioAttributes).isEqualTo(AudioAttributes.DEFAULT);
|
assertThat(infoAfterBundling.audioAttributes).isEqualTo(AudioAttributes.DEFAULT);
|
||||||
}
|
}
|
||||||
@ -568,7 +575,8 @@ public class PlayerInfoTest {
|
|||||||
.build(),
|
.build(),
|
||||||
/* excludeTimeline= */ false,
|
/* excludeTimeline= */ false,
|
||||||
/* excludeTracks= */ false)
|
/* excludeTracks= */ false)
|
||||||
.toBundleInProcess());
|
.toBundleInProcess(),
|
||||||
|
MediaSessionStub.VERSION_INT);
|
||||||
|
|
||||||
assertThat(infoAfterBundling.cueGroup).isEqualTo(CueGroup.EMPTY_TIME_ZERO);
|
assertThat(infoAfterBundling.cueGroup).isEqualTo(CueGroup.EMPTY_TIME_ZERO);
|
||||||
}
|
}
|
||||||
@ -598,14 +606,16 @@ public class PlayerInfoTest {
|
|||||||
.build(),
|
.build(),
|
||||||
/* excludeTimeline= */ false,
|
/* excludeTimeline= */ false,
|
||||||
/* excludeTracks= */ true)
|
/* excludeTracks= */ true)
|
||||||
.toBundleInProcess());
|
.toBundleInProcess(),
|
||||||
|
MediaSessionStub.VERSION_INT);
|
||||||
|
|
||||||
assertThat(infoAfterBundling.currentTracks).isEqualTo(Tracks.EMPTY);
|
assertThat(infoAfterBundling.currentTracks).isEqualTo(Tracks.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toBundleFromBundle_withDefaultValues_restoresAllData() {
|
public void toBundleFromBundle_withDefaultValues_restoresAllData() {
|
||||||
PlayerInfo roundTripValue = PlayerInfo.fromBundle(PlayerInfo.DEFAULT.toBundleInProcess());
|
PlayerInfo roundTripValue =
|
||||||
|
PlayerInfo.fromBundle(PlayerInfo.DEFAULT.toBundleInProcess(), MediaSessionStub.VERSION_INT);
|
||||||
|
|
||||||
assertThat(roundTripValue.oldPositionInfo).isEqualTo(PlayerInfo.DEFAULT.oldPositionInfo);
|
assertThat(roundTripValue.oldPositionInfo).isEqualTo(PlayerInfo.DEFAULT.oldPositionInfo);
|
||||||
assertThat(roundTripValue.newPositionInfo).isEqualTo(PlayerInfo.DEFAULT.newPositionInfo);
|
assertThat(roundTripValue.newPositionInfo).isEqualTo(PlayerInfo.DEFAULT.newPositionInfo);
|
||||||
@ -659,6 +669,21 @@ public class PlayerInfoTest {
|
|||||||
assertThat(bundle.isEmpty()).isTrue();
|
assertThat(bundle.isEmpty()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void
|
||||||
|
toBundleForRemoteProcess_withDefaultValuesForControllerInterfaceBefore6_includesSeekLimits() {
|
||||||
|
// Controller before version 6 uses 0 values for the three seek limit default values. The
|
||||||
|
// Bundle should include these to overwrite the presumed 0 on the controller side.
|
||||||
|
Bundle bundle =
|
||||||
|
PlayerInfo.DEFAULT.toBundleForRemoteProcess(/* controllerInterfaceVersion= */ 5);
|
||||||
|
|
||||||
|
assertThat(bundle.keySet())
|
||||||
|
.containsAtLeast(
|
||||||
|
PlayerInfo.FIELD_SEEK_BACK_INCREMENT_MS,
|
||||||
|
PlayerInfo.FIELD_SEEK_FORWARD_INCREMENT_MS,
|
||||||
|
PlayerInfo.FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void
|
public void
|
||||||
toBundleForRemoteProcess_withDefaultValuesForControllerInterfaceBefore3_includesPositionInfos() {
|
toBundleForRemoteProcess_withDefaultValuesForControllerInterfaceBefore3_includesPositionInfos() {
|
||||||
@ -673,4 +698,16 @@ public class PlayerInfoTest {
|
|||||||
PlayerInfo.FIELD_NEW_POSITION_INFO,
|
PlayerInfo.FIELD_NEW_POSITION_INFO,
|
||||||
PlayerInfo.FIELD_OLD_POSITION_INFO);
|
PlayerInfo.FIELD_OLD_POSITION_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fromBundle_withEmptyBundleForSessionInterfaceBefore4_restoresSeekLimitsAsZero() {
|
||||||
|
// Session before version 4 uses 0 values for the three seek limit default values. We need to
|
||||||
|
// restore those instead of current default.
|
||||||
|
|
||||||
|
PlayerInfo playerInfo = PlayerInfo.fromBundle(Bundle.EMPTY, /* sessionInterfaceVersion= */ 3);
|
||||||
|
|
||||||
|
assertThat(playerInfo.seekBackIncrementMs).isEqualTo(0);
|
||||||
|
assertThat(playerInfo.seekForwardIncrementMs).isEqualTo(0);
|
||||||
|
assertThat(playerInfo.maxSeekToPreviousPositionMs).isEqualTo(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -325,7 +325,7 @@ public class TestExoPlayerBuilder {
|
|||||||
* @return This builder.
|
* @return This builder.
|
||||||
*/
|
*/
|
||||||
@CanIgnoreReturnValue
|
@CanIgnoreReturnValue
|
||||||
public TestExoPlayerBuilder setMaxSeekToPreviousPosition(long maxSeekToPreviousPositionMs) {
|
public TestExoPlayerBuilder setMaxSeekToPreviousPositionMs(long maxSeekToPreviousPositionMs) {
|
||||||
this.maxSeekToPreviousPositionMs = maxSeekToPreviousPositionMs;
|
this.maxSeekToPreviousPositionMs = maxSeekToPreviousPositionMs;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -398,7 +398,7 @@ public class TestExoPlayerBuilder {
|
|||||||
.setLooper(looper)
|
.setLooper(looper)
|
||||||
.setSeekBackIncrementMs(seekBackIncrementMs)
|
.setSeekBackIncrementMs(seekBackIncrementMs)
|
||||||
.setSeekForwardIncrementMs(seekForwardIncrementMs)
|
.setSeekForwardIncrementMs(seekForwardIncrementMs)
|
||||||
.setMaxSeekToPreviousPosition(maxSeekToPreviousPositionMs)
|
.setMaxSeekToPreviousPositionMs(maxSeekToPreviousPositionMs)
|
||||||
.setDeviceVolumeControlEnabled(deviceVolumeControlEnabled)
|
.setDeviceVolumeControlEnabled(deviceVolumeControlEnabled)
|
||||||
.setSuppressPlaybackOnUnsuitableOutput(suppressPlaybackWhenUnsuitableOutput)
|
.setSuppressPlaybackOnUnsuitableOutput(suppressPlaybackWhenUnsuitableOutput)
|
||||||
.experimentalSetDynamicSchedulingEnabled(dynamicSchedulingEnabled);
|
.experimentalSetDynamicSchedulingEnabled(dynamicSchedulingEnabled);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user