Skip to content

Commit

Permalink
Add ad event listeners in the Looper event of the ad manager callback
Browse files Browse the repository at this point in the history
#minor-release

PiperOrigin-RevId: 509189206
(cherry picked from commit 5192962)
  • Loading branch information
marcbaechinger authored and tonihei committed Feb 28, 2023
1 parent 3696076 commit f2753e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ This release corresponds to the
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,10 @@ public void prepareSourceInternal(@Nullable TransferListener mediaTransferListen
StreamManagerLoadable streamManagerLoadable =
new StreamManagerLoadable(
sdkAdsLoader,
adsLoader.configuration,
/* imaServerSideAdInsertionMediaSource= */ this,
streamRequest,
streamPlayer,
applicationAdErrorListener,
loadVideoTimeoutMs);
applicationAdErrorListener);
loader.startLoading(
streamManagerLoadable,
new StreamManagerLoadableCallback(),
Expand Down Expand Up @@ -633,7 +632,6 @@ private void setStreamManager(@Nullable StreamManager streamManager) {
}
this.streamManager.removeAdEventListener(componentListener);
this.streamManager.destroy();
this.streamManager = null;
}
this.streamManager = streamManager;
if (streamManager != null) {
Expand All @@ -644,6 +642,12 @@ private void setStreamManager(@Nullable StreamManager streamManager) {
if (applicationAdErrorListener != null) {
streamManager.addAdErrorListener(applicationAdErrorListener);
}
AdsRenderingSettings adsRenderingSettings =
ImaSdkFactory.getInstance().createAdsRenderingSettings();
adsRenderingSettings.setLoadVideoTimeout(loadVideoTimeoutMs);
adsRenderingSettings.setFocusSkipButtonWhenAvailable(
adsLoader.configuration.focusSkipButtonWhenAvailable);
streamManager.init(adsRenderingSettings);
}
}

Expand Down Expand Up @@ -952,7 +956,6 @@ private final class StreamManagerLoadableCallback
@Override
public void onLoadCompleted(
StreamManagerLoadable loadable, long elapsedRealtimeMs, long loadDurationMs) {
mainHandler.post(() -> setStreamManager(checkNotNull(loadable.getStreamManager())));
setContentUri(checkNotNull(loadable.getContentUri()));
}

Expand Down Expand Up @@ -983,14 +986,12 @@ private static class StreamManagerLoadable
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;
Expand All @@ -1000,17 +1001,15 @@ private static class StreamManagerLoadable
/** 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;
}
Expand All @@ -1021,12 +1020,6 @@ public Uri getContentUri() {
return contentUri;
}

/** Returns the stream manager or null if not yet loaded. */
@Nullable
public StreamManager getStreamManager() {
return streamManager;
}

// Implement Loadable.

@Override
Expand Down Expand Up @@ -1080,14 +1073,7 @@ public void onAdsManagerLoaded(AdsManagerLoadedEvent event) {
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.
Expand Down

0 comments on commit f2753e2

Please sign in to comment.