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; ...@@ -54,7 +54,6 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; 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.Assertions;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
...@@ -118,11 +117,11 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -118,11 +117,11 @@ public class SimpleExoPlayer extends BasePlayer
/** /**
* Creates a builder. * Creates a builder.
* *
* <p>Use {@link #Builder(Context, RenderersFactory)} or {@link #Builder(Context, * <p>Use {@link #Builder(Context, RenderersFactory)}, {@link #Builder(Context,
* RenderersFactory, ExtractorsFactory)} instead, if you intend to provide a custom {@link * RenderersFactory)} or {@link #Builder(Context, RenderersFactory, ExtractorsFactory)} instead,
* RenderersFactory} or a custom {@link ExtractorsFactory}. This is to ensure that ProGuard or * if you intend to provide a custom {@link RenderersFactory} or a custom {@link
* R8 can remove ExoPlayer's {@link DefaultRenderersFactory} and {@link * ExtractorsFactory}. This is to ensure that ProGuard or R8 can remove ExoPlayer's {@link
* DefaultExtractorsFactory} from the APK. * DefaultRenderersFactory} and {@link DefaultExtractorsFactory} from the APK.
* *
* <p>The builder uses the following default values: * <p>The builder uses the following default values:
* *
...@@ -168,6 +167,19 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -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}. * Creates a builder with a custom {@link RenderersFactory} and {@link ExtractorsFactory}.
* *
* <p>See {@link #Builder(Context)} for a list of default values. * <p>See {@link #Builder(Context)} for a list of default values.
...@@ -184,10 +196,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -184,10 +196,7 @@ public class SimpleExoPlayer extends BasePlayer
context, context,
renderersFactory, renderersFactory,
new DefaultTrackSelector(context), new DefaultTrackSelector(context),
new DefaultMediaSourceFactory( new DefaultMediaSourceFactory(context, extractorsFactory),
new DefaultDataSourceFactory(
context, Util.getUserAgent(context, ExoPlayerLibraryInfo.VERSION_SLASHY)),
extractorsFactory),
new DefaultLoadControl(), new DefaultLoadControl(),
DefaultBandwidthMeter.getSingletonInstance(context), DefaultBandwidthMeter.getSingletonInstance(context),
new AnalyticsCollector(Clock.DEFAULT)); new AnalyticsCollector(Clock.DEFAULT));
...@@ -570,7 +579,7 @@ public class SimpleExoPlayer extends BasePlayer ...@@ -570,7 +579,7 @@ public class SimpleExoPlayer extends BasePlayer
Clock clock, Clock clock,
Looper applicationLooper) { Looper applicationLooper) {
this( this(
new Builder(context, renderersFactory, new DefaultExtractorsFactory()) new Builder(context, renderersFactory)
.setTrackSelector(trackSelector) .setTrackSelector(trackSelector)
.setMediaSourceFactory(mediaSourceFactory) .setMediaSourceFactory(mediaSourceFactory)
.setLoadControl(loadControl) .setLoadControl(loadControl)
......
...@@ -65,9 +65,8 @@ import java.util.List; ...@@ -65,9 +65,8 @@ import java.util.List;
* MediaItem.PlaybackProperties#uri uri} doesn't match one of the above. It tries to infer the * MediaItem.PlaybackProperties#uri uri} doesn't match one of the above. It tries to infer the
* required extractor by using the {@link * required extractor by using the {@link
* com.google.android.exoplayer2.extractor.DefaultExtractorsFactory} or the {@link * com.google.android.exoplayer2.extractor.DefaultExtractorsFactory} or the {@link
* ExtractorsFactory} provided in {@link #DefaultMediaSourceFactory(DataSource.Factory, * ExtractorsFactory} provided in the constructor. An {@link UnrecognizedInputFormatException}
* ExtractorsFactory)}. An {@link UnrecognizedInputFormatException} is thrown if none of the * is thrown if none of the available extractors can read the stream.
* available extractors can read the stream.
* </ul> * </ul>
* *
* <h3>Ad support for media items with ad tag URIs</h3> * <h3>Ad support for media items with ad tag URIs</h3>
...@@ -120,6 +119,17 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { ...@@ -120,6 +119,17 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
/** /**
* Creates a new instance. * 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 * @param dataSourceFactory A {@link DataSource.Factory} to create {@link DataSource} instances
* for requesting media data. * 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