mirror of
https://github.com/androidx/media.git
synced 2025-05-11 09:39:52 +08:00
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:
parent
3f5304b891
commit
c1f878deb1
@ -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
|
||||
|
@ -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.
|
||||
*
|
||||
* <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";
|
||||
|
||||
@ -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(
|
||||
|
@ -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.
|
||||
*
|
||||
* <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 {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user