Skip to content

Commit

Permalink
Add MediaSource.Factory and deprecate MediaSourceFactory
Browse files Browse the repository at this point in the history
This more closely matches the pattern we have for all implementations
except DefaultMediaSourceFactory (e.g. ProgressiveMediaSource.Factory)
and other factory interfaces like (Http)DataSource.Factory.

PiperOrigin-RevId: 417826803
  • Loading branch information
icbaker authored and tonihei committed Jan 4, 2022
1 parent 88fe829 commit 5e8d1eb
Show file tree
Hide file tree
Showing 28 changed files with 168 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException;
import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ads.AdsLoader;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.ui.StyledPlayerControlView;
Expand Down Expand Up @@ -261,7 +261,7 @@ protected boolean initializePlayer() {
intent.getBooleanExtra(IntentUtil.PREFER_EXTENSION_DECODERS_EXTRA, false);
RenderersFactory renderersFactory =
DemoUtil.buildRenderersFactory(/* context= */ this, preferExtensionDecoders);
MediaSourceFactory mediaSourceFactory =
MediaSource.Factory mediaSourceFactory =
new DefaultMediaSourceFactory(dataSourceFactory)
.setAdsLoaderProvider(this::getAdsLoader)
.setAdViewProvider(playerView);
Expand Down
2 changes: 1 addition & 1 deletion docs/ad-insertion.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ build and inject a `DefaultMediaSourceFactory` configured with an
`AdsLoader.Provider` and an `AdViewProvider` when creating the player:

~~~
MediaSourceFactory mediaSourceFactory =
MediaSource.Factory mediaSourceFactory =
new DefaultMediaSourceFactory(context)
.setAdsLoaderProvider(adsLoaderProvider)
.setAdViewProvider(playerView);
Expand Down
12 changes: 6 additions & 6 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Components common to all `ExoPlayer` implementations are:

* `MediaSource` instances that define media to be played, load the media, and
from which the loaded media can be read. `MediaSource` instances are created
from `MediaItem`s by a `MediaSourceFactory` inside the player. They can also
from `MediaItem`s by a `MediaSource.Factory` inside the player. They can also
be passed directly to the player using the [media source based playlist API].
* A `MediaSourceFactory` that converts `MediaItem`s to `MediaSource`s. The
`MediaSourceFactory` is injected when the player is created.
* A `MediaSource.Factory` that converts `MediaItem`s to `MediaSource`s. The
`MediaSource.Factory` is injected when the player is created.
* `Renderer`s that render individual components of the media. `Renderer`s are
injected when the player is created.
* A `TrackSelector` that selects tracks provided by the `MediaSource` to be
Expand Down Expand Up @@ -245,9 +245,9 @@ required. Some use cases for custom implementations are:
appropriate if you wish to obtain media samples to feed to renderers in a
custom way, or if you wish to implement custom `MediaSource` compositing
behavior.
* `MediaSourceFactory` – Implementing a custom `MediaSourceFactory` allows
an application to customize the way in which `MediaSource`s are created from
`MediaItem`s.
* `MediaSource.Factory` – Implementing a custom `MediaSource.Factory`
allows an application to customize the way in which `MediaSource`s are created
from `MediaItem`s.
* `DataSource` – ExoPlayer’s upstream package already contains a number of
`DataSource` implementations for different use cases. You may want to
implement you own `DataSource` class to load data in another way, such as over
Expand Down
4 changes: 2 additions & 2 deletions docs/drm.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ building the media item.

If an app wants to customise the `DrmSessionManager` used for playback, they can
implement a `DrmSessionManagerProvider` and pass this to the
`MediaSourceFactory` which is [used when building the player]. The provider can
`MediaSource.Factory` which is [used when building the player]. The provider can
choose whether to instantiate a new manager instance each time or not. To always
use the same instance:

~~~
DrmSessionManager customDrmSessionManager =
new CustomDrmSessionManager(/* ... */);
// Pass a drm session manager provider to the media source factory.
MediaSourceFactory mediaSourceFactory =
MediaSource.Factory mediaSourceFactory =
new DefaultMediaSourceFactory(dataSourceFactory)
.setDrmSessionManagerProvider(mediaItem -> customDrmSessionManager);
~~~
Expand Down
2 changes: 1 addition & 1 deletion docs/media-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Media items

The [playlist API][] is based on `MediaItem`s, which can be conveniently built
using `MediaItem.Builder`. Inside the player, media items are converted into
playable `MediaSource`s by a `MediaSourceFactory`. Without
playable `MediaSource`s by a `MediaSource.Factory`. Without
[custom configuration]({{ site.baseurl }}/media-sources.html#customizing-media-source-creation),
this conversion is carried out by a `DefaultMediaSourceFactory`, which is
capable of building complex media sources corresponding to the properties of the
Expand Down
12 changes: 6 additions & 6 deletions docs/media-sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ redirect_from:

In ExoPlayer every piece of media is represented by a `MediaItem`. However
internally, the player needs `MediaSource` instances to play the content. The
player creates these from media items using a `MediaSourceFactory`.
player creates these from media items using a `MediaSource.Factory`.

By default the player uses a `DefaultMediaSourceFactory`, which can create
instances of the following content `MediaSource` implementations:
Expand All @@ -27,13 +27,13 @@ customization.

## Customizing media source creation ##

When building the player, a `MediaSourceFactory` can be injected. For example, if
an app wants to insert ads and use a `CacheDataSource.Factory` to support
When building the player, a `MediaSource.Factory` can be injected. For example,
if an app wants to insert ads and use a `CacheDataSource.Factory` to support
caching, an instance of `DefaultMediaSourceFactory` can be configured to match
these requirements and injected during player construction:

~~~
MediaSourceFactory mediaSourceFactory =
MediaSource.Factory mediaSourceFactory =
new DefaultMediaSourceFactory(cacheDataSourceFactory)
.setAdsLoaderProvider(adsLoaderProvider)
.setAdViewProvider(playerView);
Expand All @@ -47,7 +47,7 @@ The
[`DefaultMediaSourceFactory` JavaDoc]({{ site.baseurl }}/doc/reference/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.html)
describes the available options in more detail.

It's also possible to inject a custom `MediaSourceFactory` implementation, for
It's also possible to inject a custom `MediaSource.Factory` implementation, for
example to support creation of a custom media source type. The factory's
`createMediaSource(MediaItem)` will be called to create a media source for each
media item that is
Expand All @@ -57,7 +57,7 @@ media item that is

The [`ExoPlayer`] interface defines additional playlist methods that accept
media sources rather than media items. This makes it possible to bypass the
player's internal `MediaSourceFactory` and pass media source instances to the
player's internal `MediaSource.Factory` and pass media source instances to the
player directly:

~~~
Expand Down
10 changes: 5 additions & 5 deletions docs/shrinking.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ ExoPlayer player =

## Custom `MediaSource` instantiation ##

If your app is using a custom `MediaSourceFactory` and you want
If your app is using a custom `MediaSource.Factory` and you want
`DefaultMediaSourceFactory` to be removed by code stripping, you should pass
your `MediaSourceFactory` directly to the `ExoPlayer.Builder` constructor.
your `MediaSource.Factory` directly to the `ExoPlayer.Builder` constructor.

~~~
ExoPlayer player =
Expand All @@ -117,13 +117,13 @@ ExoPlayer player =
{: .language-java}

If your app is using `MediaSource`s directly instead of `MediaItem`s you should
pass `MediaSourceFactory.UNSUPPORTED` to the `ExoPlayer.Builder` constructor, to
ensure `DefaultMediaSourceFactory` and `DefaultExtractorsFactory` can be
pass `MediaSource.Factory.UNSUPPORTED` to the `ExoPlayer.Builder` constructor,
to ensure `DefaultMediaSourceFactory` and `DefaultExtractorsFactory` can be
stripped by code shrinking.

~~~
ExoPlayer player =
new ExoPlayer.Builder(context, MediaSourceFactory.UNSUPPORTED).build();
new ExoPlayer.Builder(context, MediaSource.Factory.UNSUPPORTED).build();
ProgressiveMediaSource mediaSource =
new ProgressiveMediaSource.Factory(
dataSourceFactory, customExtractorsFactory)
Expand Down
2 changes: 1 addition & 1 deletion docs/transforming-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ transformer.startTransformation(inputMediaItem, outputPath);
~~~
{: .language-java}

Other parameters, such as the `MediaSourceFactory`, can be passed to the
Other parameters, such as the `MediaSource.Factory`, can be passed to the
builder.

`startTransformation` receives a `MediaItem` describing the input, and a path or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import com.google.android.exoplayer2.ExoPlayerLibraryInfo;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ads.AdsLoader;
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
import com.google.android.exoplayer2.ui.AdViewProvider;
Expand Down Expand Up @@ -222,7 +222,7 @@ public Builder setCompanionAdSlots(Collection<CompanionAdSlot> companionAdSlots)

/**
* Sets the MIME types to prioritize for linear ad media. If not specified, MIME types supported
* by the {@link MediaSourceFactory adMediaSourceFactory} used to construct the {@link
* by the {@link MediaSource.Factory adMediaSourceFactory} used to construct the {@link
* AdsMediaSource} will be used.
*
* @param adMediaMimeTypes The MIME types to prioritize for linear ad media. May contain {@link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.google.android.exoplayer2.metadata.MetadataRenderer;
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ShuffleOrder;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.TextRenderer;
Expand Down Expand Up @@ -77,7 +76,7 @@
* <ul>
* <li><b>{@link MediaSource MediaSources}</b> that define the media to be played, load the media,
* and from which the loaded media can be read. MediaSources are created from {@link MediaItem
* MediaItems} by the {@link MediaSourceFactory} injected into the player {@link
* MediaItems} by the {@link MediaSource.Factory} injected into the player {@link
* Builder#setMediaSourceFactory Builder}, or can be added directly by methods like {@link
* #setMediaSource(MediaSource)}. The library provides a {@link DefaultMediaSourceFactory} for
* progressive media files, DASH, SmoothStreaming and HLS, which also includes functionality
Expand Down Expand Up @@ -368,7 +367,7 @@ final class Builder {
/* package */ Clock clock;
/* package */ long foregroundModeTimeoutMs;
/* package */ Supplier<RenderersFactory> renderersFactorySupplier;
/* package */ Supplier<MediaSourceFactory> mediaSourceFactorySupplier;
/* package */ Supplier<MediaSource.Factory> mediaSourceFactorySupplier;
/* package */ Supplier<TrackSelector> trackSelectorSupplier;
/* package */ Supplier<LoadControl> loadControlSupplier;
/* package */ Supplier<BandwidthMeter> bandwidthMeterSupplier;
Expand Down Expand Up @@ -396,7 +395,7 @@ final class Builder {
* Creates a builder.
*
* <p>Use {@link #Builder(Context, RenderersFactory)}, {@link #Builder(Context,
* MediaSourceFactory)} or {@link #Builder(Context, RenderersFactory, MediaSourceFactory)}
* MediaSource.Factory)} or {@link #Builder(Context, RenderersFactory, MediaSource.Factory)}
* instead, if you intend to provide a custom {@link RenderersFactory}, {@link
* ExtractorsFactory} or {@link DefaultMediaSourceFactory}. This is to ensure that ProGuard or
* R8 can remove ExoPlayer's {@link DefaultRenderersFactory}, {@link DefaultExtractorsFactory}
Expand All @@ -407,7 +406,7 @@ final class Builder {
* <ul>
* <li>{@link RenderersFactory}: {@link DefaultRenderersFactory}
* <li>{@link TrackSelector}: {@link DefaultTrackSelector}
* <li>{@link MediaSourceFactory}: {@link DefaultMediaSourceFactory}
* <li>{@link MediaSource.Factory}: {@link DefaultMediaSourceFactory}
* <li>{@link LoadControl}: {@link DefaultLoadControl}
* <li>{@link BandwidthMeter}: {@link DefaultBandwidthMeter#getSingletonInstance(Context)}
* <li>{@link LivePlaybackSpeedControl}: {@link DefaultLivePlaybackSpeedControl}
Expand Down Expand Up @@ -462,7 +461,7 @@ public Builder(Context context, RenderersFactory renderersFactory) {
}

/**
* Creates a builder with a custom {@link MediaSourceFactory}.
* Creates a builder with a custom {@link MediaSource.Factory}.
*
* <p>See {@link #Builder(Context)} for a list of default values.
*
Expand All @@ -474,12 +473,12 @@ public Builder(Context context, RenderersFactory renderersFactory) {
* @param mediaSourceFactory A factory for creating a {@link MediaSource} from a {@link
* MediaItem}.
*/
public Builder(Context context, MediaSourceFactory mediaSourceFactory) {
public Builder(Context context, MediaSource.Factory mediaSourceFactory) {
this(context, () -> new DefaultRenderersFactory(context), () -> mediaSourceFactory);
}

/**
* Creates a builder with a custom {@link RenderersFactory} and {@link MediaSourceFactory}.
* Creates a builder with a custom {@link RenderersFactory} and {@link MediaSource.Factory}.
*
* <p>See {@link #Builder(Context)} for a list of default values.
*
Expand All @@ -494,7 +493,9 @@ public Builder(Context context, MediaSourceFactory mediaSourceFactory) {
* MediaItem}.
*/
public Builder(
Context context, RenderersFactory renderersFactory, MediaSourceFactory mediaSourceFactory) {
Context context,
RenderersFactory renderersFactory,
MediaSource.Factory mediaSourceFactory) {
this(context, () -> renderersFactory, () -> mediaSourceFactory);
}

Expand All @@ -507,7 +508,7 @@ public Builder(
* @param context A {@link Context}.
* @param renderersFactory A factory for creating {@link Renderer Renderers} to be used by the
* player.
* @param mediaSourceFactory A {@link MediaSourceFactory}.
* @param mediaSourceFactory A {@link MediaSource.Factory}.
* @param trackSelector A {@link TrackSelector}.
* @param loadControl A {@link LoadControl}.
* @param bandwidthMeter A {@link BandwidthMeter}.
Expand All @@ -516,7 +517,7 @@ public Builder(
public Builder(
Context context,
RenderersFactory renderersFactory,
MediaSourceFactory mediaSourceFactory,
MediaSource.Factory mediaSourceFactory,
TrackSelector trackSelector,
LoadControl loadControl,
BandwidthMeter bandwidthMeter,
Expand All @@ -534,7 +535,7 @@ public Builder(
private Builder(
Context context,
Supplier<RenderersFactory> renderersFactorySupplier,
Supplier<MediaSourceFactory> mediaSourceFactorySupplier) {
Supplier<MediaSource.Factory> mediaSourceFactorySupplier) {
this(
context,
renderersFactorySupplier,
Expand All @@ -548,7 +549,7 @@ private Builder(
private Builder(
Context context,
Supplier<RenderersFactory> renderersFactorySupplier,
Supplier<MediaSourceFactory> mediaSourceFactorySupplier,
Supplier<MediaSource.Factory> mediaSourceFactorySupplier,
Supplier<TrackSelector> trackSelectorSupplier,
Supplier<LoadControl> loadControlSupplier,
Supplier<BandwidthMeter> bandwidthMeterSupplier,
Expand Down Expand Up @@ -607,13 +608,13 @@ public Builder setRenderersFactory(RenderersFactory renderersFactory) {
}

/**
* Sets the {@link MediaSourceFactory} that will be used by the player.
* Sets the {@link MediaSource.Factory} that will be used by the player.
*
* @param mediaSourceFactory A {@link MediaSourceFactory}.
* @param mediaSourceFactory A {@link MediaSource.Factory}.
* @return This builder.
* @throws IllegalStateException If {@link #build()} has already been called.
*/
public Builder setMediaSourceFactory(MediaSourceFactory mediaSourceFactory) {
public Builder setMediaSourceFactory(MediaSource.Factory mediaSourceFactory) {
checkState(!buildCalled);
this.mediaSourceFactorySupplier = () -> mediaSourceFactory;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ShuffleOrder;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
Expand Down Expand Up @@ -133,7 +132,7 @@
private final Timeline.Window window;
private final List<MediaSourceHolderSnapshot> mediaSourceHolderSnapshots;
private final boolean useLazyPreparation;
private final MediaSourceFactory mediaSourceFactory;
private final MediaSource.Factory mediaSourceFactory;
private final AnalyticsCollector analyticsCollector;
private final Looper applicationLooper;
private final BandwidthMeter bandwidthMeter;
Expand Down Expand Up @@ -172,7 +171,7 @@
*
* @param renderers The {@link Renderer}s.
* @param trackSelector The {@link TrackSelector}.
* @param mediaSourceFactory The {@link MediaSourceFactory}.
* @param mediaSourceFactory The {@link MediaSource.Factory}.
* @param loadControl The {@link LoadControl}.
* @param bandwidthMeter The {@link BandwidthMeter}.
* @param analyticsCollector The {@link AnalyticsCollector}.
Expand All @@ -196,7 +195,7 @@
public ExoPlayerImpl(
Renderer[] renderers,
TrackSelector trackSelector,
MediaSourceFactory mediaSourceFactory,
MediaSource.Factory mediaSourceFactory,
LoadControl loadControl,
BandwidthMeter bandwidthMeter,
AnalyticsCollector analyticsCollector,
Expand Down
Loading

0 comments on commit 5e8d1eb

Please sign in to comment.