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

#minor-release

PiperOrigin-RevId: 509189206
This commit is contained in:
bachinger 2023-02-13 12:26:04 +00:00 committed by christosts
parent cf089b34f0
commit 51929625cf
2 changed files with 15 additions and 27 deletions

View File

@ -115,6 +115,8 @@
* Add a method `focusSkipButton()` to the
`ImaServerSideAdInsertionMediaSource.AdsLoader` to programmatically
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.
* Demo app
* Request notification permission for download notifications at runtime

View File

@ -559,11 +559,10 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
StreamManagerLoadable streamManagerLoadable =
new StreamManagerLoadable(
sdkAdsLoader,
adsLoader.configuration,
/* imaServerSideAdInsertionMediaSource= */ this,
streamRequest,
streamPlayer,
applicationAdErrorListener,
loadVideoTimeoutMs);
applicationAdErrorListener);
loader.startLoading(
streamManagerLoadable,
new StreamManagerLoadableCallback(),
@ -638,7 +637,6 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
}
this.streamManager.removeAdEventListener(componentListener);
this.streamManager.destroy();
this.streamManager = null;
}
this.streamManager = streamManager;
if (streamManager != null) {
@ -649,6 +647,12 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
if (applicationAdErrorListener != null) {
streamManager.addAdErrorListener(applicationAdErrorListener);
}
AdsRenderingSettings adsRenderingSettings =
ImaSdkFactory.getInstance().createAdsRenderingSettings();
adsRenderingSettings.setLoadVideoTimeout(loadVideoTimeoutMs);
adsRenderingSettings.setFocusSkipButtonWhenAvailable(
adsLoader.configuration.focusSkipButtonWhenAvailable);
streamManager.init(adsRenderingSettings);
}
}
@ -915,7 +919,6 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
@Override
public void onLoadCompleted(
StreamManagerLoadable loadable, long elapsedRealtimeMs, long loadDurationMs) {
mainHandler.post(() -> setStreamManager(checkNotNull(loadable.getStreamManager())));
setContentUri(checkNotNull(loadable.getContentUri()));
}
@ -946,14 +949,12 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
implements Loadable, AdsLoadedListener, AdErrorListener {
private final com.google.ads.interactivemedia.v3.api.AdsLoader adsLoader;
private final ServerSideAdInsertionConfiguration serverSideAdInsertionConfiguration;
private final ImaServerSideAdInsertionMediaSource imaServerSideAdInsertionMediaSource;
private final StreamRequest request;
private final StreamPlayer streamPlayer;
@Nullable private final AdErrorListener adErrorListener;
private final int loadVideoTimeoutMs;
private final ConditionVariable conditionVariable;
@Nullable private volatile StreamManager streamManager;
@Nullable private volatile Uri contentUri;
private volatile boolean cancelled;
private volatile boolean error;
@ -963,17 +964,15 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
/** Creates an instance. */
private StreamManagerLoadable(
com.google.ads.interactivemedia.v3.api.AdsLoader adsLoader,
ServerSideAdInsertionConfiguration serverSideAdInsertionConfiguration,
ImaServerSideAdInsertionMediaSource imaServerSideAdInsertionMediaSource,
StreamRequest request,
StreamPlayer streamPlayer,
@Nullable AdErrorListener adErrorListener,
int loadVideoTimeoutMs) {
@Nullable AdErrorListener adErrorListener) {
this.adsLoader = adsLoader;
this.serverSideAdInsertionConfiguration = serverSideAdInsertionConfiguration;
this.imaServerSideAdInsertionMediaSource = imaServerSideAdInsertionMediaSource;
this.request = request;
this.streamPlayer = streamPlayer;
this.adErrorListener = adErrorListener;
this.loadVideoTimeoutMs = loadVideoTimeoutMs;
conditionVariable = new ConditionVariable();
errorCode = -1;
}
@ -984,12 +983,6 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
return contentUri;
}
/** Returns the stream manager or null if not yet loaded. */
@Nullable
public StreamManager getStreamManager() {
return streamManager;
}
// Implement Loadable.
@Override
@ -1043,14 +1036,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
conditionVariable.open();
return;
}
AdsRenderingSettings adsRenderingSettings =
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;
imaServerSideAdInsertionMediaSource.setStreamManager(streamManager);
}
// AdErrorEvent.AdErrorListener implementation.