mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add DefaultMediaSourceFactory.setDataSourceFactory
Also add this to the stable API instead of the constructor that takes `DataSource.Factory`. PiperOrigin-RevId: 450414119
This commit is contained in:
parent
274f3a13a2
commit
e39a324b19
6 changed files with 60 additions and 17 deletions
|
|
@ -308,8 +308,11 @@ public class PlayerActivity extends AppCompatActivity
|
||||||
serverSideAdsLoader = serverSideAdLoaderBuilder.build();
|
serverSideAdsLoader = serverSideAdLoaderBuilder.build();
|
||||||
ImaServerSideAdInsertionMediaSource.Factory imaServerSideAdInsertionMediaSourceFactory =
|
ImaServerSideAdInsertionMediaSource.Factory imaServerSideAdInsertionMediaSourceFactory =
|
||||||
new ImaServerSideAdInsertionMediaSource.Factory(
|
new ImaServerSideAdInsertionMediaSource.Factory(
|
||||||
serverSideAdsLoader, new DefaultMediaSourceFactory(dataSourceFactory));
|
serverSideAdsLoader,
|
||||||
return new DefaultMediaSourceFactory(dataSourceFactory)
|
new DefaultMediaSourceFactory(/* context= */ this)
|
||||||
|
.setDataSourceFactory(dataSourceFactory));
|
||||||
|
return new DefaultMediaSourceFactory(/* context= */ this)
|
||||||
|
.setDataSourceFactory(dataSourceFactory)
|
||||||
.setDrmSessionManagerProvider(drmSessionManagerProvider)
|
.setDrmSessionManagerProvider(drmSessionManagerProvider)
|
||||||
.setLocalAdInsertionComponents(
|
.setLocalAdInsertionComponents(
|
||||||
this::getClientSideAdsLoader, /* adViewProvider= */ playerView)
|
this::getClientSideAdsLoader, /* adViewProvider= */ playerView)
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,8 @@ DataSource.Factory cacheDataSourceFactory =
|
||||||
|
|
||||||
ExoPlayer player = new ExoPlayer.Builder(context)
|
ExoPlayer player = new ExoPlayer.Builder(context)
|
||||||
.setMediaSourceFactory(
|
.setMediaSourceFactory(
|
||||||
new DefaultMediaSourceFactory(cacheDataSourceFactory))
|
new DefaultMediaSourceFactory(context)
|
||||||
|
.setDataSourceFactory(cacheDataSourceFactory))
|
||||||
.build();
|
.build();
|
||||||
~~~
|
~~~
|
||||||
{: .language-java}
|
{: .language-java}
|
||||||
|
|
@ -83,7 +84,9 @@ DataSource.Factory dataSourceFactory = () -> {
|
||||||
};
|
};
|
||||||
|
|
||||||
ExoPlayer player = new ExoPlayer.Builder(context)
|
ExoPlayer player = new ExoPlayer.Builder(context)
|
||||||
.setMediaSourceFactory(new DefaultMediaSourceFactory(dataSourceFactory))
|
.setMediaSourceFactory(
|
||||||
|
new DefaultMediaSourceFactory(context)
|
||||||
|
.setDataSourceFactory(dataSourceFactory))
|
||||||
.build();
|
.build();
|
||||||
~~~
|
~~~
|
||||||
{: .language-java}
|
{: .language-java}
|
||||||
|
|
|
||||||
|
|
@ -319,7 +319,8 @@ DataSource.Factory cacheDataSourceFactory =
|
||||||
|
|
||||||
ExoPlayer player = new ExoPlayer.Builder(context)
|
ExoPlayer player = new ExoPlayer.Builder(context)
|
||||||
.setMediaSourceFactory(
|
.setMediaSourceFactory(
|
||||||
new DefaultMediaSourceFactory(cacheDataSourceFactory))
|
new DefaultMediaSourceFactory(context)
|
||||||
|
.setDataSourceFactory(cacheDataSourceFactory))
|
||||||
.build();
|
.build();
|
||||||
~~~
|
~~~
|
||||||
{: .language-java}
|
{: .language-java}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ these requirements and injected during player construction:
|
||||||
|
|
||||||
~~~
|
~~~
|
||||||
MediaSource.Factory mediaSourceFactory =
|
MediaSource.Factory mediaSourceFactory =
|
||||||
new DefaultMediaSourceFactory(cacheDataSourceFactory)
|
new DefaultMediaSourceFactory(context)
|
||||||
|
.setDataSourceFactory(cacheDataSourceFactory)
|
||||||
.setLocalAdInsertionComponents(
|
.setLocalAdInsertionComponents(
|
||||||
adsLoaderProvider, /* adViewProvider= */ playerView);
|
adsLoaderProvider, /* adViewProvider= */ playerView);
|
||||||
ExoPlayer player = new ExoPlayer.Builder(context)
|
ExoPlayer player = new ExoPlayer.Builder(context)
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,9 @@ DefaultDataSource.Factory dataSourceFactory =
|
||||||
// Inject the DefaultDataSource.Factory when creating the player.
|
// Inject the DefaultDataSource.Factory when creating the player.
|
||||||
ExoPlayer player =
|
ExoPlayer player =
|
||||||
new ExoPlayer.Builder(context)
|
new ExoPlayer.Builder(context)
|
||||||
.setMediaSourceFactory(new DefaultMediaSourceFactory(dataSourceFactory))
|
.setMediaSourceFactory(
|
||||||
|
new DefaultMediaSourceFactory(context)
|
||||||
|
.setDataSourceFactory(dataSourceFactory))
|
||||||
.build();
|
.build();
|
||||||
~~~
|
~~~
|
||||||
{: .language-java}
|
{: .language-java}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.checkerframework.checker.nullness.compatqual.NullableType;
|
import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default {@link MediaSource.Factory} implementation.
|
* The default {@link MediaSource.Factory} implementation.
|
||||||
|
|
@ -104,9 +105,9 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
|
|
||||||
private static final String TAG = "DMediaSourceFactory";
|
private static final String TAG = "DMediaSourceFactory";
|
||||||
|
|
||||||
private final DataSource.Factory dataSourceFactory;
|
|
||||||
private final DelegateFactoryLoader delegateFactoryLoader;
|
private final DelegateFactoryLoader delegateFactoryLoader;
|
||||||
|
|
||||||
|
private DataSource.Factory dataSourceFactory;
|
||||||
@Nullable private MediaSource.Factory serverSideAdInsertionMediaSourceFactory;
|
@Nullable private MediaSource.Factory serverSideAdInsertionMediaSourceFactory;
|
||||||
@Nullable private AdsLoader.Provider adsLoaderProvider;
|
@Nullable private AdsLoader.Provider adsLoaderProvider;
|
||||||
@Nullable private AdViewProvider adViewProvider;
|
@Nullable private AdViewProvider adViewProvider;
|
||||||
|
|
@ -130,6 +131,9 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
*
|
*
|
||||||
|
* <p>Note that this constructor is only useful to try and ensure that ExoPlayer's {@link
|
||||||
|
* DefaultExtractorsFactory} can be removed by ProGuard or R8.
|
||||||
|
*
|
||||||
* @param context Any context.
|
* @param context Any context.
|
||||||
* @param extractorsFactory An {@link ExtractorsFactory} used to extract progressive media from
|
* @param extractorsFactory An {@link ExtractorsFactory} used to extract progressive media from
|
||||||
* its container.
|
* its container.
|
||||||
|
|
@ -141,6 +145,9 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
*
|
*
|
||||||
|
* <p>Note that this constructor is only useful to try and ensure that ExoPlayer's {@link
|
||||||
|
* DefaultDataSource.Factory} can be removed by ProGuard or R8.
|
||||||
|
*
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
|
|
@ -151,6 +158,10 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
*
|
*
|
||||||
|
* <p>Note that this constructor is only useful to try and ensure that ExoPlayer's {@link
|
||||||
|
* DefaultDataSource.Factory} and {@link DefaultExtractorsFactory} can be removed by ProGuard or
|
||||||
|
* R8.
|
||||||
|
*
|
||||||
* @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.
|
||||||
* @param extractorsFactory An {@link ExtractorsFactory} used to extract progressive media from
|
* @param extractorsFactory An {@link ExtractorsFactory} used to extract progressive media from
|
||||||
|
|
@ -159,7 +170,8 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
public DefaultMediaSourceFactory(
|
public DefaultMediaSourceFactory(
|
||||||
DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
|
DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
|
||||||
this.dataSourceFactory = dataSourceFactory;
|
this.dataSourceFactory = dataSourceFactory;
|
||||||
delegateFactoryLoader = new DelegateFactoryLoader(dataSourceFactory, extractorsFactory);
|
delegateFactoryLoader = new DelegateFactoryLoader(extractorsFactory);
|
||||||
|
delegateFactoryLoader.setDataSourceFactory(dataSourceFactory);
|
||||||
liveTargetOffsetMs = C.TIME_UNSET;
|
liveTargetOffsetMs = C.TIME_UNSET;
|
||||||
liveMinOffsetMs = C.TIME_UNSET;
|
liveMinOffsetMs = C.TIME_UNSET;
|
||||||
liveMaxOffsetMs = C.TIME_UNSET;
|
liveMaxOffsetMs = C.TIME_UNSET;
|
||||||
|
|
@ -253,6 +265,18 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link DataSource.Factory} used to create {@link DataSource} instances for requesting
|
||||||
|
* media data.
|
||||||
|
*
|
||||||
|
* @param dataSourceFactory The {@link DataSource.Factory}.
|
||||||
|
* @return This factory, for convenience.
|
||||||
|
*/
|
||||||
|
public DefaultMediaSourceFactory setDataSourceFactory(DataSource.Factory dataSourceFactory) {
|
||||||
|
this.dataSourceFactory = dataSourceFactory;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link MediaSource.Factory} used to handle {@link MediaItem} instances containing a
|
* Sets the {@link MediaSource.Factory} used to handle {@link MediaItem} instances containing a
|
||||||
* {@link Uri} identified as resolving to content with server side ad insertion (SSAI).
|
* {@link Uri} identified as resolving to content with server side ad insertion (SSAI).
|
||||||
|
|
@ -484,19 +508,17 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
|
|
||||||
/** Loads media source factories lazily. */
|
/** Loads media source factories lazily. */
|
||||||
private static final class DelegateFactoryLoader {
|
private static final class DelegateFactoryLoader {
|
||||||
private final DataSource.Factory dataSourceFactory;
|
|
||||||
private final ExtractorsFactory extractorsFactory;
|
private final ExtractorsFactory extractorsFactory;
|
||||||
private final Map<Integer, @NullableType Supplier<MediaSource.Factory>>
|
private final Map<Integer, @NullableType Supplier<MediaSource.Factory>>
|
||||||
mediaSourceFactorySuppliers;
|
mediaSourceFactorySuppliers;
|
||||||
private final Set<Integer> supportedTypes;
|
private final Set<Integer> supportedTypes;
|
||||||
private final Map<Integer, MediaSource.Factory> mediaSourceFactories;
|
private final Map<Integer, MediaSource.Factory> mediaSourceFactories;
|
||||||
|
|
||||||
|
private DataSource.@MonotonicNonNull Factory dataSourceFactory;
|
||||||
@Nullable private DrmSessionManagerProvider drmSessionManagerProvider;
|
@Nullable private DrmSessionManagerProvider drmSessionManagerProvider;
|
||||||
@Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
@Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
|
|
||||||
public DelegateFactoryLoader(
|
public DelegateFactoryLoader(ExtractorsFactory extractorsFactory) {
|
||||||
DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory) {
|
|
||||||
this.dataSourceFactory = dataSourceFactory;
|
|
||||||
this.extractorsFactory = extractorsFactory;
|
this.extractorsFactory = extractorsFactory;
|
||||||
mediaSourceFactorySuppliers = new HashMap<>();
|
mediaSourceFactorySuppliers = new HashMap<>();
|
||||||
supportedTypes = new HashSet<>();
|
supportedTypes = new HashSet<>();
|
||||||
|
|
@ -532,6 +554,15 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
return mediaSourceFactory;
|
return mediaSourceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDataSourceFactory(DataSource.Factory dataSourceFactory) {
|
||||||
|
if (dataSourceFactory != this.dataSourceFactory) {
|
||||||
|
this.dataSourceFactory = dataSourceFactory;
|
||||||
|
// TODO(b/233577470): Call MediaSource.Factory.setDataSourceFactory on each value when it
|
||||||
|
// exists on the interface.
|
||||||
|
mediaSourceFactories.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setDrmSessionManagerProvider(
|
public void setDrmSessionManagerProvider(
|
||||||
@Nullable DrmSessionManagerProvider drmSessionManagerProvider) {
|
@Nullable DrmSessionManagerProvider drmSessionManagerProvider) {
|
||||||
this.drmSessionManagerProvider = drmSessionManagerProvider;
|
this.drmSessionManagerProvider = drmSessionManagerProvider;
|
||||||
|
|
@ -570,20 +601,20 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
clazz =
|
clazz =
|
||||||
Class.forName("com.google.android.exoplayer2.source.dash.DashMediaSource$Factory")
|
Class.forName("com.google.android.exoplayer2.source.dash.DashMediaSource$Factory")
|
||||||
.asSubclass(MediaSource.Factory.class);
|
.asSubclass(MediaSource.Factory.class);
|
||||||
mediaSourceFactorySupplier = () -> newInstance(clazz, dataSourceFactory);
|
mediaSourceFactorySupplier = () -> newInstance(clazz, checkNotNull(dataSourceFactory));
|
||||||
break;
|
break;
|
||||||
case C.CONTENT_TYPE_SS:
|
case C.CONTENT_TYPE_SS:
|
||||||
clazz =
|
clazz =
|
||||||
Class.forName(
|
Class.forName(
|
||||||
"com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource$Factory")
|
"com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource$Factory")
|
||||||
.asSubclass(MediaSource.Factory.class);
|
.asSubclass(MediaSource.Factory.class);
|
||||||
mediaSourceFactorySupplier = () -> newInstance(clazz, dataSourceFactory);
|
mediaSourceFactorySupplier = () -> newInstance(clazz, checkNotNull(dataSourceFactory));
|
||||||
break;
|
break;
|
||||||
case C.CONTENT_TYPE_HLS:
|
case C.CONTENT_TYPE_HLS:
|
||||||
clazz =
|
clazz =
|
||||||
Class.forName("com.google.android.exoplayer2.source.hls.HlsMediaSource$Factory")
|
Class.forName("com.google.android.exoplayer2.source.hls.HlsMediaSource$Factory")
|
||||||
.asSubclass(MediaSource.Factory.class);
|
.asSubclass(MediaSource.Factory.class);
|
||||||
mediaSourceFactorySupplier = () -> newInstance(clazz, dataSourceFactory);
|
mediaSourceFactorySupplier = () -> newInstance(clazz, checkNotNull(dataSourceFactory));
|
||||||
break;
|
break;
|
||||||
case C.CONTENT_TYPE_RTSP:
|
case C.CONTENT_TYPE_RTSP:
|
||||||
clazz =
|
clazz =
|
||||||
|
|
@ -593,7 +624,9 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
break;
|
break;
|
||||||
case C.CONTENT_TYPE_OTHER:
|
case C.CONTENT_TYPE_OTHER:
|
||||||
mediaSourceFactorySupplier =
|
mediaSourceFactorySupplier =
|
||||||
() -> new ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory);
|
() ->
|
||||||
|
new ProgressiveMediaSource.Factory(
|
||||||
|
checkNotNull(dataSourceFactory), extractorsFactory);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue