mirror of
https://github.com/androidx/media.git
synced 2025-05-05 22:50:57 +08:00
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:
parent
0266971406
commit
4d2a2384d6
@ -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
|
|||||||
/**
|
/**
|
||||||
* 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:
|
||||||
*
|
*
|
||||||
@ -167,6 +166,19 @@ public class SimpleExoPlayer extends BasePlayer
|
|||||||
this(context, renderersFactory, new DefaultExtractorsFactory());
|
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}.
|
* Creates a builder with a custom {@link RenderersFactory} and {@link ExtractorsFactory}.
|
||||||
*
|
*
|
||||||
@ -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
|
|||||||
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;
|
|||||||
* 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>
|
||||||
@ -117,6 +116,17 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
|||||||
this(new DefaultDataSourceFactory(context));
|
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.
|
* Creates a new instance.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user