Commit d1dc6134 by tonihei Committed by Tianyi Feng

Remove deprecated stop(boolean)

This method has been deprecated for over 2 years.

PiperOrigin-RevId: 520586238
parent e6db3479
......@@ -475,17 +475,6 @@ public final class CastPlayer extends BasePlayer {
@Override
public void stop() {
stop(/* reset= */ false);
}
/**
* @deprecated Use {@link #stop()} and {@link #clearMediaItems()} (if {@code reset} is true) or
* just {@link #stop()} (if {@code reset} is false). Any player error will be cleared when
* {@link #prepare() re-preparing} the player.
*/
@Deprecated
@Override
public void stop(boolean reset) {
playbackState = STATE_IDLE;
if (remoteMediaClient != null) {
// TODO(b/69792021): Support or emulate stop without position reset.
......
......@@ -480,20 +480,6 @@ public class ForwardingPlayer implements Player {
player.stop();
}
/**
* Calls {@link Player#stop(boolean)} on the delegate.
*
* @deprecated Use {@link #stop()} and {@link #clearMediaItems()} (if {@code reset} is true) or
* just {@link #stop()} (if {@code reset} is false). Any player error will be cleared when
* {@link #prepare() re-preparing} the player.
*/
@SuppressWarnings("deprecation") // Forwarding to deprecated method
@Deprecated
@Override
public void stop(boolean reset) {
player.stop(reset);
}
/** Calls {@link Player#release()} on the delegate. */
@Override
public void release() {
......
......@@ -2505,14 +2505,6 @@ public interface Player {
void stop();
/**
* @deprecated Use {@link #stop()} and {@link #clearMediaItems()} (if {@code reset} is true) or
* just {@link #stop()} (if {@code reset} is false). Any player error will be cleared when
* {@link #prepare() re-preparing} the player.
*/
@Deprecated
void stop(boolean reset);
/**
* Releases the player. This method must be called when the player is no longer required. The
* player must not be used after calling this method.
*
......
......@@ -2329,14 +2329,6 @@ public abstract class SimpleBasePlayer extends BasePlayer {
}
@Override
public final void stop(boolean reset) {
stop();
if (reset) {
clearMediaItems();
}
}
@Override
public final void release() {
verifyApplicationThreadAndInitState();
// Use a local copy to ensure the lambda below uses the current state value.
......
......@@ -945,7 +945,6 @@ import java.util.concurrent.TimeoutException;
if (!internalPlayer.setForegroundMode(foregroundMode)) {
// One of the renderers timed out releasing its resources.
stopInternal(
/* reset= */ false,
ExoPlaybackException.createForUnexpected(
new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_SET_FOREGROUND_MODE),
PlaybackException.ERROR_CODE_TIMEOUT));
......@@ -956,14 +955,8 @@ import java.util.concurrent.TimeoutException;
@Override
public void stop() {
verifyApplicationThread();
stop(/* reset= */ false);
}
@Override
public void stop(boolean reset) {
verifyApplicationThread();
audioFocusManager.updateAudioFocus(getPlayWhenReady(), Player.STATE_IDLE);
stopInternal(reset, /* error= */ null);
stopInternal(/* error= */ null);
currentCueGroup = new CueGroup(ImmutableList.of(), playbackInfo.positionUs);
}
......@@ -1748,38 +1741,27 @@ import java.util.concurrent.TimeoutException;
/**
* Stops the player.
*
* @param reset Whether the playlist should be cleared and whether the playback position and
* playback error should be reset.
* @param error An optional {@link ExoPlaybackException} to set.
*/
private void stopInternal(boolean reset, @Nullable ExoPlaybackException error) {
PlaybackInfo playbackInfo;
if (reset) {
playbackInfo =
removeMediaItemsInternal(
/* fromIndex= */ 0, /* toIndex= */ mediaSourceHolderSnapshots.size());
playbackInfo = playbackInfo.copyWithPlaybackError(null);
} else {
playbackInfo = this.playbackInfo.copyWithLoadingMediaPeriodId(this.playbackInfo.periodId);
playbackInfo.bufferedPositionUs = playbackInfo.positionUs;
playbackInfo.totalBufferedDurationUs = 0;
}
private void stopInternal(@Nullable ExoPlaybackException error) {
PlaybackInfo playbackInfo =
this.playbackInfo.copyWithLoadingMediaPeriodId(this.playbackInfo.periodId);
playbackInfo.bufferedPositionUs = playbackInfo.positionUs;
playbackInfo.totalBufferedDurationUs = 0;
playbackInfo = playbackInfo.copyWithPlaybackState(Player.STATE_IDLE);
if (error != null) {
playbackInfo = playbackInfo.copyWithPlaybackError(error);
}
pendingOperationAcks++;
internalPlayer.stop();
boolean positionDiscontinuity =
playbackInfo.timeline.isEmpty() && !this.playbackInfo.timeline.isEmpty();
updatePlaybackInfo(
playbackInfo,
TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED,
/* ignored */ TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED,
/* ignored */ PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST,
/* seekProcessed= */ false,
positionDiscontinuity,
DISCONTINUITY_REASON_REMOVE,
/* discontinuityWindowStartPositionUs= */ getCurrentPositionUsInternal(playbackInfo),
/* positionDiscontinuity= */ false,
/* ignored */ DISCONTINUITY_REASON_INTERNAL,
/* ignored */ C.TIME_UNSET,
/* ignored */ C.INDEX_UNSET,
/* repeatCurrentMediaItem= */ false);
}
......@@ -2578,7 +2560,6 @@ import java.util.concurrent.TimeoutException;
this.videoOutput = videoOutput;
if (messageDeliveryTimedOut) {
stopInternal(
/* reset= */ false,
ExoPlaybackException.createForUnexpected(
new ExoTimeoutException(ExoTimeoutException.TIMEOUT_OPERATION_DETACH_SURFACE),
PlaybackException.ERROR_CODE_TIMEOUT));
......
......@@ -1068,18 +1068,6 @@ public class SimpleExoPlayer extends BasePlayer
player.stop();
}
/**
* @deprecated Use {@link #stop()} and {@link #clearMediaItems()} (if {@code reset} is true) or
* just {@link #stop()} (if {@code reset} is false). Any player error will be cleared when
* {@link #prepare() re-preparing} the player.
*/
@Deprecated
@Override
public void stop(boolean reset) {
blockUntilConstructorFinished();
player.stop(reset);
}
@Override
public void release() {
blockUntilConstructorFinished();
......
......@@ -1495,7 +1495,7 @@ public final class ExoPlayerTest {
}
@Test
public void stop_withoutReset_doesNotResetPosition_correctMasking() throws Exception {
public void stop_correctMasking() throws Exception {
int[] currentMediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET};
long[] currentPosition = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET};
long[] bufferedPosition = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET};
......@@ -1515,7 +1515,7 @@ public final class ExoPlayerTest {
currentPosition[0] = player.getCurrentPosition();
bufferedPosition[0] = player.getBufferedPosition();
totalBufferedDuration[0] = player.getTotalBufferedDuration();
player.stop(/* reset= */ false);
player.stop();
currentMediaItemIndex[1] = player.getCurrentMediaItemIndex();
currentPosition[1] = player.getCurrentPosition();
bufferedPosition[1] = player.getBufferedPosition();
......@@ -1565,109 +1565,12 @@ public final class ExoPlayerTest {
}
@Test
public void stop_withoutReset_releasesMediaSource() throws Exception {
public void stop_releasesMediaSource() throws Exception {
Timeline timeline = new FakeTimeline();
final FakeMediaSource mediaSource =
new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule =
new ActionSchedule.Builder(TAG)
.waitForPlaybackState(Player.STATE_READY)
.stop(/* reset= */ false)
.build();
new ExoPlayerTestRunner.Builder(context)
.setTimeline(timeline)
.setActionSchedule(actionSchedule)
.build()
.start()
.blockUntilActionScheduleFinished(TIMEOUT_MS)
.blockUntilEnded(TIMEOUT_MS);
mediaSource.assertReleased();
}
@Test
public void stop_withReset_doesResetPosition_correctMasking() throws Exception {
int[] currentMediaItemIndex = {C.INDEX_UNSET, C.INDEX_UNSET, C.INDEX_UNSET};
long[] currentPosition = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET};
long[] bufferedPosition = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET};
long[] totalBufferedDuration = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET};
final FakeMediaSource mediaSource =
new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule =
new ActionSchedule.Builder(TAG)
.pause()
.seek(/* mediaItemIndex= */ 1, /* positionMs= */ 1000)
.waitForPlaybackState(Player.STATE_READY)
.executeRunnable(
new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndex[0] = player.getCurrentMediaItemIndex();
currentPosition[0] = player.getCurrentPosition();
bufferedPosition[0] = player.getBufferedPosition();
totalBufferedDuration[0] = player.getTotalBufferedDuration();
player.stop(/* reset= */ true);
currentMediaItemIndex[1] = player.getCurrentMediaItemIndex();
currentPosition[1] = player.getCurrentPosition();
bufferedPosition[1] = player.getBufferedPosition();
totalBufferedDuration[1] = player.getTotalBufferedDuration();
}
})
.waitForPlaybackState(Player.STATE_IDLE)
.executeRunnable(
new PlayerRunnable() {
@Override
public void run(ExoPlayer player) {
currentMediaItemIndex[2] = player.getCurrentMediaItemIndex();
currentPosition[2] = player.getCurrentPosition();
bufferedPosition[2] = player.getBufferedPosition();
totalBufferedDuration[2] = player.getTotalBufferedDuration();
}
})
.build();
ExoPlayerTestRunner testRunner =
new ExoPlayerTestRunner.Builder(context)
.setMediaSources(mediaSource, mediaSource)
.setActionSchedule(actionSchedule)
.build()
.start()
.blockUntilActionScheduleFinished(TIMEOUT_MS);
testRunner.assertTimelineChangeReasonsEqual(
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED,
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE,
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED);
testRunner.assertPositionDiscontinuityReasonsEqual(
Player.DISCONTINUITY_REASON_SEEK, Player.DISCONTINUITY_REASON_REMOVE);
assertThat(currentMediaItemIndex[0]).isEqualTo(1);
assertThat(currentPosition[0]).isGreaterThan(0);
assertThat(bufferedPosition[0]).isEqualTo(10000);
assertThat(totalBufferedDuration[0]).isEqualTo(10000 - currentPosition[0]);
assertThat(currentMediaItemIndex[1]).isEqualTo(0);
assertThat(currentPosition[1]).isEqualTo(0);
assertThat(bufferedPosition[1]).isEqualTo(0);
assertThat(totalBufferedDuration[1]).isEqualTo(0);
assertThat(currentMediaItemIndex[2]).isEqualTo(0);
assertThat(currentPosition[2]).isEqualTo(0);
assertThat(bufferedPosition[2]).isEqualTo(0);
assertThat(totalBufferedDuration[2]).isEqualTo(0);
}
@Test
public void stop_withReset_releasesMediaSource() throws Exception {
Timeline timeline = new FakeTimeline();
final FakeMediaSource mediaSource =
new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT);
ActionSchedule actionSchedule =
new ActionSchedule.Builder(TAG)
.waitForPlaybackState(Player.STATE_READY)
.stop(/* reset= */ true)
.build();
new ActionSchedule.Builder(TAG).waitForPlaybackState(Player.STATE_READY).stop().build();
new ExoPlayerTestRunner.Builder(context)
.setTimeline(timeline)
......@@ -1745,7 +1648,7 @@ public final class ExoPlayerTest {
}
@Test
public void settingNewStartPositionPossibleAfterStopWithReset() throws Exception {
public void settingNewStartPositionPossibleAfterStopAndClearMediaItems() throws Exception {
Timeline timeline = new FakeTimeline();
Timeline secondTimeline = new FakeTimeline(/* windowCount= */ 2);
MediaSource secondSource =
......@@ -1755,7 +1658,8 @@ public final class ExoPlayerTest {
ActionSchedule actionSchedule =
new ActionSchedule.Builder(TAG)
.waitForPlaybackState(Player.STATE_READY)
.stop(/* reset= */ true)
.stop()
.clearMediaItems()
.waitForPlaybackState(Player.STATE_IDLE)
.seek(/* mediaItemIndex= */ 1, /* positionMs= */ 1000)
.setMediaSources(secondSource)
......@@ -1971,11 +1875,12 @@ public final class ExoPlayerTest {
}
@Test
public void stopDuringPreparationOverwritesPreparation() throws Exception {
public void stopAndClearMediaItemsDuringPreparationOverwritesPreparation() throws Exception {
ActionSchedule actionSchedule =
new ActionSchedule.Builder(TAG)
.waitForPlaybackState(Player.STATE_BUFFERING)
.stop(true)
.stop()
.clearMediaItems()
.waitForPendingPlayerCommands()
.build();
ExoPlayerTestRunner testRunner =
......@@ -1998,8 +1903,8 @@ public final class ExoPlayerTest {
ActionSchedule actionSchedule =
new ActionSchedule.Builder(TAG)
.waitForPlaybackState(Player.STATE_READY)
.stop(false)
.stop(false)
.stop()
.stop()
// Wait until the player fully processed the second stop to see that no further
// callbacks are triggered.
.waitForPendingPlayerCommands()
......@@ -3264,7 +3169,7 @@ public final class ExoPlayerTest {
public void onPlaybackStateChanged(@Player.State int playbackState) {
playerListener1States.add(playbackState);
if (playbackState == Player.STATE_READY) {
playerReference.get().stop(/* reset= */ true);
playerReference.get().stop();
}
}
};
......@@ -3316,7 +3221,8 @@ public final class ExoPlayerTest {
public void onPlaybackStateChanged(@Player.State int playbackState) {
playerListenerStates.add(playbackState);
if (playbackState == Player.STATE_READY) {
playerReference.get().stop(/* reset= */ true);
playerReference.get().stop();
playerReference.get().clearMediaItems();
sequence.add(0);
}
}
......@@ -3387,7 +3293,7 @@ public final class ExoPlayerTest {
})
// Ensure there are no further pending callbacks.
.delay(1)
.stop(/* reset= */ true)
.stop()
.waitForPlaybackState(Player.STATE_IDLE)
.prepare()
.waitForPlaybackState(Player.STATE_ENDED)
......@@ -3403,14 +3309,12 @@ public final class ExoPlayerTest {
exoPlayerTestRunner.assertTimelinesSame(
new FakeMediaSource.InitialTimeline(firstTimeline),
firstTimeline,
Timeline.EMPTY,
new FakeMediaSource.InitialTimeline(secondTimeline),
secondTimeline);
exoPlayerTestRunner.assertTimelineChangeReasonsEqual(
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED,
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE,
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED,
Player.TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED,
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}
......@@ -6247,8 +6151,7 @@ public final class ExoPlayerTest {
}
@Test
public void stopWithNoReset_modifyingPlaylistRemainsInIdleState_needsPrepareForBuffering()
throws Exception {
public void stop_modifyingPlaylistRemainsInIdleState_needsPrepareForBuffering() throws Exception {
Timeline timeline = new FakeTimeline();
FakeMediaSource secondMediaSource = new FakeMediaSource(timeline);
int[] playbackStateHolder = new int[3];
......@@ -6256,7 +6159,7 @@ public final class ExoPlayerTest {
ActionSchedule actionSchedule =
new ActionSchedule.Builder(TAG)
.waitForPlaybackState(Player.STATE_READY)
.stop(/* reset= */ false)
.stop()
.executeRunnable(
new PlaybackStateCollector(/* index= */ 0, playbackStateHolder, windowCountHolder))
.clearMediaItems()
......@@ -9070,40 +8973,8 @@ public final class ExoPlayerTest {
player.release();
}
// Tests deprecated stop(boolean reset)
@SuppressWarnings("deprecation")
@Test
public void stop_withReset_notifiesMediaItemTransition() throws Exception {
List<MediaItem> reportedMediaItems = new ArrayList<>();
List<Integer> reportedTransitionReasons = new ArrayList<>();
MediaSource mediaSource1 = FakeMediaSource.createWithWindowId(/* windowId= */ new Object());
MediaSource mediaSource2 = FakeMediaSource.createWithWindowId(/* windowId= */ new Object());
ExoPlayer player = new TestExoPlayerBuilder(context).build();
player.addListener(
new Listener() {
@Override
public void onMediaItemTransition(@Nullable MediaItem mediaItem, int reason) {
reportedMediaItems.add(mediaItem);
reportedTransitionReasons.add(reason);
}
});
player.setMediaSources(ImmutableList.of(mediaSource1, mediaSource2));
player.prepare();
runUntilPlaybackState(player, Player.STATE_READY);
player.stop(/* reset= */ true);
assertThat(reportedMediaItems).containsExactly(mediaSource1.getMediaItem(), null).inOrder();
assertThat(reportedTransitionReasons)
.containsExactly(
Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED,
Player.MEDIA_ITEM_TRANSITION_REASON_PLAYLIST_CHANGED)
.inOrder();
player.release();
}
@Test
public void stop_withoutReset_doesNotNotifyMediaItemTransition() throws Exception {
public void stop_doesNotNotifyMediaItemTransition() throws Exception {
List<MediaItem> reportedMediaItems = new ArrayList<>();
List<Integer> reportedTransitionReasons = new ArrayList<>();
MediaSource mediaSource1 = FakeMediaSource.createWithWindowId(/* windowId= */ new Object());
......@@ -12073,43 +11944,6 @@ public final class ExoPlayerTest {
player.release();
}
// Tests deprecated stop(boolean reset)
@SuppressWarnings("deprecation")
@Test
public void stop_withResetRemovesPlayingPeriod_callsOnPositionDiscontinuity() throws Exception {
ExoPlayer player = new TestExoPlayerBuilder(context).build();
Player.Listener listener = mock(Player.Listener.class);
player.addListener(listener);
player.setMediaSource(createFakeMediaSource(/* id= */ 123));
player.prepare();
TestPlayerRunHelper.playUntilPosition(
player, /* mediaItemIndex= */ 0, /* positionMs= */ 5 * C.MILLIS_PER_SECOND);
player.stop(/* reset= */ true);
ArgumentCaptor<Player.PositionInfo> oldPosition =
ArgumentCaptor.forClass(Player.PositionInfo.class);
ArgumentCaptor<Player.PositionInfo> newPosition =
ArgumentCaptor.forClass(Player.PositionInfo.class);
verify(listener, never())
.onPositionDiscontinuity(any(), any(), not(eq(Player.DISCONTINUITY_REASON_REMOVE)));
verify(listener)
.onPositionDiscontinuity(
oldPosition.capture(), newPosition.capture(), eq(Player.DISCONTINUITY_REASON_REMOVE));
List<Player.PositionInfo> oldPositions = oldPosition.getAllValues();
List<Player.PositionInfo> newPositions = newPosition.getAllValues();
assertThat(oldPositions.get(0).mediaItemIndex).isEqualTo(0);
assertThat(oldPositions.get(0).mediaItem.localConfiguration.tag).isEqualTo(123);
assertThat(oldPositions.get(0).positionMs).isIn(Range.closed(4980L, 5000L));
assertThat(oldPositions.get(0).contentPositionMs).isIn(Range.closed(4980L, 5000L));
assertThat(newPositions.get(0).windowUid).isNull();
assertThat(newPositions.get(0).mediaItemIndex).isEqualTo(0);
assertThat(newPositions.get(0).mediaItem).isNull();
assertThat(newPositions.get(0).positionMs).isEqualTo(0);
assertThat(newPositions.get(0).contentPositionMs).isEqualTo(0);
player.release();
}
@Test
public void seekTo_cancelsSourceDiscontinuity_callsOnPositionDiscontinuity() throws Exception {
Timeline timeline1 =
......
......@@ -337,13 +337,11 @@ public abstract class Action {
}
}
/** Calls {@link Player#stop()} or {@link Player#stop(boolean)}. */
/** Calls {@link Player#stop()}. */
public static final class Stop extends Action {
private static final String STOP_ACTION_TAG = "Stop";
@Nullable private final Boolean reset;
/**
* Action will call {@link Player#stop()}.
*
......@@ -351,28 +349,12 @@ public abstract class Action {
*/
public Stop(String tag) {
super(tag, STOP_ACTION_TAG);
this.reset = null;
}
/**
* Action will call {@link Player#stop(boolean)}.
*
* @param tag A tag to use for logging.
* @param reset The value to pass to {@link Player#stop(boolean)}.
*/
public Stop(@Size(max = 23) String tag, boolean reset) {
super(tag, STOP_ACTION_TAG);
this.reset = reset;
}
@Override
protected void doActionImpl(
ExoPlayer player, DefaultTrackSelector trackSelector, @Nullable Surface surface) {
if (reset == null) {
player.stop();
} else {
player.stop(reset);
}
player.stop();
}
}
......
......@@ -241,17 +241,6 @@ public final class ActionSchedule {
}
/**
* Schedules a stop action.
*
* @param reset Whether the player should be reset.
* @return The builder, for convenience.
*/
@CanIgnoreReturnValue
public Builder stop(boolean reset) {
return apply(new Stop(tag, reset));
}
/**
* Schedules a play action.
*
* @return The builder, for convenience.
......
......@@ -183,17 +183,6 @@ public class StubPlayer extends BasePlayer {
throw new UnsupportedOperationException();
}
/**
* @deprecated Use {@link #stop()} and {@link #clearMediaItems()} (if {@code reset} is true) or
* just {@link #stop()} (if {@code reset} is false). Any player error will be cleared when
* {@link #prepare() re-preparing} the player.
*/
@Deprecated
@Override
public void stop(boolean reset) {
throw new UnsupportedOperationException();
}
@Override
public void release() {
throw new UnsupportedOperationException();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment