Commit 938728ce by ibaker Committed by Ian Baker

Add DefaultMediaSourceFactory.{set,clear}LocalAdInsertionConfig

Deprecate the setAdsLoaderProvider and setAdViewProvider methods these
replace.

PiperOrigin-RevId: 448251423
parent 800e5330
...@@ -311,8 +311,8 @@ public class PlayerActivity extends AppCompatActivity ...@@ -311,8 +311,8 @@ public class PlayerActivity extends AppCompatActivity
serverSideAdsLoader, new DefaultMediaSourceFactory(dataSourceFactory)); serverSideAdsLoader, new DefaultMediaSourceFactory(dataSourceFactory));
return new DefaultMediaSourceFactory(dataSourceFactory) return new DefaultMediaSourceFactory(dataSourceFactory)
.setDrmSessionManagerProvider(drmSessionManagerProvider) .setDrmSessionManagerProvider(drmSessionManagerProvider)
.setAdsLoaderProvider(this::getClientSideAdsLoader) .setLocalAdInsertionComponents(
.setAdViewProvider(playerView) this::getClientSideAdsLoader, /* adViewProvider= */ playerView)
.setServerSideAdInsertionMediaSourceFactory(imaServerSideAdInsertionMediaSourceFactory); .setServerSideAdInsertionMediaSourceFactory(imaServerSideAdInsertionMediaSourceFactory);
} }
......
...@@ -51,8 +51,8 @@ build and inject a `DefaultMediaSourceFactory` configured with an ...@@ -51,8 +51,8 @@ build and inject a `DefaultMediaSourceFactory` configured with an
~~~ ~~~
MediaSource.Factory mediaSourceFactory = MediaSource.Factory mediaSourceFactory =
new DefaultMediaSourceFactory(context) new DefaultMediaSourceFactory(context)
.setAdsLoaderProvider(adsLoaderProvider) .setLocalAdInsertionComponents(
.setAdViewProvider(playerView); adsLoaderProvider, /* adViewProvider= */ playerView);
ExoPlayer player = new ExoPlayer.Builder(context) ExoPlayer player = new ExoPlayer.Builder(context)
.setMediaSourceFactory(mediaSourceFactory) .setMediaSourceFactory(mediaSourceFactory)
.build(); .build();
......
...@@ -35,8 +35,8 @@ these requirements and injected during player construction: ...@@ -35,8 +35,8 @@ these requirements and injected during player construction:
~~~ ~~~
MediaSource.Factory mediaSourceFactory = MediaSource.Factory mediaSourceFactory =
new DefaultMediaSourceFactory(cacheDataSourceFactory) new DefaultMediaSourceFactory(cacheDataSourceFactory)
.setAdsLoaderProvider(adsLoaderProvider) .setLocalAdInsertionComponents(
.setAdViewProvider(playerView); adsLoaderProvider, /* adViewProvider= */ playerView);
ExoPlayer player = new ExoPlayer.Builder(context) ExoPlayer player = new ExoPlayer.Builder(context)
.setMediaSourceFactory(mediaSourceFactory) .setMediaSourceFactory(mediaSourceFactory)
.build(); .build();
......
...@@ -188,9 +188,15 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { ...@@ -188,9 +188,15 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
* Sets the {@link AdsLoader.Provider} that provides {@link AdsLoader} instances for media items * Sets the {@link AdsLoader.Provider} that provides {@link AdsLoader} instances for media items
* that have {@link MediaItem.LocalConfiguration#adsConfiguration ads configurations}. * that have {@link MediaItem.LocalConfiguration#adsConfiguration ads configurations}.
* *
* <p>This will override or clear the {@link AdsLoader.Provider} set by {@link
* #setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)}.
*
* @param adsLoaderProvider A provider for {@link AdsLoader} instances. * @param adsLoaderProvider A provider for {@link AdsLoader} instances.
* @return This factory, for convenience. * @return This factory, for convenience.
* @deprecated Use {@link #setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)}
* instead.
*/ */
@Deprecated
public DefaultMediaSourceFactory setAdsLoaderProvider( public DefaultMediaSourceFactory setAdsLoaderProvider(
@Nullable AdsLoader.Provider adsLoaderProvider) { @Nullable AdsLoader.Provider adsLoaderProvider) {
this.adsLoaderProvider = adsLoaderProvider; this.adsLoaderProvider = adsLoaderProvider;
...@@ -200,15 +206,54 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { ...@@ -200,15 +206,54 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
/** /**
* Sets the {@link AdViewProvider} that provides information about views for the ad playback UI. * Sets the {@link AdViewProvider} that provides information about views for the ad playback UI.
* *
* @param adViewProvider A provider for {@link AdsLoader} instances. * <p>This will override or clear the {@link AdViewProvider} set by {@link
* #setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)}.
*
* @param adViewProvider A provider for information about views for the ad playback UI.
* @return This factory, for convenience. * @return This factory, for convenience.
* @deprecated Use {@link #setLocalAdInsertionComponents(AdsLoader.Provider, AdViewProvider)}
* instead.
*/ */
@Deprecated
public DefaultMediaSourceFactory setAdViewProvider(@Nullable AdViewProvider adViewProvider) { public DefaultMediaSourceFactory setAdViewProvider(@Nullable AdViewProvider adViewProvider) {
this.adViewProvider = adViewProvider; this.adViewProvider = adViewProvider;
return this; return this;
} }
/** /**
* Sets the components required for local ad insertion for media items that have {@link
* MediaItem.LocalConfiguration#adsConfiguration ads configurations}
*
* <p>This will override the values set by {@link #setAdsLoaderProvider(AdsLoader.Provider)} and
* {@link #setAdViewProvider(AdViewProvider)}.
*
* @param adsLoaderProvider A provider for {@link AdsLoader} instances.
* @param adViewProvider A provider for information about views for the ad playback UI.
* @return This factory, for convenience.
*/
public DefaultMediaSourceFactory setLocalAdInsertionComponents(
AdsLoader.Provider adsLoaderProvider, AdViewProvider adViewProvider) {
this.adsLoaderProvider = checkNotNull(adsLoaderProvider);
this.adViewProvider = checkNotNull(adViewProvider);
return this;
}
/**
* Clear any values set via {@link #setLocalAdInsertionComponents(AdsLoader.Provider,
* AdViewProvider)}.
*
* <p>This will also clear any values set by {@link #setAdsLoaderProvider(AdsLoader.Provider)} and
* {@link #setAdViewProvider(AdViewProvider)}.
*
* @return This factory, for convenience.
*/
public DefaultMediaSourceFactory clearLocalAdInsertionComponents() {
this.adsLoaderProvider = null;
this.adViewProvider = null;
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).
* *
......
...@@ -191,8 +191,9 @@ public final class DefaultMediaSourceFactoryTest { ...@@ -191,8 +191,9 @@ public final class DefaultMediaSourceFactoryTest {
assertThat(supportedTypes).asList().containsExactly(C.CONTENT_TYPE_OTHER); assertThat(supportedTypes).asList().containsExactly(C.CONTENT_TYPE_OTHER);
} }
@SuppressWarnings("deprecation") // Testing deprecated setters.
@Test @Test
public void createMediaSource_withAdsConfiguration_callsAdsLoader() { public void createMediaSource_withDeprecatedAdsConfiguration_callsAdsLoader() {
Uri adTagUri = Uri.parse(URI_MEDIA); Uri adTagUri = Uri.parse(URI_MEDIA);
MediaItem mediaItem = MediaItem mediaItem =
new MediaItem.Builder() new MediaItem.Builder()
...@@ -210,6 +211,24 @@ public final class DefaultMediaSourceFactoryTest { ...@@ -210,6 +211,24 @@ public final class DefaultMediaSourceFactoryTest {
} }
@Test @Test
public void createMediaSource_withAdsConfiguration_callsAdsLoader() {
Uri adTagUri = Uri.parse(URI_MEDIA);
MediaItem mediaItem =
new MediaItem.Builder()
.setUri(URI_MEDIA)
.setAdsConfiguration(new MediaItem.AdsConfiguration.Builder(adTagUri).build())
.build();
DefaultMediaSourceFactory defaultMediaSourceFactory =
new DefaultMediaSourceFactory((Context) ApplicationProvider.getApplicationContext())
.setLocalAdInsertionComponents(
ignoredAdsConfiguration -> mock(AdsLoader.class), mock(AdViewProvider.class));
MediaSource mediaSource = defaultMediaSourceFactory.createMediaSource(mediaItem);
assertThat(mediaSource).isInstanceOf(AdsMediaSource.class);
}
@Test
public void createMediaSource_withAdsConfiguration_adProvidersNotSet_playsWithoutAdNoException() { public void createMediaSource_withAdsConfiguration_adProvidersNotSet_playsWithoutAdNoException() {
MediaItem mediaItem = MediaItem mediaItem =
new MediaItem.Builder() new MediaItem.Builder()
......
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