Skip to content

Commit 7659ff2

Browse files
committed
Add test
1 parent 6b11abd commit 7659ff2

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

libraries/exoplayer_ima/src/main/java/androidx/media3/exoplayer/ima/AdTagLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public void deactivate() {
402402
* callback can be handled first.
403403
*/
404404
private void deactivateInternal(Player player) {
405-
if (!AdPlaybackState.NONE.equals(adPlaybackState)
405+
if (!adPlaybackState.equals(AdPlaybackState.NONE)
406406
&& imaPausedContent
407407
&& player.getPlayerError() == null) {
408408
if (adsManager != null) {

libraries/exoplayer_ima/src/test/java/androidx/media3/exoplayer/ima/ImaAdsLoaderTest.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,41 @@ public void buildWithEnableContinuousPlayback_setsAdsRequestProperty() {
14811481
verify(mockAdsRequest).setContinuousPlayback(true);
14821482
}
14831483

1484+
@Test
1485+
public void contentErrorDuringAdPlayback_doesNotMarkAdAsFailed() throws IOException {
1486+
// Load and play a preroll ad.
1487+
imaAdsLoader.start(
1488+
adsMediaSource, TEST_DATA_SPEC, TEST_ADS_ID, adViewProvider, adsLoaderListener);
1489+
adEventListener.onAdEvent(getAdEvent(AdEventType.LOADED, mockPrerollSingleAd));
1490+
videoAdPlayer.loadAd(TEST_AD_MEDIA_INFO, mockAdPodInfo);
1491+
adEventListener.onAdEvent(getAdEvent(AdEventType.CONTENT_PAUSE_REQUESTED, mockPrerollSingleAd));
1492+
videoAdPlayer.playAd(TEST_AD_MEDIA_INFO);
1493+
fakePlayer.setPlayingAdPosition(
1494+
/* periodIndex= */ 0,
1495+
/* adGroupIndex= */ 0,
1496+
/* adIndexInAdGroup= */ 0,
1497+
/* positionMs= */ 0,
1498+
/* contentPositionMs= */ 0);
1499+
fakePlayer.setState(Player.STATE_READY, /* playWhenReady= */ true);
1500+
adEventListener.onAdEvent(getAdEvent(AdEventType.STARTED, mockPrerollSingleAd));
1501+
1502+
// Simulate a content preparation error while the ad is playing.
1503+
// The player is not playing an ad from its perspective, so isPlayingAd() is false.
1504+
fakePlayer.setPlayingContentPosition(/* periodIndex= */ 0, /* positionMs= */ 0);
1505+
ExoPlaybackException error =
1506+
ExoPlaybackException.createForSource(
1507+
new IOException("Content preparation error"),
1508+
PlaybackException.ERROR_CODE_IO_UNSPECIFIED);
1509+
fakePlayer.setPlayerError(error);
1510+
shadowOf(Looper.getMainLooper()).runToEndOfTasks();
1511+
1512+
// Verify that the ad is not marked as failed.
1513+
AdPlaybackState adPlaybackState = getAdPlaybackState(0);
1514+
assertThat(adPlaybackState.getAdGroup(0).states[0])
1515+
.isNotEqualTo(AdPlaybackState.AD_STATE_ERROR);
1516+
verify(mockVideoAdPlayerCallback, never()).onError(any());
1517+
}
1518+
14841519
private void setupMocks() {
14851520
ArgumentCaptor<Object> userRequestContextCaptor = ArgumentCaptor.forClass(Object.class);
14861521
doNothing().when(mockAdsRequest).setUserRequestContext(userRequestContextCaptor.capture());

0 commit comments

Comments
 (0)