diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 3d6f16349c..fcf2c5fc46 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -34,6 +34,9 @@ * DASH: * Fix handling of empty segment timelines ([#11014](https://github.com/google/ExoPlayer/issues/11014)). +* IMA DAI extension: + * Fix a bug where a new ad group is inserted in live streams because the + calculated content position in consecutive timelines varies slightly. * Remove deprecated symbols: * Remove `DefaultAudioSink` constructors, use `DefaultAudioSink.Builder` instead. diff --git a/libraries/exoplayer_ima/src/main/java/androidx/media3/exoplayer/ima/ImaServerSideAdInsertionMediaSource.java b/libraries/exoplayer_ima/src/main/java/androidx/media3/exoplayer/ima/ImaServerSideAdInsertionMediaSource.java index 13d3209098..d418768885 100644 --- a/libraries/exoplayer_ima/src/main/java/androidx/media3/exoplayer/ima/ImaServerSideAdInsertionMediaSource.java +++ b/libraries/exoplayer_ima/src/main/java/androidx/media3/exoplayer/ima/ImaServerSideAdInsertionMediaSource.java @@ -1340,16 +1340,18 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou } AdPlaybackState newAdPlaybackState = adPlaybackState; Timeline timeline = player.getCurrentTimeline(); + Timeline.Period currentPeriod = new Timeline.Period(); long positionInWindowUs = - timeline.getPeriod(player.getCurrentPeriodIndex(), new Timeline.Period()) - .positionInWindowUs; - long currentContentPeriodPositionUs = - msToUs(player.getContentPosition()) - positionInWindowUs; + timeline.getPeriod(player.getCurrentPeriodIndex(), currentPeriod).positionInWindowUs; + long contentPositionUs = + player.isPlayingAd() + ? currentPeriod.getAdGroupTimeUs(player.getCurrentAdGroupIndex()) + : msToUs(player.getContentPosition()); Ad ad = event.getAd(); AdPodInfo adPodInfo = ad.getAdPodInfo(); newAdPlaybackState = addLiveAdBreak( - currentContentPeriodPositionUs, + /* currentContentPeriodPositionUs= */ contentPositionUs - positionInWindowUs, /* adDurationUs= */ secToUsRounded(ad.getDuration()), /* adPositionInAdPod= */ adPodInfo.getAdPosition(), /* totalAdDurationUs= */ secToUsRounded(adPodInfo.getMaxDuration()),