Commit f1197d8a by andrewlewis Committed by Oliver Woodman

Handle errors in all VideoAdPlayer callbacks

Some but not all VideoAdPlayer callbacks from the IMA SDK included
defensive handling of unexpected cases. Add the remaining ones.

Issue: #7492
PiperOrigin-RevId: 316082651
parent 8ab3fab4
...@@ -6,7 +6,10 @@ ...@@ -6,7 +6,10 @@
seeking to an unprepared period within the current window. For example when seeking to an unprepared period within the current window. For example when
seeking over an ad group, or to the next period in a multi-period DASH seeking over an ad group, or to the next period in a multi-period DASH
stream ([#5507](https://github.com/google/ExoPlayer/issues/5507)). stream ([#5507](https://github.com/google/ExoPlayer/issues/5507)).
* IMA extension: Add option to skip ads before the start position. * IMA extension:
* Add option to skip ads before the start position.
* Catch unexpected errors in `stopAd` to avoid a crash
([#7492](https://github.com/google/ExoPlayer/issues/7492)).
### 2.11.5 (2020-06-05) ### ### 2.11.5 (2020-06-05) ###
......
...@@ -916,32 +916,36 @@ public final class ImaAdsLoader ...@@ -916,32 +916,36 @@ public final class ImaAdsLoader
Log.w(TAG, "Unexpected playAd without stopAd"); Log.w(TAG, "Unexpected playAd without stopAd");
} }
if (imaAdState == IMA_AD_STATE_NONE) { try {
// IMA is requesting to play the ad, so stop faking the content position. if (imaAdState == IMA_AD_STATE_NONE) {
fakeContentProgressElapsedRealtimeMs = C.TIME_UNSET; // IMA is requesting to play the ad, so stop faking the content position.
fakeContentProgressOffsetMs = C.TIME_UNSET; fakeContentProgressElapsedRealtimeMs = C.TIME_UNSET;
imaAdState = IMA_AD_STATE_PLAYING; fakeContentProgressOffsetMs = C.TIME_UNSET;
imaAdMediaInfo = adMediaInfo; imaAdState = IMA_AD_STATE_PLAYING;
imaAdInfo = Assertions.checkNotNull(adInfoByAdMediaInfo.get(adMediaInfo)); imaAdMediaInfo = adMediaInfo;
for (int i = 0; i < adCallbacks.size(); i++) { imaAdInfo = Assertions.checkNotNull(adInfoByAdMediaInfo.get(adMediaInfo));
adCallbacks.get(i).onPlay(adMediaInfo);
}
if (pendingAdPrepareErrorAdInfo != null && pendingAdPrepareErrorAdInfo.equals(imaAdInfo)) {
pendingAdPrepareErrorAdInfo = null;
for (int i = 0; i < adCallbacks.size(); i++) { for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onError(adMediaInfo); adCallbacks.get(i).onPlay(adMediaInfo);
}
if (pendingAdPrepareErrorAdInfo != null && pendingAdPrepareErrorAdInfo.equals(imaAdInfo)) {
pendingAdPrepareErrorAdInfo = null;
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onError(adMediaInfo);
}
}
updateAdProgress();
} else {
imaAdState = IMA_AD_STATE_PLAYING;
Assertions.checkState(adMediaInfo.equals(imaAdMediaInfo));
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onResume(adMediaInfo);
} }
} }
updateAdProgress(); if (!Assertions.checkNotNull(player).getPlayWhenReady()) {
} else { Assertions.checkNotNull(adsManager).pause();
imaAdState = IMA_AD_STATE_PLAYING;
Assertions.checkState(adMediaInfo.equals(imaAdMediaInfo));
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onResume(adMediaInfo);
} }
} } catch (RuntimeException e) {
if (!Assertions.checkNotNull(player).getPlayWhenReady()) { maybeNotifyInternalError("playAd", e);
Assertions.checkNotNull(adsManager).pause();
} }
} }
...@@ -955,9 +959,9 @@ public final class ImaAdsLoader ...@@ -955,9 +959,9 @@ public final class ImaAdsLoader
return; return;
} }
Assertions.checkNotNull(player);
Assertions.checkState(imaAdState != IMA_AD_STATE_NONE);
try { try {
Assertions.checkNotNull(player);
Assertions.checkState(imaAdState != IMA_AD_STATE_NONE);
stopAdInternal(); stopAdInternal();
} catch (RuntimeException e) { } catch (RuntimeException e) {
maybeNotifyInternalError("stopAd", e); maybeNotifyInternalError("stopAd", e);
...@@ -973,10 +977,15 @@ public final class ImaAdsLoader ...@@ -973,10 +977,15 @@ public final class ImaAdsLoader
// This method is called after content is resumed. // This method is called after content is resumed.
return; return;
} }
Assertions.checkState(adMediaInfo.equals(imaAdMediaInfo));
imaAdState = IMA_AD_STATE_PAUSED; try {
for (int i = 0; i < adCallbacks.size(); i++) { Assertions.checkState(adMediaInfo.equals(imaAdMediaInfo));
adCallbacks.get(i).onPause(adMediaInfo); imaAdState = IMA_AD_STATE_PAUSED;
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onPause(adMediaInfo);
}
} catch (RuntimeException e) {
maybeNotifyInternalError("pauseAd", e);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment