From cd9b914c423900edcfe1e64bfb775a601bc23844 Mon Sep 17 00:00:00 2001 From: bachinger Date: Fri, 14 Jun 2024 05:21:08 -0700 Subject: [PATCH] Remove PreloadConfiguration from public API This feature isn't completed, so we should remove the public facing API to avoid confusion. #minor-release PiperOrigin-RevId: 643318692 --- .../androidx/media3/exoplayer/ExoPlayer.java | 38 --------- .../media3/exoplayer/ExoPlayerImpl.java | 26 +++++- .../exoplayer/ExoPlayerImplInternal.java | 12 +-- .../media3/exoplayer/MediaPeriodQueue.java | 7 +- .../media3/exoplayer/SimpleExoPlayer.java | 12 --- .../media3/exoplayer/ExoPlayerTest.java | 85 +------------------ .../exoplayer/MediaPeriodQueueTest.java | 2 +- .../test/utils/ExoPlayerTestRunner.java | 10 --- .../media3/test/utils/StubExoPlayer.java | 10 --- .../test/utils/TestExoPlayerBuilder.java | 16 ---- 10 files changed, 38 insertions(+), 180 deletions(-) diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayer.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayer.java index 08428368ef..ce12d42a93 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayer.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayer.java @@ -437,31 +437,6 @@ public interface ExoPlayer extends Player { default void onOffloadedPlayback(boolean isOffloadedPlayback) {} } - /** Configuration options for preloading playlist items. */ - @UnstableApi - class PreloadConfiguration { - - /** Default preload configuration that disables playlist preloading. */ - public static final PreloadConfiguration DEFAULT = - new PreloadConfiguration(/* targetPreloadDurationUs= */ C.TIME_UNSET); - - /** - * The target duration to buffer when preloading, in microseconds or {@link C#TIME_UNSET} to - * disable preloading. - */ - public final long targetPreloadDurationUs; - - /** - * Creates an instance. - * - * @param targetPreloadDurationUs The target duration to preload, in microseconds or {@link - * C#TIME_UNSET} to disable preloading. - */ - public PreloadConfiguration(long targetPreloadDurationUs) { - this.targetPreloadDurationUs = targetPreloadDurationUs; - } - } - /** * A builder for {@link ExoPlayer} instances. * @@ -1581,19 +1556,6 @@ public interface ExoPlayer extends Player { @UnstableApi void setShuffleOrder(ShuffleOrder shuffleOrder); - /** - * Sets the {@linkplain PreloadConfiguration preload configuration} to configure playlist - * preloading. - * - * @param preloadConfiguration The preload configuration. - */ - @UnstableApi - void setPreloadConfiguration(PreloadConfiguration preloadConfiguration); - - /** Returns the {@linkplain PreloadConfiguration preload configuration}. */ - @UnstableApi - PreloadConfiguration getPreloadConfiguration(); - /** * {@inheritDoc} * diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java index edcde1d4cc..6edf593406 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImpl.java @@ -141,6 +141,30 @@ import java.util.concurrent.TimeoutException; MediaLibraryInfo.registerModule("media3.exoplayer"); } + /** Configuration options for preloading playlist items. */ + public static final class PreloadConfiguration { + + /** Default preload configuration that disables playlist preloading. */ + public static final PreloadConfiguration DEFAULT = + new PreloadConfiguration(/* targetPreloadDurationUs= */ C.TIME_UNSET); + + /** + * The target duration to buffer when preloading, in microseconds or {@link C#TIME_UNSET} to + * disable preloading. + */ + public final long targetPreloadDurationUs; + + /** + * Creates an instance. + * + * @param targetPreloadDurationUs The target duration to preload, in microseconds or {@link + * C#TIME_UNSET} to disable preloading. + */ + public PreloadConfiguration(long targetPreloadDurationUs) { + this.targetPreloadDurationUs = targetPreloadDurationUs; + } + } + private static final String TAG = "ExoPlayerImpl"; /** @@ -885,7 +909,6 @@ import java.util.concurrent.TimeoutException; return shuffleModeEnabled; } - @Override public void setPreloadConfiguration(PreloadConfiguration preloadConfiguration) { verifyApplicationThread(); if (this.preloadConfiguration.equals(preloadConfiguration)) { @@ -895,7 +918,6 @@ import java.util.concurrent.TimeoutException; internalPlayer.setPreloadConfiguration(preloadConfiguration); } - @Override public PreloadConfiguration getPreloadConfiguration() { return preloadConfiguration; } diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImplInternal.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImplInternal.java index 3878ba2036..01ce88e26f 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImplInternal.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/ExoPlayerImplInternal.java @@ -57,7 +57,6 @@ import androidx.media3.common.util.TraceUtil; import androidx.media3.common.util.Util; import androidx.media3.datasource.DataSourceException; import androidx.media3.exoplayer.DefaultMediaClock.PlaybackParametersListener; -import androidx.media3.exoplayer.ExoPlayer.PreloadConfiguration; import androidx.media3.exoplayer.analytics.AnalyticsCollector; import androidx.media3.exoplayer.analytics.PlayerId; import androidx.media3.exoplayer.drm.DrmSession; @@ -242,7 +241,7 @@ import java.util.concurrent.atomic.AtomicBoolean; @Nullable private ExoPlaybackException pendingRecoverableRendererError; private long setForegroundModeTimeoutMs; private long playbackMaybeBecameStuckAtMs; - private PreloadConfiguration preloadConfiguration; + private ExoPlayerImpl.PreloadConfiguration preloadConfiguration; private Timeline lastPreloadPoolInvalidationTimeline; public ExoPlayerImplInternal( @@ -264,7 +263,7 @@ import java.util.concurrent.atomic.AtomicBoolean; PlaybackInfoUpdateListener playbackInfoUpdateListener, PlayerId playerId, Looper playbackLooper, - PreloadConfiguration preloadConfiguration) { + ExoPlayerImpl.PreloadConfiguration preloadConfiguration) { this.playbackInfoUpdateListener = playbackInfoUpdateListener; this.renderers = renderers; this.trackSelector = trackSelector; @@ -373,7 +372,7 @@ import java.util.concurrent.atomic.AtomicBoolean; handler.obtainMessage(MSG_SET_SHUFFLE_ENABLED, shuffleModeEnabled ? 1 : 0, 0).sendToTarget(); } - public void setPreloadConfiguration(PreloadConfiguration preloadConfiguration) { + public void setPreloadConfiguration(ExoPlayerImpl.PreloadConfiguration preloadConfiguration) { handler.obtainMessage(MSG_SET_PRELOAD_CONFIGURATION, preloadConfiguration).sendToTarget(); } @@ -562,7 +561,7 @@ import java.util.concurrent.atomic.AtomicBoolean; setShuffleModeEnabledInternal(msg.arg1 != 0); break; case MSG_SET_PRELOAD_CONFIGURATION: - setPreloadConfigurationInternal((PreloadConfiguration) msg.obj); + setPreloadConfigurationInternal((ExoPlayerImpl.PreloadConfiguration) msg.obj); break; case MSG_DO_SOME_WORK: doSomeWork(); @@ -951,7 +950,8 @@ import java.util.concurrent.atomic.AtomicBoolean; handleLoadingMediaPeriodChanged(/* loadingTrackSelectionChanged= */ false); } - private void setPreloadConfigurationInternal(PreloadConfiguration preloadConfiguration) { + private void setPreloadConfigurationInternal( + ExoPlayerImpl.PreloadConfiguration preloadConfiguration) { this.preloadConfiguration = preloadConfiguration; queue.updatePreloadConfiguration(playbackInfo.timeline, preloadConfiguration); } diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/MediaPeriodQueue.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/MediaPeriodQueue.java index 35c3637963..5554b09c88 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/MediaPeriodQueue.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/MediaPeriodQueue.java @@ -28,7 +28,6 @@ import androidx.media3.common.Player.RepeatMode; import androidx.media3.common.Timeline; import androidx.media3.common.util.Assertions; import androidx.media3.common.util.HandlerWrapper; -import androidx.media3.exoplayer.ExoPlayer.PreloadConfiguration; import androidx.media3.exoplayer.analytics.AnalyticsCollector; import androidx.media3.exoplayer.source.MediaPeriod; import androidx.media3.exoplayer.source.MediaSource.MediaPeriodId; @@ -85,7 +84,7 @@ import java.util.List; private int length; @Nullable private Object oldFrontPeriodUid; private long oldFrontPeriodWindowSequenceNumber; - private PreloadConfiguration preloadConfiguration; + private ExoPlayerImpl.PreloadConfiguration preloadConfiguration; private List preloadPriorityList; /** @@ -100,7 +99,7 @@ import java.util.List; AnalyticsCollector analyticsCollector, HandlerWrapper analyticsCollectorHandler, MediaPeriodHolder.Factory mediaPeriodHolderFactory, - PreloadConfiguration preloadConfiguration) { + ExoPlayerImpl.PreloadConfiguration preloadConfiguration) { this.analyticsCollector = analyticsCollector; this.analyticsCollectorHandler = analyticsCollectorHandler; this.mediaPeriodHolderFactory = mediaPeriodHolderFactory; @@ -143,7 +142,7 @@ import java.util.List; * @param preloadConfiguration The new preload configuration. */ public void updatePreloadConfiguration( - Timeline timeline, PreloadConfiguration preloadConfiguration) { + Timeline timeline, ExoPlayerImpl.PreloadConfiguration preloadConfiguration) { this.preloadConfiguration = preloadConfiguration; invalidatePreloadPool(timeline); } diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/SimpleExoPlayer.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/SimpleExoPlayer.java index 0c38eccc6f..231ba4af43 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/SimpleExoPlayer.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/SimpleExoPlayer.java @@ -992,18 +992,6 @@ public class SimpleExoPlayer extends BasePlayer player.setRepeatMode(repeatMode); } - @Override - public void setPreloadConfiguration(PreloadConfiguration preloadConfiguration) { - blockUntilConstructorFinished(); - player.setPreloadConfiguration(preloadConfiguration); - } - - @Override - public PreloadConfiguration getPreloadConfiguration() { - blockUntilConstructorFinished(); - return player.getPreloadConfiguration(); - } - @Override public void setShuffleModeEnabled(boolean shuffleModeEnabled) { blockUntilConstructorFinished(); diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/ExoPlayerTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/ExoPlayerTest.java index 8ce6082f24..505650ba62 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/ExoPlayerTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/ExoPlayerTest.java @@ -274,16 +274,14 @@ public class ExoPlayerTest { } private TestExoPlayerBuilder parameterizeTestExoPlayerBuilder(TestExoPlayerBuilder builder) { - return builder.setPreloadConfiguration(createPreloadConfiguration()); + // TODO: set PreloadConfiguration when enabled again after the release. + return builder; } private ExoPlayerTestRunner.Builder parameterizeExoPlayerTestRunnerBuilder( ExoPlayerTestRunner.Builder builder) { - return builder.setPreloadConfiguration(createPreloadConfiguration()); - } - - private ExoPlayer.PreloadConfiguration createPreloadConfiguration() { - return new ExoPlayer.PreloadConfiguration(getTargetPreloadDurationUs()); + // TODO: set PreloadConfiguration when enabled again after the release. + return builder; } /** @@ -6808,80 +6806,6 @@ public class ExoPlayerTest { Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE /* source prepared */); } - @Test - public void prepare_preloadingEnabled_nextWindowPeriodCreatedForPreloading() throws Exception { - FakeMediaSource mediaSource1 = - new FakeMediaSource( - new FakeTimeline( - new TimelineWindowDefinition( - /* isSeekable= */ true, - /* isDynamic= */ false, - /* durationUs= */ DefaultLoadControl.DEFAULT_MAX_BUFFER_MS * 2))); - List createdMediaPeriodIds = new ArrayList<>(); - FakeMediaSource mediaSource2 = - new FakeMediaSource() { - @Override - public MediaPeriod createPeriod( - MediaPeriodId id, Allocator allocator, long startPositionUs) { - createdMediaPeriodIds.add(id); - return super.createPeriod(id, allocator, startPositionUs); - } - }; - ExoPlayer player = - // Intentionally not using `parameterizeTestExoPlayerBuilder()` for preload specific test. - new TestExoPlayerBuilder(context) - .setPreloadConfiguration( - new ExoPlayer.PreloadConfiguration(/* targetPreloadDurationUs= */ 5_000_000L)) - .build(); - player.setMediaSources(ImmutableList.of(mediaSource1, mediaSource2)); - - player.prepare(); - run(player).untilPendingCommandsAreFullyHandled(); - - assertThat(createdMediaPeriodIds).hasSize(1); - play(player).untilState(Player.STATE_ENDED); - assertThat(createdMediaPeriodIds).hasSize(1); - player.release(); - } - - @Test - public void prepare_preloadingEnabledRepeatModeOne_sameWindowPeriodCreatedForPreloading() - throws Exception { - FakeTimeline timeline = - new FakeTimeline( - new TimelineWindowDefinition( - /* isSeekable= */ true, - /* isDynamic= */ false, - /* durationUs= */ DefaultLoadControl.DEFAULT_MAX_BUFFER_MS * 2)); - List createdMediaPeriodIds = new ArrayList<>(); - FakeMediaSource mediaSource = - new FakeMediaSource(timeline) { - @Override - public MediaPeriod createPeriod( - MediaPeriodId id, Allocator allocator, long startPositionUs) { - createdMediaPeriodIds.add(id); - return super.createPeriod(id, allocator, startPositionUs); - } - }; - ExoPlayer player = - // Intentionally not using `parameterizeTestExoPlayerBuilder()` for preload specific test. - new TestExoPlayerBuilder(context) - .setPreloadConfiguration( - new ExoPlayer.PreloadConfiguration(/* targetPreloadDurationUs= */ 5_000_000L)) - .build(); - player.setRepeatMode(Player.REPEAT_MODE_ONE); - player.setMediaSource(mediaSource); - - player.prepare(); - run(player).untilPendingCommandsAreFullyHandled(); - - assertThat(createdMediaPeriodIds).hasSize(2); - player.setRepeatMode(Player.REPEAT_MODE_OFF); - play(player).untilState(Player.STATE_ENDED); - assertThat(createdMediaPeriodIds).hasSize(2); - player.release(); - } - @Test public void seekToIndexLargerThanNumberOfPlaylistItems() throws Exception { Timeline fakeTimeline = @@ -14583,7 +14507,6 @@ public class ExoPlayerTest { new DefaultRenderersFactory(context).setAllowedVideoJoiningTimeMs(0)) .setClock(new FakeClock(/* isAutoAdvancing= */ true)) .build(); - player.setPreloadConfiguration(createPreloadConfiguration()); player.setPauseAtEndOfMediaItems(true); Surface surface = new Surface(new SurfaceTexture(/* texName= */ 0)); player.setVideoSurface(surface); diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/MediaPeriodQueueTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/MediaPeriodQueueTest.java index b9232ee1f0..f87bf94642 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/MediaPeriodQueueTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/MediaPeriodQueueTest.java @@ -40,7 +40,7 @@ import androidx.media3.common.Timeline; import androidx.media3.common.Tracks; import androidx.media3.common.util.Clock; import androidx.media3.common.util.HandlerWrapper; -import androidx.media3.exoplayer.ExoPlayer.PreloadConfiguration; +import androidx.media3.exoplayer.ExoPlayerImpl.PreloadConfiguration; import androidx.media3.exoplayer.analytics.AnalyticsCollector; import androidx.media3.exoplayer.analytics.DefaultAnalyticsCollector; import androidx.media3.exoplayer.analytics.PlayerId; diff --git a/libraries/test_utils/src/main/java/androidx/media3/test/utils/ExoPlayerTestRunner.java b/libraries/test_utils/src/main/java/androidx/media3/test/utils/ExoPlayerTestRunner.java index 808268ff34..0daf21bf59 100644 --- a/libraries/test_utils/src/main/java/androidx/media3/test/utils/ExoPlayerTestRunner.java +++ b/libraries/test_utils/src/main/java/androidx/media3/test/utils/ExoPlayerTestRunner.java @@ -284,16 +284,6 @@ public final class ExoPlayerTestRunner implements Player.Listener, ActionSchedul return this; } - /** - * @see ExoPlayer#setPreloadConfiguration(ExoPlayer.PreloadConfiguration) - * @return This builder. - */ - @CanIgnoreReturnValue - public Builder setPreloadConfiguration(ExoPlayer.PreloadConfiguration preloadConfiguration) { - testPlayerBuilder.setPreloadConfiguration(preloadConfiguration); - return this; - } - /** * Sets an {@link ActionSchedule} to be run by the test runner. The first action will be * executed immediately before {@link ExoPlayer#prepare()}. diff --git a/libraries/test_utils/src/main/java/androidx/media3/test/utils/StubExoPlayer.java b/libraries/test_utils/src/main/java/androidx/media3/test/utils/StubExoPlayer.java index 8a13d08712..f21d7283f2 100644 --- a/libraries/test_utils/src/main/java/androidx/media3/test/utils/StubExoPlayer.java +++ b/libraries/test_utils/src/main/java/androidx/media3/test/utils/StubExoPlayer.java @@ -154,16 +154,6 @@ public class StubExoPlayer extends StubPlayer implements ExoPlayer { throw new UnsupportedOperationException(); } - @Override - public void setPreloadConfiguration(PreloadConfiguration preloadConfiguration) { - throw new UnsupportedOperationException(); - } - - @Override - public PreloadConfiguration getPreloadConfiguration() { - throw new UnsupportedOperationException(); - } - @Override public void setMediaSource(MediaSource mediaSource) { throw new UnsupportedOperationException(); diff --git a/libraries/test_utils/src/main/java/androidx/media3/test/utils/TestExoPlayerBuilder.java b/libraries/test_utils/src/main/java/androidx/media3/test/utils/TestExoPlayerBuilder.java index 73bdb26ea4..378a01e81e 100644 --- a/libraries/test_utils/src/main/java/androidx/media3/test/utils/TestExoPlayerBuilder.java +++ b/libraries/test_utils/src/main/java/androidx/media3/test/utils/TestExoPlayerBuilder.java @@ -56,7 +56,6 @@ public class TestExoPlayerBuilder { private long seekForwardIncrementMs; private boolean deviceVolumeControlEnabled; private boolean suppressPlaybackWhenUnsuitableOutput; - @Nullable private ExoPlayer.PreloadConfiguration preloadConfiguration; private boolean dynamicSchedulingEnabled; public TestExoPlayerBuilder(Context context) { @@ -162,18 +161,6 @@ public class TestExoPlayerBuilder { return this; } - /** - * Sets the preload configuration. - * - * @see ExoPlayer#setPreloadConfiguration(ExoPlayer.PreloadConfiguration) - */ - @CanIgnoreReturnValue - public TestExoPlayerBuilder setPreloadConfiguration( - ExoPlayer.PreloadConfiguration preloadConfiguration) { - this.preloadConfiguration = preloadConfiguration; - return this; - } - /** * Returns the {@link Renderer Renderers} that have been set with {@link #setRenderers} or null if * no {@link Renderer Renderers} have been explicitly set. Note that these renderers may not be @@ -386,9 +373,6 @@ public class TestExoPlayerBuilder { builder.setMediaSourceFactory(mediaSourceFactory); } ExoPlayer exoPlayer = builder.build(); - if (preloadConfiguration != null) { - exoPlayer.setPreloadConfiguration(preloadConfiguration); - } return exoPlayer; } }