Skip to content

Commit ed56ed2

Browse files
marcbaechingercopybara-github
authored andcommitted
Don't enqueue ad periods that start after the end of the period
Issue: #2215 PiperOrigin-RevId: 747376615
1 parent 3205811 commit ed56ed2

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

RELEASENOTES.md

+4
Original file line numberDiff line numberDiff line change
@@ -2981,6 +2981,10 @@ This release corresponds to the
29812981
* Ad playback / IMA:
29822982
* Decrease ad polling rate from every 100ms to every 200ms, to line up
29832983
with Media Rating Council (MRC) recommendations.
2984+
* Fix bug where ad groups after the end of a VOD window stalled playback.
2985+
Ads groups with a start time after the window are not enqueued into the
2986+
`MediaPeriodQueue` anymore
2987+
([#2215](https://github.com/androidx/media/issues/2215)).
29842988
* FFmpeg extension:
29852989
* Update CMake version to `3.21.0+` to avoid a CMake bug causing
29862990
AndroidStudio's gradle sync to fail

libraries/common/src/main/java/androidx/media3/common/AdPlaybackState.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,10 @@ && getAdGroup(index).timeUs <= positionUs)
865865
|| !getAdGroup(index).shouldPlayAdGroup())) {
866866
index++;
867867
}
868-
return index < adGroupCount ? index : C.INDEX_UNSET;
868+
return index < adGroupCount
869+
&& (periodDurationUs == C.TIME_UNSET || getAdGroup(index).timeUs <= periodDurationUs)
870+
? index
871+
: C.INDEX_UNSET;
869872
}
870873

871874
/** Returns whether the specified ad has been marked as in {@link #AD_STATE_ERROR}. */

libraries/common/src/test/java/androidx/media3/common/AdPlaybackStateTest.java

+4
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,10 @@ public void endsWithLivePostrollPlaceHolder_emptyAdPlaybackState_postrollNotDete
856856
state.getAdGroupIndexAfterPositionUs(
857857
/* positionUs= */ C.TIME_END_OF_SOURCE, /* periodDurationUs= */ 5000))
858858
.isEqualTo(C.INDEX_UNSET);
859+
assertThat(
860+
state.getAdGroupIndexAfterPositionUs(
861+
/* positionUs= */ 1001, /* periodDurationUs= */ 1002))
862+
.isEqualTo(C.INDEX_UNSET);
859863
}
860864

861865
@Test

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ private void handlePlayerStateChanged(boolean playWhenReady, @Player.State int p
868868
}
869869

870870
if (imaAdState == IMA_AD_STATE_NONE
871-
&& playbackState == Player.STATE_BUFFERING
871+
&& (playbackState == Player.STATE_BUFFERING || playbackState == Player.STATE_ENDED)
872872
&& playWhenReady) {
873873
ensureSentContentCompleteIfAtEndOfStream();
874874
} else if (imaAdState != IMA_AD_STATE_NONE && playbackState == Player.STATE_ENDED) {

0 commit comments

Comments
 (0)