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
This commit is contained in:
ibaker 2021-12-16 16:24:32 +00:00 committed by tonihei
parent a24ffbd21b
commit 2fad15a815
2 changed files with 27 additions and 21 deletions

View File

@ -99,23 +99,9 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
@UnstableApi
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.
*
* <p>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";
@ -123,7 +109,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;
@ -213,14 +199,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;
}
@ -459,7 +445,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(

View File

@ -19,9 +19,11 @@ import androidx.annotation.Nullable;
import androidx.media3.common.AdPlaybackState;
import androidx.media3.common.AdViewProvider;
import androidx.media3.common.C;
import androidx.media3.common.MediaItem;
import androidx.media3.common.Player;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSpec;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.source.ads.AdsMediaSource.AdLoadException;
import java.io.IOException;
@ -48,6 +50,24 @@ import java.io.IOException;
@UnstableApi
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.
*
* <p>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 {