mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Add StreamEventListener for IMA SSAI source
Issue: androidx/media#555 PiperOrigin-RevId: 561711428
This commit is contained in:
parent
219b253731
commit
3911c9d0c7
2 changed files with 49 additions and 8 deletions
|
|
@ -115,6 +115,21 @@ import java.util.Objects;
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSource<Void> {
|
public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSource<Void> {
|
||||||
|
|
||||||
|
/** A listener to be notified of stream events. */
|
||||||
|
public interface StreamEventListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the {@linkplain StreamManager#getStreamId() stream ID} provided by the IMA SDK
|
||||||
|
* changed.
|
||||||
|
*
|
||||||
|
* <p>This method is called on the main thread.
|
||||||
|
*
|
||||||
|
* @param mediaItem The media item that the source resolved to the given stream ID.
|
||||||
|
* @param streamId The stream ID.
|
||||||
|
*/
|
||||||
|
void onStreamIdChanged(MediaItem mediaItem, String streamId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory for creating {@link ImaServerSideAdInsertionMediaSource
|
* Factory for creating {@link ImaServerSideAdInsertionMediaSource
|
||||||
* ImaServerSideAdInsertionMediaSources}.
|
* ImaServerSideAdInsertionMediaSources}.
|
||||||
|
|
@ -182,9 +197,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
adsLoader,
|
adsLoader,
|
||||||
imaAdsLoader,
|
imaAdsLoader,
|
||||||
streamPlayer,
|
streamPlayer,
|
||||||
contentMediaSourceFactory,
|
contentMediaSourceFactory);
|
||||||
adsLoader.configuration.applicationAdEventListener,
|
|
||||||
adsLoader.configuration.applicationAdErrorListener);
|
|
||||||
adsLoader.addMediaSourceResources(mediaSource, streamPlayer, imaAdsLoader);
|
adsLoader.addMediaSourceResources(mediaSource, streamPlayer, imaAdsLoader);
|
||||||
return mediaSource;
|
return mediaSource;
|
||||||
}
|
}
|
||||||
|
|
@ -200,6 +213,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
private final AdViewProvider adViewProvider;
|
private final AdViewProvider adViewProvider;
|
||||||
|
|
||||||
@Nullable private ImaSdkSettings imaSdkSettings;
|
@Nullable private ImaSdkSettings imaSdkSettings;
|
||||||
|
private StreamEventListener streamEventListener;
|
||||||
@Nullable private AdEventListener adEventListener;
|
@Nullable private AdEventListener adEventListener;
|
||||||
@Nullable private AdErrorEvent.AdErrorListener adErrorListener;
|
@Nullable private AdErrorEvent.AdErrorListener adErrorListener;
|
||||||
private State state;
|
private State state;
|
||||||
|
|
@ -218,6 +232,10 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
companionAdSlots = ImmutableList.of();
|
companionAdSlots = ImmutableList.of();
|
||||||
state = new State(ImmutableMap.of());
|
state = new State(ImmutableMap.of());
|
||||||
focusSkipButtonWhenAvailable = true;
|
focusSkipButtonWhenAvailable = true;
|
||||||
|
streamEventListener =
|
||||||
|
(mediaItem, streamId) -> {
|
||||||
|
// Do nothing.
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -236,6 +254,18 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the optional {@link StreamEventListener} that will be called for stream events.
|
||||||
|
*
|
||||||
|
* @param streamEventListener The stream event listener.
|
||||||
|
* @return This builder, for convenience.
|
||||||
|
*/
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public AdsLoader.Builder setStreamEventListener(StreamEventListener streamEventListener) {
|
||||||
|
this.streamEventListener = streamEventListener;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the optional {@link AdEventListener} that will be passed to {@link
|
* Sets the optional {@link AdEventListener} that will be passed to {@link
|
||||||
* StreamManager#addAdEventListener(AdEventListener)} when the stream manager becomes
|
* StreamManager#addAdEventListener(AdEventListener)} when the stream manager becomes
|
||||||
|
|
@ -318,6 +348,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
new ServerSideAdInsertionConfiguration(
|
new ServerSideAdInsertionConfiguration(
|
||||||
adViewProvider,
|
adViewProvider,
|
||||||
imaSdkSettings,
|
imaSdkSettings,
|
||||||
|
streamEventListener,
|
||||||
adEventListener,
|
adEventListener,
|
||||||
adErrorListener,
|
adErrorListener,
|
||||||
companionAdSlots,
|
companionAdSlots,
|
||||||
|
|
@ -505,6 +536,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
private final MediaSource.Factory contentMediaSourceFactory;
|
private final MediaSource.Factory contentMediaSourceFactory;
|
||||||
private final AdsLoader adsLoader;
|
private final AdsLoader adsLoader;
|
||||||
private final com.google.ads.interactivemedia.v3.api.AdsLoader sdkAdsLoader;
|
private final com.google.ads.interactivemedia.v3.api.AdsLoader sdkAdsLoader;
|
||||||
|
private final StreamEventListener streamEventListener;
|
||||||
@Nullable private final AdEventListener applicationAdEventListener;
|
@Nullable private final AdEventListener applicationAdEventListener;
|
||||||
@Nullable private final AdErrorListener applicationAdErrorListener;
|
@Nullable private final AdErrorListener applicationAdErrorListener;
|
||||||
private final boolean isLiveStream;
|
private final boolean isLiveStream;
|
||||||
|
|
@ -517,6 +549,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
|
|
||||||
@Nullable private Loader loader;
|
@Nullable private Loader loader;
|
||||||
@Nullable private StreamManager streamManager;
|
@Nullable private StreamManager streamManager;
|
||||||
|
@Nullable private String streamId;
|
||||||
@Nullable private ServerSideAdInsertionMediaSource serverSideAdInsertionMediaSource;
|
@Nullable private ServerSideAdInsertionMediaSource serverSideAdInsertionMediaSource;
|
||||||
@Nullable private IOException loadError;
|
@Nullable private IOException loadError;
|
||||||
@Nullable private Timeline contentTimeline;
|
@Nullable private Timeline contentTimeline;
|
||||||
|
|
@ -532,9 +565,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
AdsLoader adsLoader,
|
AdsLoader adsLoader,
|
||||||
com.google.ads.interactivemedia.v3.api.AdsLoader sdkAdsLoader,
|
com.google.ads.interactivemedia.v3.api.AdsLoader sdkAdsLoader,
|
||||||
StreamPlayer streamPlayer,
|
StreamPlayer streamPlayer,
|
||||||
MediaSource.Factory contentMediaSourceFactory,
|
MediaSource.Factory contentMediaSourceFactory) {
|
||||||
@Nullable AdEventListener applicationAdEventListener,
|
|
||||||
@Nullable AdErrorListener applicationAdErrorListener) {
|
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.mediaItem = mediaItem;
|
this.mediaItem = mediaItem;
|
||||||
this.streamRequest = streamRequest;
|
this.streamRequest = streamRequest;
|
||||||
|
|
@ -542,8 +573,9 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
this.sdkAdsLoader = sdkAdsLoader;
|
this.sdkAdsLoader = sdkAdsLoader;
|
||||||
this.streamPlayer = streamPlayer;
|
this.streamPlayer = streamPlayer;
|
||||||
this.contentMediaSourceFactory = contentMediaSourceFactory;
|
this.contentMediaSourceFactory = contentMediaSourceFactory;
|
||||||
this.applicationAdEventListener = applicationAdEventListener;
|
this.streamEventListener = adsLoader.configuration.streamEventListener;
|
||||||
this.applicationAdErrorListener = applicationAdErrorListener;
|
this.applicationAdEventListener = adsLoader.configuration.applicationAdEventListener;
|
||||||
|
this.applicationAdErrorListener = adsLoader.configuration.applicationAdErrorListener;
|
||||||
Assertions.checkArgument(player.getApplicationLooper() == Looper.getMainLooper());
|
Assertions.checkArgument(player.getApplicationLooper() == Looper.getMainLooper());
|
||||||
mainHandler = new Handler(Looper.getMainLooper());
|
mainHandler = new Handler(Looper.getMainLooper());
|
||||||
Uri streamRequestUri = checkNotNull(mediaItem.localConfiguration).uri;
|
Uri streamRequestUri = checkNotNull(mediaItem.localConfiguration).uri;
|
||||||
|
|
@ -677,9 +709,15 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
|
||||||
}
|
}
|
||||||
this.streamManager.removeAdEventListener(componentListener);
|
this.streamManager.removeAdEventListener(componentListener);
|
||||||
this.streamManager.destroy();
|
this.streamManager.destroy();
|
||||||
|
streamId = null;
|
||||||
}
|
}
|
||||||
this.streamManager = streamManager;
|
this.streamManager = streamManager;
|
||||||
if (streamManager != null) {
|
if (streamManager != null) {
|
||||||
|
String newStreamId = streamManager.getStreamId();
|
||||||
|
if (!Objects.equals(streamId, newStreamId)) {
|
||||||
|
streamId = newStreamId;
|
||||||
|
streamEventListener.onStreamIdChanged(getMediaItem(), newStreamId);
|
||||||
|
}
|
||||||
streamManager.addAdEventListener(componentListener);
|
streamManager.addAdEventListener(componentListener);
|
||||||
if (applicationAdEventListener != null) {
|
if (applicationAdEventListener != null) {
|
||||||
streamManager.addAdEventListener(applicationAdEventListener);
|
streamManager.addAdEventListener(applicationAdEventListener);
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,7 @@ import java.util.Set;
|
||||||
|
|
||||||
public final AdViewProvider adViewProvider;
|
public final AdViewProvider adViewProvider;
|
||||||
public final ImaSdkSettings imaSdkSettings;
|
public final ImaSdkSettings imaSdkSettings;
|
||||||
|
public final ImaServerSideAdInsertionMediaSource.StreamEventListener streamEventListener;
|
||||||
@Nullable public final AdEvent.AdEventListener applicationAdEventListener;
|
@Nullable public final AdEvent.AdEventListener applicationAdEventListener;
|
||||||
@Nullable public final AdErrorEvent.AdErrorListener applicationAdErrorListener;
|
@Nullable public final AdErrorEvent.AdErrorListener applicationAdErrorListener;
|
||||||
public final ImmutableList<CompanionAdSlot> companionAdSlots;
|
public final ImmutableList<CompanionAdSlot> companionAdSlots;
|
||||||
|
|
@ -183,6 +184,7 @@ import java.util.Set;
|
||||||
public ServerSideAdInsertionConfiguration(
|
public ServerSideAdInsertionConfiguration(
|
||||||
AdViewProvider adViewProvider,
|
AdViewProvider adViewProvider,
|
||||||
ImaSdkSettings imaSdkSettings,
|
ImaSdkSettings imaSdkSettings,
|
||||||
|
ImaServerSideAdInsertionMediaSource.StreamEventListener streamEventListener,
|
||||||
@Nullable AdEvent.AdEventListener applicationAdEventListener,
|
@Nullable AdEvent.AdEventListener applicationAdEventListener,
|
||||||
@Nullable AdErrorEvent.AdErrorListener applicationAdErrorListener,
|
@Nullable AdErrorEvent.AdErrorListener applicationAdErrorListener,
|
||||||
List<CompanionAdSlot> companionAdSlots,
|
List<CompanionAdSlot> companionAdSlots,
|
||||||
|
|
@ -190,6 +192,7 @@ import java.util.Set;
|
||||||
boolean debugModeEnabled) {
|
boolean debugModeEnabled) {
|
||||||
this.imaSdkSettings = imaSdkSettings;
|
this.imaSdkSettings = imaSdkSettings;
|
||||||
this.adViewProvider = adViewProvider;
|
this.adViewProvider = adViewProvider;
|
||||||
|
this.streamEventListener = streamEventListener;
|
||||||
this.applicationAdEventListener = applicationAdEventListener;
|
this.applicationAdEventListener = applicationAdEventListener;
|
||||||
this.applicationAdErrorListener = applicationAdErrorListener;
|
this.applicationAdErrorListener = applicationAdErrorListener;
|
||||||
this.companionAdSlots = ImmutableList.copyOf(companionAdSlots);
|
this.companionAdSlots = ImmutableList.copyOf(companionAdSlots);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue