Add convenience constructor methods.

When passing in ExtractorFactory instances to SimpleExoPlayer.Builder or
DefaultMediaSourceFactory, we currently need to pass in one other
instance (RenderersFactory or DataSource.Factory), that developers will
often set to its default. To avoid specifying these defaults, these new
convience methods allow to just set the ExtractorsFactory if required.

PiperOrigin-RevId: 330908002
This commit is contained in:
tonihei 2020-09-10 12:12:23 +01:00 committed by Oliver Woodman
parent 0266971406
commit 4d2a2384d6
2 changed files with 33 additions and 14 deletions

View File

@ -54,7 +54,6 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.Log;
@ -118,11 +117,11 @@ public class SimpleExoPlayer extends BasePlayer
/**
* Creates a builder.
*
* <p>Use {@link #Builder(Context, RenderersFactory)} or {@link #Builder(Context,
* RenderersFactory, ExtractorsFactory)} instead, if you intend to provide a custom {@link
* RenderersFactory} or a custom {@link ExtractorsFactory}. This is to ensure that ProGuard or
* R8 can remove ExoPlayer's {@link DefaultRenderersFactory} and {@link
* DefaultExtractorsFactory} from the APK.
* <p>Use {@link #Builder(Context, RenderersFactory)}, {@link #Builder(Context,
* RenderersFactory)} or {@link #Builder(Context, RenderersFactory, ExtractorsFactory)} instead,
* if you intend to provide a custom {@link RenderersFactory} or a custom {@link
* ExtractorsFactory}. This is to ensure that ProGuard or R8 can remove ExoPlayer's {@link
* DefaultRenderersFactory} and {@link DefaultExtractorsFactory} from the APK.
*
* <p>The builder uses the following default values:
*
@ -167,6 +166,19 @@ public class SimpleExoPlayer extends BasePlayer
this(context, renderersFactory, new DefaultExtractorsFactory());
}
/**
* Creates a builder with a custom {@link ExtractorsFactory}.
*
* <p>See {@link #Builder(Context)} for a list of default values.
*
* @param context A {@link Context}.
* @param extractorsFactory An {@link ExtractorsFactory} used to extract progressive media from
* its container.
*/
public Builder(Context context, ExtractorsFactory extractorsFactory) {
this(context, new DefaultRenderersFactory(context), extractorsFactory);
}
/**
* Creates a builder with a custom {@link RenderersFactory} and {@link ExtractorsFactory}.
*
@ -184,10 +196,7 @@ public class SimpleExoPlayer extends BasePlayer
context,
renderersFactory,
new DefaultTrackSelector(context),
new DefaultMediaSourceFactory(
new DefaultDataSourceFactory(
context, Util.getUserAgent(context, ExoPlayerLibraryInfo.VERSION_SLASHY)),
extractorsFactory),
new DefaultMediaSourceFactory(context, extractorsFactory),
new DefaultLoadControl(),
DefaultBandwidthMeter.getSingletonInstance(context),
new AnalyticsCollector(Clock.DEFAULT));
@ -570,7 +579,7 @@ public class SimpleExoPlayer extends BasePlayer
Clock clock,
Looper applicationLooper) {
this(
new Builder(context, renderersFactory, new DefaultExtractorsFactory())
new Builder(context, renderersFactory)
.setTrackSelector(trackSelector)
.setMediaSourceFactory(mediaSourceFactory)
.setLoadControl(loadControl)

View File

@ -65,9 +65,8 @@ import java.util.List;
* MediaItem.PlaybackProperties#uri uri} doesn't match one of the above. It tries to infer the
* required extractor by using the {@link
* com.google.android.exoplayer2.extractor.DefaultExtractorsFactory} or the {@link
* ExtractorsFactory} provided in {@link #DefaultMediaSourceFactory(DataSource.Factory,
* ExtractorsFactory)}. An {@link UnrecognizedInputFormatException} is thrown if none of the
* available extractors can read the stream.
* ExtractorsFactory} provided in the constructor. An {@link UnrecognizedInputFormatException}
* is thrown if none of the available extractors can read the stream.
* </ul>
*
* <h3>Ad support for media items with ad tag URIs</h3>
@ -117,6 +116,17 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
this(new DefaultDataSourceFactory(context));
}
/**
* Creates a new instance.
*
* @param context Any context.
* @param extractorsFactory An {@link ExtractorsFactory} used to extract progressive media from
* its container.
*/
public DefaultMediaSourceFactory(Context context, ExtractorsFactory extractorsFactory) {
this(new DefaultDataSourceFactory(context), extractorsFactory);
}
/**
* Creates a new instance.
*