mirror of
https://github.com/samsonjs/media.git
synced 2026-04-08 11:45:51 +00:00
Add a setter for ad error listeners
This is useful because ImaAdsLoader.getAdsLoader() can now return null (before ads have been requested), and it avoids the app needing to get an AdsManager to attach its listener. PiperOrigin-RevId: 330907051
This commit is contained in:
parent
fdb9bbb619
commit
0266971406
1 changed files with 32 additions and 0 deletions
|
|
@ -124,6 +124,7 @@ public final class ImaAdsLoader
|
|||
private final Context context;
|
||||
|
||||
@Nullable private ImaSdkSettings imaSdkSettings;
|
||||
@Nullable private AdErrorListener adErrorListener;
|
||||
@Nullable private AdEventListener adEventListener;
|
||||
@Nullable private Set<UiElement> adUiElements;
|
||||
@Nullable private Collection<CompanionAdSlot> companionAdSlots;
|
||||
|
|
@ -165,6 +166,19 @@ public final class ImaAdsLoader
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a listener for ad errors that will be passed to {@link
|
||||
* AdsLoader#addAdErrorListener(AdErrorListener)} and {@link
|
||||
* AdsManager#addAdErrorListener(AdErrorListener)}.
|
||||
*
|
||||
* @param adErrorListener The ad error listener.
|
||||
* @return This builder, for convenience.
|
||||
*/
|
||||
public Builder setAdErrorListener(AdErrorListener adErrorListener) {
|
||||
this.adErrorListener = checkNotNull(adErrorListener);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a listener for ad events that will be passed to {@link
|
||||
* AdsManager#addAdEventListener(AdEventListener)}.
|
||||
|
|
@ -316,6 +330,7 @@ public final class ImaAdsLoader
|
|||
playAdBeforeStartPosition,
|
||||
adUiElements,
|
||||
companionAdSlots,
|
||||
adErrorListener,
|
||||
adEventListener,
|
||||
imaFactory);
|
||||
}
|
||||
|
|
@ -341,6 +356,7 @@ public final class ImaAdsLoader
|
|||
playAdBeforeStartPosition,
|
||||
adUiElements,
|
||||
companionAdSlots,
|
||||
adErrorListener,
|
||||
adEventListener,
|
||||
imaFactory);
|
||||
}
|
||||
|
|
@ -408,6 +424,7 @@ public final class ImaAdsLoader
|
|||
private final int mediaBitrate;
|
||||
@Nullable private final Set<UiElement> adUiElements;
|
||||
@Nullable private final Collection<CompanionAdSlot> companionAdSlots;
|
||||
@Nullable private final AdErrorListener adErrorListener;
|
||||
@Nullable private final AdEventListener adEventListener;
|
||||
private final ImaFactory imaFactory;
|
||||
private final ImaSdkSettings imaSdkSettings;
|
||||
|
|
@ -516,6 +533,7 @@ public final class ImaAdsLoader
|
|||
/* playAdBeforeStartPosition= */ true,
|
||||
/* adUiElements= */ null,
|
||||
/* companionAdSlots= */ null,
|
||||
/* adErrorListener= */ null,
|
||||
/* adEventListener= */ null,
|
||||
/* imaFactory= */ new DefaultImaFactory());
|
||||
}
|
||||
|
|
@ -534,6 +552,7 @@ public final class ImaAdsLoader
|
|||
boolean playAdBeforeStartPosition,
|
||||
@Nullable Set<UiElement> adUiElements,
|
||||
@Nullable Collection<CompanionAdSlot> companionAdSlots,
|
||||
@Nullable AdErrorListener adErrorListener,
|
||||
@Nullable AdEventListener adEventListener,
|
||||
ImaFactory imaFactory) {
|
||||
checkArgument(adTagUri != null || adsResponse != null);
|
||||
|
|
@ -548,6 +567,7 @@ public final class ImaAdsLoader
|
|||
this.playAdBeforeStartPosition = playAdBeforeStartPosition;
|
||||
this.adUiElements = adUiElements;
|
||||
this.companionAdSlots = companionAdSlots;
|
||||
this.adErrorListener = adErrorListener;
|
||||
this.adEventListener = adEventListener;
|
||||
this.imaFactory = imaFactory;
|
||||
if (imaSdkSettings == null) {
|
||||
|
|
@ -629,6 +649,9 @@ public final class ImaAdsLoader
|
|||
}
|
||||
adsLoader = imaFactory.createAdsLoader(context, imaSdkSettings, adDisplayContainer);
|
||||
adsLoader.addAdErrorListener(componentListener);
|
||||
if (adErrorListener != null) {
|
||||
adsLoader.addAdErrorListener(adErrorListener);
|
||||
}
|
||||
adsLoader.addAdsLoadedListener(componentListener);
|
||||
AdsRequest request = imaFactory.createAdsRequest();
|
||||
if (adTagUri != null) {
|
||||
|
|
@ -759,6 +782,9 @@ public final class ImaAdsLoader
|
|||
if (adsLoader != null) {
|
||||
adsLoader.removeAdsLoadedListener(componentListener);
|
||||
adsLoader.removeAdErrorListener(componentListener);
|
||||
if (adErrorListener != null) {
|
||||
adsLoader.removeAdErrorListener(adErrorListener);
|
||||
}
|
||||
}
|
||||
imaPausedContent = false;
|
||||
imaAdState = IMA_AD_STATE_NONE;
|
||||
|
|
@ -1582,6 +1608,9 @@ public final class ImaAdsLoader
|
|||
private void destroyAdsManager() {
|
||||
if (adsManager != null) {
|
||||
adsManager.removeAdErrorListener(componentListener);
|
||||
if (adErrorListener != null) {
|
||||
adsManager.removeAdErrorListener(adErrorListener);
|
||||
}
|
||||
adsManager.removeAdEventListener(componentListener);
|
||||
if (adEventListener != null) {
|
||||
adsManager.removeAdEventListener(adEventListener);
|
||||
|
|
@ -1642,6 +1671,9 @@ public final class ImaAdsLoader
|
|||
pendingAdRequestContext = null;
|
||||
ImaAdsLoader.this.adsManager = adsManager;
|
||||
adsManager.addAdErrorListener(this);
|
||||
if (adErrorListener != null) {
|
||||
adsManager.addAdErrorListener(adErrorListener);
|
||||
}
|
||||
adsManager.addAdEventListener(this);
|
||||
if (adEventListener != null) {
|
||||
adsManager.addAdEventListener(adEventListener);
|
||||
|
|
|
|||
Loading…
Reference in a new issue