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
This commit is contained in:
andrewlewis 2020-06-12 12:20:43 +01:00 committed by Oliver Woodman
parent c5144dc777
commit 5a88e0bc1d
2 changed files with 41 additions and 29 deletions

View File

@ -208,7 +208,10 @@
([#6922](https://github.com/google/ExoPlayer/pull/6922)).
* Cast extension: Implement playlist API and deprecate the old queue
manipulation API.
* 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)).
* Demo app: Retain previous position in list of samples.
* Add Guava dependency.

View File

@ -916,6 +916,7 @@ public final class ImaAdsLoader
Log.w(TAG, "Unexpected playAd without stopAd");
}
try {
if (imaAdState == IMA_AD_STATE_NONE) {
// IMA is requesting to play the ad, so stop faking the content position.
fakeContentProgressElapsedRealtimeMs = C.TIME_UNSET;
@ -943,6 +944,9 @@ public final class ImaAdsLoader
if (!Assertions.checkNotNull(player).getPlayWhenReady()) {
Assertions.checkNotNull(adsManager).pause();
}
} catch (RuntimeException e) {
maybeNotifyInternalError("playAd", e);
}
}
@Override
@ -955,9 +959,9 @@ public final class ImaAdsLoader
return;
}
try {
Assertions.checkNotNull(player);
Assertions.checkState(imaAdState != IMA_AD_STATE_NONE);
try {
stopAdInternal();
} catch (RuntimeException e) {
maybeNotifyInternalError("stopAd", e);
@ -973,11 +977,16 @@ public final class ImaAdsLoader
// This method is called after content is resumed.
return;
}
try {
Assertions.checkState(adMediaInfo.equals(imaAdMediaInfo));
imaAdState = IMA_AD_STATE_PAUSED;
for (int i = 0; i < adCallbacks.size(); i++) {
adCallbacks.get(i).onPause(adMediaInfo);
}
} catch (RuntimeException e) {
maybeNotifyInternalError("pauseAd", e);
}
}
// Player.EventListener implementation.