From c1f878deb1ffda388046636c4839852610c3e186 Mon Sep 17 00:00:00 2001 From: ibaker Date: Thu, 16 Dec 2021 16:24:32 +0000 Subject: [PATCH] Move DefaultMediaSourceFactory.AdsLoaderProvider to AdsLoader.Provider Keep the old interface deprecated so any app code implementing it by name (rather than with a lambda) will continue to work. PiperOrigin-RevId: 416816566 --- docs/ad-insertion.md | 4 +-- .../source/DefaultMediaSourceFactory.java | 28 +++++-------------- .../exoplayer2/source/ads/AdsLoader.java | 20 +++++++++++++ 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/docs/ad-insertion.md b/docs/ad-insertion.md index 4e42430f5b..090d0e49d9 100644 --- a/docs/ad-insertion.md +++ b/docs/ad-insertion.md @@ -46,7 +46,7 @@ MediaItem mediaItem = To enable player support for media items that specify ad tags, it's necessary to build and inject a `DefaultMediaSourceFactory` configured with an -`AdsLoaderProvider` and an `AdViewProvider` when creating the player: +`AdsLoader.Provider` and an `AdViewProvider` when creating the player: ~~~ MediaSourceFactory mediaSourceFactory = @@ -61,7 +61,7 @@ ExoPlayer player = new ExoPlayer.Builder(context) Internally, `DefaultMediaSourceFactory` will wrap the content media source in an `AdsMediaSource`. The `AdsMediaSource` will obtain an `AdsLoader` from the -`AdsLoaderProvider` and use it to insert ads as defined by the media item's ad +`AdsLoader.Provider` and use it to insert ads as defined by the media item's ad tag. ExoPlayer's `StyledPlayerView` and `PlayerView` UI components both implement diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java b/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java index a34f1023a0..38bcb12391 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java @@ -97,23 +97,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; */ public final class DefaultMediaSourceFactory implements MediaSourceFactory { - /** - * Provides {@link AdsLoader} instances for media items that have {@link - * MediaItem.LocalConfiguration#adsConfiguration ad tag URIs}. - */ - public interface AdsLoaderProvider { - - /** - * Returns an {@link AdsLoader} for the given {@link - * MediaItem.LocalConfiguration#adsConfiguration ads configuration}, or {@code null} if no ads - * loader is available for the given ads configuration. - * - *

This method is called each time a {@link MediaSource} is created from a {@link MediaItem} - * that defines an {@link MediaItem.LocalConfiguration#adsConfiguration ads configuration}. - */ - @Nullable - AdsLoader getAdsLoader(MediaItem.AdsConfiguration adsConfiguration); - } + /** @deprecated Use {@link AdsLoader.Provider} instead. */ + @Deprecated + public interface AdsLoaderProvider extends AdsLoader.Provider {} private static final String TAG = "DMediaSourceFactory"; @@ -121,7 +107,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { private final DelegateFactoryLoader delegateFactoryLoader; @Nullable private final MediaSourceFactory serverSideDaiMediaSourceFactory; - @Nullable private AdsLoaderProvider adsLoaderProvider; + @Nullable private AdsLoader.Provider adsLoaderProvider; @Nullable private AdViewProvider adViewProvider; @Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy; private long liveTargetOffsetMs; @@ -211,14 +197,14 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { } /** - * Sets the {@link AdsLoaderProvider} 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}. * * @param adsLoaderProvider A provider for {@link AdsLoader} instances. * @return This factory, for convenience. */ public DefaultMediaSourceFactory setAdsLoaderProvider( - @Nullable AdsLoaderProvider adsLoaderProvider) { + @Nullable AdsLoader.Provider adsLoaderProvider) { this.adsLoaderProvider = adsLoaderProvider; return this; } @@ -457,7 +443,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory { if (adsConfiguration == null) { return mediaSource; } - @Nullable AdsLoaderProvider adsLoaderProvider = this.adsLoaderProvider; + @Nullable AdsLoader.Provider adsLoaderProvider = this.adsLoaderProvider; @Nullable AdViewProvider adViewProvider = this.adViewProvider; if (adsLoaderProvider == null || adViewProvider == null) { Log.w( diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/ads/AdsLoader.java b/library/core/src/main/java/com/google/android/exoplayer2/source/ads/AdsLoader.java index f937b0a07b..c28131aacf 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/ads/AdsLoader.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/ads/AdsLoader.java @@ -17,7 +17,9 @@ package com.google.android.exoplayer2.source.ads; import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; +import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.ads.AdsMediaSource.AdLoadException; import com.google.android.exoplayer2.ui.AdViewProvider; import com.google.android.exoplayer2.upstream.DataSpec; @@ -45,6 +47,24 @@ import java.io.IOException; */ public interface AdsLoader { + /** + * Provides {@link AdsLoader} instances for media items that have {@link + * MediaItem.LocalConfiguration#adsConfiguration ad tag URIs}. + */ + interface Provider { + + /** + * Returns an {@link AdsLoader} for the given {@link + * MediaItem.LocalConfiguration#adsConfiguration ads configuration}, or {@code null} if no ads + * loader is available for the given ads configuration. + * + *

This method is called each time a {@link MediaSource} is created from a {@link MediaItem} + * that defines an {@link MediaItem.LocalConfiguration#adsConfiguration ads configuration}. + */ + @Nullable + AdsLoader getAdsLoader(MediaItem.AdsConfiguration adsConfiguration); + } + /** Listener for ads loader events. All methods are called on the main thread. */ interface EventListener {