Add ad event listeners in the Looper event of the ad manager callback

#minor-release

PiperOrigin-RevId: 509189206
(cherry picked from commit 51929625cfeff17af413c1a06c87e10e72f218d1)
This commit is contained in:
bachinger 2023-02-13 12:26:04 +00:00 committed by tonihei
parent 3696076f0f
commit f2753e2e27
2 changed files with 15 additions and 27 deletions

View File

@ -103,6 +103,8 @@ This release corresponds to the
* Add a method `focusSkipButton()` to the * Add a method `focusSkipButton()` to the
`ImaServerSideAdInsertionMediaSource.AdsLoader` to programmatically `ImaServerSideAdInsertionMediaSource.AdsLoader` to programmatically
request to focus the skip button. request to focus the skip button.
* Fix a bug which prevented playback from starting for a DAI stream
without any ads.
* Bump IMA SDK version to 3.29.0. * Bump IMA SDK version to 3.29.0.
* Demo app: * Demo app:
* Request notification permission for download notifications at runtime * Request notification permission for download notifications at runtime

View File

@ -554,11 +554,10 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
StreamManagerLoadable streamManagerLoadable = StreamManagerLoadable streamManagerLoadable =
new StreamManagerLoadable( new StreamManagerLoadable(
sdkAdsLoader, sdkAdsLoader,
adsLoader.configuration, /* imaServerSideAdInsertionMediaSource= */ this,
streamRequest, streamRequest,
streamPlayer, streamPlayer,
applicationAdErrorListener, applicationAdErrorListener);
loadVideoTimeoutMs);
loader.startLoading( loader.startLoading(
streamManagerLoadable, streamManagerLoadable,
new StreamManagerLoadableCallback(), new StreamManagerLoadableCallback(),
@ -633,7 +632,6 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
} }
this.streamManager.removeAdEventListener(componentListener); this.streamManager.removeAdEventListener(componentListener);
this.streamManager.destroy(); this.streamManager.destroy();
this.streamManager = null;
} }
this.streamManager = streamManager; this.streamManager = streamManager;
if (streamManager != null) { if (streamManager != null) {
@ -644,6 +642,12 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
if (applicationAdErrorListener != null) { if (applicationAdErrorListener != null) {
streamManager.addAdErrorListener(applicationAdErrorListener); streamManager.addAdErrorListener(applicationAdErrorListener);
} }
AdsRenderingSettings adsRenderingSettings =
ImaSdkFactory.getInstance().createAdsRenderingSettings();
adsRenderingSettings.setLoadVideoTimeout(loadVideoTimeoutMs);
adsRenderingSettings.setFocusSkipButtonWhenAvailable(
adsLoader.configuration.focusSkipButtonWhenAvailable);
streamManager.init(adsRenderingSettings);
} }
} }
@ -952,7 +956,6 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
@Override @Override
public void onLoadCompleted( public void onLoadCompleted(
StreamManagerLoadable loadable, long elapsedRealtimeMs, long loadDurationMs) { StreamManagerLoadable loadable, long elapsedRealtimeMs, long loadDurationMs) {
mainHandler.post(() -> setStreamManager(checkNotNull(loadable.getStreamManager())));
setContentUri(checkNotNull(loadable.getContentUri())); setContentUri(checkNotNull(loadable.getContentUri()));
} }
@ -983,14 +986,12 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
implements Loadable, AdsLoadedListener, AdErrorListener { implements Loadable, AdsLoadedListener, AdErrorListener {
private final com.google.ads.interactivemedia.v3.api.AdsLoader adsLoader; private final com.google.ads.interactivemedia.v3.api.AdsLoader adsLoader;
private final ServerSideAdInsertionConfiguration serverSideAdInsertionConfiguration; private final ImaServerSideAdInsertionMediaSource imaServerSideAdInsertionMediaSource;
private final StreamRequest request; private final StreamRequest request;
private final StreamPlayer streamPlayer; private final StreamPlayer streamPlayer;
@Nullable private final AdErrorListener adErrorListener; @Nullable private final AdErrorListener adErrorListener;
private final int loadVideoTimeoutMs;
private final ConditionVariable conditionVariable; private final ConditionVariable conditionVariable;
@Nullable private volatile StreamManager streamManager;
@Nullable private volatile Uri contentUri; @Nullable private volatile Uri contentUri;
private volatile boolean cancelled; private volatile boolean cancelled;
private volatile boolean error; private volatile boolean error;
@ -1000,17 +1001,15 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
/** Creates an instance. */ /** Creates an instance. */
private StreamManagerLoadable( private StreamManagerLoadable(
com.google.ads.interactivemedia.v3.api.AdsLoader adsLoader, com.google.ads.interactivemedia.v3.api.AdsLoader adsLoader,
ServerSideAdInsertionConfiguration serverSideAdInsertionConfiguration, ImaServerSideAdInsertionMediaSource imaServerSideAdInsertionMediaSource,
StreamRequest request, StreamRequest request,
StreamPlayer streamPlayer, StreamPlayer streamPlayer,
@Nullable AdErrorListener adErrorListener, @Nullable AdErrorListener adErrorListener) {
int loadVideoTimeoutMs) {
this.adsLoader = adsLoader; this.adsLoader = adsLoader;
this.serverSideAdInsertionConfiguration = serverSideAdInsertionConfiguration; this.imaServerSideAdInsertionMediaSource = imaServerSideAdInsertionMediaSource;
this.request = request; this.request = request;
this.streamPlayer = streamPlayer; this.streamPlayer = streamPlayer;
this.adErrorListener = adErrorListener; this.adErrorListener = adErrorListener;
this.loadVideoTimeoutMs = loadVideoTimeoutMs;
conditionVariable = new ConditionVariable(); conditionVariable = new ConditionVariable();
errorCode = -1; errorCode = -1;
} }
@ -1021,12 +1020,6 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
return contentUri; return contentUri;
} }
/** Returns the stream manager or null if not yet loaded. */
@Nullable
public StreamManager getStreamManager() {
return streamManager;
}
// Implement Loadable. // Implement Loadable.
@Override @Override
@ -1080,14 +1073,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
conditionVariable.open(); conditionVariable.open();
return; return;
} }
AdsRenderingSettings adsRenderingSettings = imaServerSideAdInsertionMediaSource.setStreamManager(streamManager);
ImaSdkFactory.getInstance().createAdsRenderingSettings();
adsRenderingSettings.setLoadVideoTimeout(loadVideoTimeoutMs);
adsRenderingSettings.setFocusSkipButtonWhenAvailable(
serverSideAdInsertionConfiguration.focusSkipButtonWhenAvailable);
// After initialization completed the streamUri will be reported to the streamPlayer.
streamManager.init(adsRenderingSettings);
this.streamManager = streamManager;
} }
// AdErrorEvent.AdErrorListener implementation. // AdErrorEvent.AdErrorListener implementation.