mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add DefaultMediaSourceFactory.{set,clear}LocalAdInsertionConfig
Deprecate the setAdsLoaderProvider and setAdViewProvider methods these replace. PiperOrigin-RevId: 448251423
This commit is contained in:
parent
800e533014
commit
938728ce00
5 changed files with 72 additions and 8 deletions
|
|
@ -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
|
||||||
~~~
|
~~~
|
||||||
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:
|
||||||
~~~
|
~~~
|
||||||
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 {
|
||||||
* 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,14 +206,53 @@ 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 {
|
||||||
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()
|
||||||
|
|
@ -209,6 +210,24 @@ public final class DefaultMediaSourceFactoryTest {
|
||||||
assertThat(mediaSource).isInstanceOf(AdsMediaSource.class);
|
assertThat(mediaSource).isInstanceOf(AdsMediaSource.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void createMediaSource_withAdsConfiguration_adProvidersNotSet_playsWithoutAdNoException() {
|
public void createMediaSource_withAdsConfiguration_adProvidersNotSet_playsWithoutAdNoException() {
|
||||||
MediaItem mediaItem =
|
MediaItem mediaItem =
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue