mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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;
|
private final Context context;
|
||||||
|
|
||||||
@Nullable private ImaSdkSettings imaSdkSettings;
|
@Nullable private ImaSdkSettings imaSdkSettings;
|
||||||
|
@Nullable private AdErrorListener adErrorListener;
|
||||||
@Nullable private AdEventListener adEventListener;
|
@Nullable private AdEventListener adEventListener;
|
||||||
@Nullable private Set<UiElement> adUiElements;
|
@Nullable private Set<UiElement> adUiElements;
|
||||||
@Nullable private Collection<CompanionAdSlot> companionAdSlots;
|
@Nullable private Collection<CompanionAdSlot> companionAdSlots;
|
||||||
|
|
@ -165,6 +166,19 @@ public final class ImaAdsLoader
|
||||||
return this;
|
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
|
* Sets a listener for ad events that will be passed to {@link
|
||||||
* AdsManager#addAdEventListener(AdEventListener)}.
|
* AdsManager#addAdEventListener(AdEventListener)}.
|
||||||
|
|
@ -316,6 +330,7 @@ public final class ImaAdsLoader
|
||||||
playAdBeforeStartPosition,
|
playAdBeforeStartPosition,
|
||||||
adUiElements,
|
adUiElements,
|
||||||
companionAdSlots,
|
companionAdSlots,
|
||||||
|
adErrorListener,
|
||||||
adEventListener,
|
adEventListener,
|
||||||
imaFactory);
|
imaFactory);
|
||||||
}
|
}
|
||||||
|
|
@ -341,6 +356,7 @@ public final class ImaAdsLoader
|
||||||
playAdBeforeStartPosition,
|
playAdBeforeStartPosition,
|
||||||
adUiElements,
|
adUiElements,
|
||||||
companionAdSlots,
|
companionAdSlots,
|
||||||
|
adErrorListener,
|
||||||
adEventListener,
|
adEventListener,
|
||||||
imaFactory);
|
imaFactory);
|
||||||
}
|
}
|
||||||
|
|
@ -408,6 +424,7 @@ public final class ImaAdsLoader
|
||||||
private final int mediaBitrate;
|
private final int mediaBitrate;
|
||||||
@Nullable private final Set<UiElement> adUiElements;
|
@Nullable private final Set<UiElement> adUiElements;
|
||||||
@Nullable private final Collection<CompanionAdSlot> companionAdSlots;
|
@Nullable private final Collection<CompanionAdSlot> companionAdSlots;
|
||||||
|
@Nullable private final AdErrorListener adErrorListener;
|
||||||
@Nullable private final AdEventListener adEventListener;
|
@Nullable private final AdEventListener adEventListener;
|
||||||
private final ImaFactory imaFactory;
|
private final ImaFactory imaFactory;
|
||||||
private final ImaSdkSettings imaSdkSettings;
|
private final ImaSdkSettings imaSdkSettings;
|
||||||
|
|
@ -516,6 +533,7 @@ public final class ImaAdsLoader
|
||||||
/* playAdBeforeStartPosition= */ true,
|
/* playAdBeforeStartPosition= */ true,
|
||||||
/* adUiElements= */ null,
|
/* adUiElements= */ null,
|
||||||
/* companionAdSlots= */ null,
|
/* companionAdSlots= */ null,
|
||||||
|
/* adErrorListener= */ null,
|
||||||
/* adEventListener= */ null,
|
/* adEventListener= */ null,
|
||||||
/* imaFactory= */ new DefaultImaFactory());
|
/* imaFactory= */ new DefaultImaFactory());
|
||||||
}
|
}
|
||||||
|
|
@ -534,6 +552,7 @@ public final class ImaAdsLoader
|
||||||
boolean playAdBeforeStartPosition,
|
boolean playAdBeforeStartPosition,
|
||||||
@Nullable Set<UiElement> adUiElements,
|
@Nullable Set<UiElement> adUiElements,
|
||||||
@Nullable Collection<CompanionAdSlot> companionAdSlots,
|
@Nullable Collection<CompanionAdSlot> companionAdSlots,
|
||||||
|
@Nullable AdErrorListener adErrorListener,
|
||||||
@Nullable AdEventListener adEventListener,
|
@Nullable AdEventListener adEventListener,
|
||||||
ImaFactory imaFactory) {
|
ImaFactory imaFactory) {
|
||||||
checkArgument(adTagUri != null || adsResponse != null);
|
checkArgument(adTagUri != null || adsResponse != null);
|
||||||
|
|
@ -548,6 +567,7 @@ public final class ImaAdsLoader
|
||||||
this.playAdBeforeStartPosition = playAdBeforeStartPosition;
|
this.playAdBeforeStartPosition = playAdBeforeStartPosition;
|
||||||
this.adUiElements = adUiElements;
|
this.adUiElements = adUiElements;
|
||||||
this.companionAdSlots = companionAdSlots;
|
this.companionAdSlots = companionAdSlots;
|
||||||
|
this.adErrorListener = adErrorListener;
|
||||||
this.adEventListener = adEventListener;
|
this.adEventListener = adEventListener;
|
||||||
this.imaFactory = imaFactory;
|
this.imaFactory = imaFactory;
|
||||||
if (imaSdkSettings == null) {
|
if (imaSdkSettings == null) {
|
||||||
|
|
@ -629,6 +649,9 @@ public final class ImaAdsLoader
|
||||||
}
|
}
|
||||||
adsLoader = imaFactory.createAdsLoader(context, imaSdkSettings, adDisplayContainer);
|
adsLoader = imaFactory.createAdsLoader(context, imaSdkSettings, adDisplayContainer);
|
||||||
adsLoader.addAdErrorListener(componentListener);
|
adsLoader.addAdErrorListener(componentListener);
|
||||||
|
if (adErrorListener != null) {
|
||||||
|
adsLoader.addAdErrorListener(adErrorListener);
|
||||||
|
}
|
||||||
adsLoader.addAdsLoadedListener(componentListener);
|
adsLoader.addAdsLoadedListener(componentListener);
|
||||||
AdsRequest request = imaFactory.createAdsRequest();
|
AdsRequest request = imaFactory.createAdsRequest();
|
||||||
if (adTagUri != null) {
|
if (adTagUri != null) {
|
||||||
|
|
@ -759,6 +782,9 @@ public final class ImaAdsLoader
|
||||||
if (adsLoader != null) {
|
if (adsLoader != null) {
|
||||||
adsLoader.removeAdsLoadedListener(componentListener);
|
adsLoader.removeAdsLoadedListener(componentListener);
|
||||||
adsLoader.removeAdErrorListener(componentListener);
|
adsLoader.removeAdErrorListener(componentListener);
|
||||||
|
if (adErrorListener != null) {
|
||||||
|
adsLoader.removeAdErrorListener(adErrorListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
imaPausedContent = false;
|
imaPausedContent = false;
|
||||||
imaAdState = IMA_AD_STATE_NONE;
|
imaAdState = IMA_AD_STATE_NONE;
|
||||||
|
|
@ -1582,6 +1608,9 @@ public final class ImaAdsLoader
|
||||||
private void destroyAdsManager() {
|
private void destroyAdsManager() {
|
||||||
if (adsManager != null) {
|
if (adsManager != null) {
|
||||||
adsManager.removeAdErrorListener(componentListener);
|
adsManager.removeAdErrorListener(componentListener);
|
||||||
|
if (adErrorListener != null) {
|
||||||
|
adsManager.removeAdErrorListener(adErrorListener);
|
||||||
|
}
|
||||||
adsManager.removeAdEventListener(componentListener);
|
adsManager.removeAdEventListener(componentListener);
|
||||||
if (adEventListener != null) {
|
if (adEventListener != null) {
|
||||||
adsManager.removeAdEventListener(adEventListener);
|
adsManager.removeAdEventListener(adEventListener);
|
||||||
|
|
@ -1642,6 +1671,9 @@ public final class ImaAdsLoader
|
||||||
pendingAdRequestContext = null;
|
pendingAdRequestContext = null;
|
||||||
ImaAdsLoader.this.adsManager = adsManager;
|
ImaAdsLoader.this.adsManager = adsManager;
|
||||||
adsManager.addAdErrorListener(this);
|
adsManager.addAdErrorListener(this);
|
||||||
|
if (adErrorListener != null) {
|
||||||
|
adsManager.addAdErrorListener(adErrorListener);
|
||||||
|
}
|
||||||
adsManager.addAdEventListener(this);
|
adsManager.addAdEventListener(this);
|
||||||
if (adEventListener != null) {
|
if (adEventListener != null) {
|
||||||
adsManager.addAdEventListener(adEventListener);
|
adsManager.addAdEventListener(adEventListener);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue