Commit 362d4f5b by tonihei Committed by Oliver Woodman

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
parent 06de13ec
......@@ -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:
*
......@@ -168,6 +167,19 @@ public class SimpleExoPlayer extends BasePlayer
}
/**
* 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}.
*
* <p>See {@link #Builder(Context)} for a list of default values.
......@@ -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)
......
......@@ -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>
......@@ -120,6 +119,17 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
/**
* 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.
*
* @param dataSourceFactory A {@link DataSource.Factory} to create {@link DataSource} instances
* for requesting media data.
*/
......
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