mirror of
https://github.com/androidx/media.git
synced 2025-05-12 01:59:50 +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
|
To enable player support for media items that specify ad tags, it's necessary to
|
||||||
build and inject a `DefaultMediaSourceFactory` configured with an
|
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 =
|
MediaSourceFactory mediaSourceFactory =
|
||||||
@ -61,7 +61,7 @@ ExoPlayer player = new ExoPlayer.Builder(context)
|
|||||||
|
|
||||||
Internally, `DefaultMediaSourceFactory` will wrap the content media source in an
|
Internally, `DefaultMediaSourceFactory` will wrap the content media source in an
|
||||||
`AdsMediaSource`. The `AdsMediaSource` will obtain an `AdsLoader` from the
|
`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.
|
tag.
|
||||||
|
|
||||||
ExoPlayer's `StyledPlayerView` and `PlayerView` UI components both implement
|
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 {
|
public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||||
|
|
||||||
/**
|
/** @deprecated Use {@link AdsLoader.Provider} instead. */
|
||||||
* Provides {@link AdsLoader} instances for media items that have {@link
|
@Deprecated
|
||||||
* MediaItem.LocalConfiguration#adsConfiguration ad tag URIs}.
|
public interface AdsLoaderProvider extends AdsLoader.Provider {}
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String TAG = "DMediaSourceFactory";
|
private static final String TAG = "DMediaSourceFactory";
|
||||||
|
|
||||||
@ -121,7 +107,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
|||||||
private final DelegateFactoryLoader delegateFactoryLoader;
|
private final DelegateFactoryLoader delegateFactoryLoader;
|
||||||
|
|
||||||
@Nullable private final MediaSourceFactory serverSideDaiMediaSourceFactory;
|
@Nullable private final MediaSourceFactory serverSideDaiMediaSourceFactory;
|
||||||
@Nullable private AdsLoaderProvider adsLoaderProvider;
|
@Nullable private AdsLoader.Provider adsLoaderProvider;
|
||||||
@Nullable private AdViewProvider adViewProvider;
|
@Nullable private AdViewProvider adViewProvider;
|
||||||
@Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
@Nullable private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
private long liveTargetOffsetMs;
|
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}.
|
* that have {@link MediaItem.LocalConfiguration#adsConfiguration ads configurations}.
|
||||||
*
|
*
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
public DefaultMediaSourceFactory setAdsLoaderProvider(
|
public DefaultMediaSourceFactory setAdsLoaderProvider(
|
||||||
@Nullable AdsLoaderProvider adsLoaderProvider) {
|
@Nullable AdsLoader.Provider adsLoaderProvider) {
|
||||||
this.adsLoaderProvider = adsLoaderProvider;
|
this.adsLoaderProvider = adsLoaderProvider;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -457,7 +443,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
|||||||
if (adsConfiguration == null) {
|
if (adsConfiguration == null) {
|
||||||
return mediaSource;
|
return mediaSource;
|
||||||
}
|
}
|
||||||
@Nullable AdsLoaderProvider adsLoaderProvider = this.adsLoaderProvider;
|
@Nullable AdsLoader.Provider adsLoaderProvider = this.adsLoaderProvider;
|
||||||
@Nullable AdViewProvider adViewProvider = this.adViewProvider;
|
@Nullable AdViewProvider adViewProvider = this.adViewProvider;
|
||||||
if (adsLoaderProvider == null || adViewProvider == null) {
|
if (adsLoaderProvider == null || adViewProvider == null) {
|
||||||
Log.w(
|
Log.w(
|
||||||
|
@ -17,7 +17,9 @@ package com.google.android.exoplayer2.source.ads;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.MediaItem;
|
||||||
import com.google.android.exoplayer2.Player;
|
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.source.ads.AdsMediaSource.AdLoadException;
|
||||||
import com.google.android.exoplayer2.ui.AdViewProvider;
|
import com.google.android.exoplayer2.ui.AdViewProvider;
|
||||||
import com.google.android.exoplayer2.upstream.DataSpec;
|
import com.google.android.exoplayer2.upstream.DataSpec;
|
||||||
@ -45,6 +47,24 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public interface AdsLoader {
|
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. */
|
/** Listener for ads loader events. All methods are called on the main thread. */
|
||||||
interface EventListener {
|
interface EventListener {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user