@@ -916,32 +916,36 @@ public void playAd(AdMediaInfo adMediaInfo) {
916
916
Log .w (TAG , "Unexpected playAd without stopAd" );
917
917
}
918
918
919
- if (imaAdState == IMA_AD_STATE_NONE ) {
920
- // IMA is requesting to play the ad, so stop faking the content position.
921
- fakeContentProgressElapsedRealtimeMs = C .TIME_UNSET ;
922
- fakeContentProgressOffsetMs = C .TIME_UNSET ;
923
- imaAdState = IMA_AD_STATE_PLAYING ;
924
- imaAdMediaInfo = adMediaInfo ;
925
- imaAdInfo = Assertions .checkNotNull (adInfoByAdMediaInfo .get (adMediaInfo ));
926
- for (int i = 0 ; i < adCallbacks .size (); i ++) {
927
- adCallbacks .get (i ).onPlay (adMediaInfo );
928
- }
929
- if (pendingAdPrepareErrorAdInfo != null && pendingAdPrepareErrorAdInfo .equals (imaAdInfo )) {
930
- pendingAdPrepareErrorAdInfo = null ;
919
+ try {
920
+ if (imaAdState == IMA_AD_STATE_NONE ) {
921
+ // IMA is requesting to play the ad, so stop faking the content position.
922
+ fakeContentProgressElapsedRealtimeMs = C .TIME_UNSET ;
923
+ fakeContentProgressOffsetMs = C .TIME_UNSET ;
924
+ imaAdState = IMA_AD_STATE_PLAYING ;
925
+ imaAdMediaInfo = adMediaInfo ;
926
+ imaAdInfo = Assertions .checkNotNull (adInfoByAdMediaInfo .get (adMediaInfo ));
931
927
for (int i = 0 ; i < adCallbacks .size (); i ++) {
932
- adCallbacks .get (i ).onError (adMediaInfo );
928
+ adCallbacks .get (i ).onPlay (adMediaInfo );
929
+ }
930
+ if (pendingAdPrepareErrorAdInfo != null && pendingAdPrepareErrorAdInfo .equals (imaAdInfo )) {
931
+ pendingAdPrepareErrorAdInfo = null ;
932
+ for (int i = 0 ; i < adCallbacks .size (); i ++) {
933
+ adCallbacks .get (i ).onError (adMediaInfo );
934
+ }
935
+ }
936
+ updateAdProgress ();
937
+ } else {
938
+ imaAdState = IMA_AD_STATE_PLAYING ;
939
+ Assertions .checkState (adMediaInfo .equals (imaAdMediaInfo ));
940
+ for (int i = 0 ; i < adCallbacks .size (); i ++) {
941
+ adCallbacks .get (i ).onResume (adMediaInfo );
933
942
}
934
943
}
935
- updateAdProgress ();
936
- } else {
937
- imaAdState = IMA_AD_STATE_PLAYING ;
938
- Assertions .checkState (adMediaInfo .equals (imaAdMediaInfo ));
939
- for (int i = 0 ; i < adCallbacks .size (); i ++) {
940
- adCallbacks .get (i ).onResume (adMediaInfo );
944
+ if (!Assertions .checkNotNull (player ).getPlayWhenReady ()) {
945
+ Assertions .checkNotNull (adsManager ).pause ();
941
946
}
942
- }
943
- if (!Assertions .checkNotNull (player ).getPlayWhenReady ()) {
944
- Assertions .checkNotNull (adsManager ).pause ();
947
+ } catch (RuntimeException e ) {
948
+ maybeNotifyInternalError ("playAd" , e );
945
949
}
946
950
}
947
951
@@ -955,9 +959,9 @@ public void stopAd(AdMediaInfo adMediaInfo) {
955
959
return ;
956
960
}
957
961
958
- Assertions .checkNotNull (player );
959
- Assertions .checkState (imaAdState != IMA_AD_STATE_NONE );
960
962
try {
963
+ Assertions .checkNotNull (player );
964
+ Assertions .checkState (imaAdState != IMA_AD_STATE_NONE );
961
965
stopAdInternal ();
962
966
} catch (RuntimeException e ) {
963
967
maybeNotifyInternalError ("stopAd" , e );
@@ -973,10 +977,15 @@ public void pauseAd(AdMediaInfo adMediaInfo) {
973
977
// This method is called after content is resumed.
974
978
return ;
975
979
}
976
- Assertions .checkState (adMediaInfo .equals (imaAdMediaInfo ));
977
- imaAdState = IMA_AD_STATE_PAUSED ;
978
- for (int i = 0 ; i < adCallbacks .size (); i ++) {
979
- adCallbacks .get (i ).onPause (adMediaInfo );
980
+
981
+ try {
982
+ Assertions .checkState (adMediaInfo .equals (imaAdMediaInfo ));
983
+ imaAdState = IMA_AD_STATE_PAUSED ;
984
+ for (int i = 0 ; i < adCallbacks .size (); i ++) {
985
+ adCallbacks .get (i ).onPause (adMediaInfo );
986
+ }
987
+ } catch (RuntimeException e ) {
988
+ maybeNotifyInternalError ("pauseAd" , e );
980
989
}
981
990
}
982
991
0 commit comments