Deprecate LoopingMediaSource.

There is no use case left where we couldn't use a better
alternative (either looping in the player, using the Player
playlist API, or ConcatenatingMediaSource for advanced cases)

PiperOrigin-RevId: 367990981
This commit is contained in:
tonihei 2021-04-12 14:36:22 +01:00 committed by marcbaechinger
parent e499f6d38c
commit aa54aa64b8
4 changed files with 18 additions and 22 deletions

View File

@ -26,16 +26,10 @@ import com.google.android.exoplayer2.audio.AudioSink;
import com.google.android.exoplayer2.audio.DefaultAudioSink; import com.google.android.exoplayer2.audio.DefaultAudioSink;
import com.google.android.exoplayer2.audio.MediaCodecAudioRenderer; import com.google.android.exoplayer2.audio.MediaCodecAudioRenderer;
import com.google.android.exoplayer2.metadata.MetadataRenderer; import com.google.android.exoplayer2.metadata.MetadataRenderer;
import com.google.android.exoplayer2.source.ClippingMediaSource;
import com.google.android.exoplayer2.source.ConcatenatingMediaSource;
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory; import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
import com.google.android.exoplayer2.source.LoopingMediaSource;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceFactory; import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.MergingMediaSource;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.source.ShuffleOrder; import com.google.android.exoplayer2.source.ShuffleOrder;
import com.google.android.exoplayer2.source.SingleSampleMediaSource;
import com.google.android.exoplayer2.text.TextRenderer; import com.google.android.exoplayer2.text.TextRenderer;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector;
@ -61,15 +55,13 @@ import java.util.List;
* Components common to all ExoPlayer implementations are: * Components common to all ExoPlayer implementations are:
* *
* <ul> * <ul>
* <li>A <b>{@link MediaSource}</b> that defines the media to be played, loads the media, and from * <li><b>{@link MediaSource MediaSources}</b> that define the media to be played, load the media,
* which the loaded media can be read. A MediaSource is injected via {@link * and from which the loaded media can be read. MediaSources are created from {@link MediaItem
* #setMediaSource(MediaSource)} at the start of playback. The library modules provide default * MediaItems} by the {@link MediaSourceFactory} injected in the {@link
* implementations for progressive media files ({@link ProgressiveMediaSource}), DASH * Builder#setMediaSourceFactory Builder}, or can be added directly by methods like {@link
* (DashMediaSource), SmoothStreaming (SsMediaSource) and HLS (HlsMediaSource), an * #setMediaSource(MediaSource)}. The library provides a {@link DefaultMediaSourceFactory} for
* implementation for loading single media samples ({@link SingleSampleMediaSource}) that's * progressive media files, DASH, SmoothStreaming and HLS, including functionality for
* most often used for side-loaded subtitle files, and implementations for building more * side-loading subtitle files and clipping media.
* complex MediaSources from simpler ones ({@link MergingMediaSource}, {@link
* ConcatenatingMediaSource}, {@link LoopingMediaSource} and {@link ClippingMediaSource}).
* <li><b>{@link Renderer}</b>s that render individual components of the media. The library * <li><b>{@link Renderer}</b>s that render individual components of the media. The library
* provides default implementations for common media types ({@link MediaCodecVideoRenderer}, * provides default implementations for common media types ({@link MediaCodecVideoRenderer},
* {@link MediaCodecAudioRenderer}, {@link TextRenderer} and {@link MetadataRenderer}). A * {@link MediaCodecAudioRenderer}, {@link TextRenderer} and {@link MetadataRenderer}). A

View File

@ -32,9 +32,15 @@ import java.util.Map;
/** /**
* Loops a {@link MediaSource} a specified number of times. * Loops a {@link MediaSource} a specified number of times.
* *
* <p>Note: To loop a {@link MediaSource} indefinitely, it is usually better to use {@link * @deprecated To loop a {@link MediaSource} indefinitely, use {@link Player#setRepeatMode(int)}
* ExoPlayer#setRepeatMode(int)} instead of this class. * instead of this class. To add a {@link MediaSource} a specific number of times to the
* playlist, use {@link ExoPlayer#addMediaSource} in a loop with the same {@link MediaSource}.
* To combine repeated {@link MediaSource} instances into one {@link MediaSource}, for example
* to further wrap it in another {@link MediaSource}, use {@link ConcatenatingMediaSource} with
* the same {@link MediaSource} {@link ConcatenatingMediaSource#addMediaSource added} multiple
* times.
*/ */
@Deprecated
public final class LoopingMediaSource extends CompositeMediaSource<Void> { public final class LoopingMediaSource extends CompositeMediaSource<Void> {
private final MaskingMediaSource maskingMediaSource; private final MaskingMediaSource maskingMediaSource;

View File

@ -88,7 +88,6 @@ import com.google.android.exoplayer2.robolectric.TestPlayerRunHelper;
import com.google.android.exoplayer2.source.ClippingMediaSource; import com.google.android.exoplayer2.source.ClippingMediaSource;
import com.google.android.exoplayer2.source.CompositeMediaSource; import com.google.android.exoplayer2.source.CompositeMediaSource;
import com.google.android.exoplayer2.source.ConcatenatingMediaSource; import com.google.android.exoplayer2.source.ConcatenatingMediaSource;
import com.google.android.exoplayer2.source.LoopingMediaSource;
import com.google.android.exoplayer2.source.MaskingMediaSource; import com.google.android.exoplayer2.source.MaskingMediaSource;
import com.google.android.exoplayer2.source.MediaPeriod; import com.google.android.exoplayer2.source.MediaPeriod;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
@ -3643,7 +3642,6 @@ public final class ExoPlayerTest {
public void seekTo_windowIndexIsReset_deprecated() throws Exception { public void seekTo_windowIndexIsReset_deprecated() throws Exception {
FakeTimeline fakeTimeline = new FakeTimeline(); FakeTimeline fakeTimeline = new FakeTimeline();
FakeMediaSource mediaSource = new FakeMediaSource(fakeTimeline); FakeMediaSource mediaSource = new FakeMediaSource(fakeTimeline);
LoopingMediaSource loopingMediaSource = new LoopingMediaSource(mediaSource, 2);
final int[] windowIndex = {C.INDEX_UNSET}; final int[] windowIndex = {C.INDEX_UNSET};
final long[] positionMs = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; final long[] positionMs = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET};
final long[] bufferedPositions = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; final long[] bufferedPositions = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET};
@ -3677,7 +3675,7 @@ public final class ExoPlayerTest {
}) })
.build(); .build();
new ExoPlayerTestRunner.Builder(context) new ExoPlayerTestRunner.Builder(context)
.setMediaSources(loopingMediaSource) .setMediaSources(mediaSource, mediaSource)
.setActionSchedule(actionSchedule) .setActionSchedule(actionSchedule)
.build() .build()
.start() .start()
@ -3697,7 +3695,6 @@ public final class ExoPlayerTest {
public void seekTo_windowIndexIsReset() throws Exception { public void seekTo_windowIndexIsReset() throws Exception {
FakeTimeline fakeTimeline = new FakeTimeline(); FakeTimeline fakeTimeline = new FakeTimeline();
FakeMediaSource mediaSource = new FakeMediaSource(fakeTimeline); FakeMediaSource mediaSource = new FakeMediaSource(fakeTimeline);
LoopingMediaSource loopingMediaSource = new LoopingMediaSource(mediaSource, 2);
final int[] windowIndex = {C.INDEX_UNSET}; final int[] windowIndex = {C.INDEX_UNSET};
final long[] positionMs = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; final long[] positionMs = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET};
final long[] bufferedPositions = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET}; final long[] bufferedPositions = {C.TIME_UNSET, C.TIME_UNSET, C.TIME_UNSET};
@ -3731,7 +3728,7 @@ public final class ExoPlayerTest {
}) })
.build(); .build();
new ExoPlayerTestRunner.Builder(context) new ExoPlayerTestRunner.Builder(context)
.setMediaSources(loopingMediaSource) .setMediaSources(mediaSource, mediaSource)
.setActionSchedule(actionSchedule) .setActionSchedule(actionSchedule)
.build() .build()
.start() .start()

View File

@ -30,6 +30,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** Unit tests for {@link LoopingMediaSource}. */ /** Unit tests for {@link LoopingMediaSource}. */
@SuppressWarnings("deprecation") // Testing deprecated class.
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class LoopingMediaSourceTest { public class LoopingMediaSourceTest {