Skip to content

Commit 70d6221

Browse files
marcbaechingercopybara-github
authored andcommitted
Use public ad playback state when evaluating the public stream position
PiperOrigin-RevId: 781077925
1 parent 6d0f06c commit 70d6221

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/source/ads/ServerSideAdInsertionUtil.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,35 +84,35 @@ public static AdPlaybackState addAdGroupToAdPlaybackState(
8484
}
8585

8686
/**
87-
* Returns the position in the underlying server-side inserted ads stream for the current playback
88-
* position in the {@link Player}.
87+
* Returns the position in the underlying server-side inserted ads stream of the given ads ID for
88+
* the current playback position in the {@link Player}.
8989
*
9090
* @param player The {@link Player}.
91-
* @param adPlaybackState The {@link AdPlaybackState} defining the ad groups.
91+
* @param adsId The ads ID of the period for which to get the stream position.
9292
* @return The position in the underlying server-side inserted ads stream, in microseconds, or
9393
* {@link C#TIME_UNSET} if it can't be determined.
9494
*/
95-
public static long getStreamPositionUs(Player player, AdPlaybackState adPlaybackState) {
95+
public static long getStreamPositionUs(Player player, Object adsId) {
9696
Timeline timeline = player.getCurrentTimeline();
9797
if (timeline.isEmpty()) {
9898
return C.TIME_UNSET;
9999
}
100100
Timeline.Period period =
101101
timeline.getPeriod(player.getCurrentPeriodIndex(), new Timeline.Period());
102-
if (!Objects.equals(period.getAdsId(), adPlaybackState.adsId)) {
102+
if (!Objects.equals(period.getAdsId(), adsId)) {
103103
return C.TIME_UNSET;
104104
}
105105
if (player.isPlayingAd()) {
106106
int adGroupIndex = player.getCurrentAdGroupIndex();
107107
int adIndexInAdGroup = player.getCurrentAdIndexInAdGroup();
108108
long adPositionUs = Util.msToUs(player.getCurrentPosition());
109109
return getStreamPositionUsForAd(
110-
adPositionUs, adGroupIndex, adIndexInAdGroup, adPlaybackState);
110+
adPositionUs, adGroupIndex, adIndexInAdGroup, period.adPlaybackState);
111111
}
112112
long periodPositionUs =
113113
Util.msToUs(player.getCurrentPosition()) - period.getPositionInWindowUs();
114114
return getStreamPositionUsForContent(
115-
periodPositionUs, /* nextAdGroupIndex= */ C.INDEX_UNSET, adPlaybackState);
115+
periodPositionUs, /* nextAdGroupIndex= */ C.INDEX_UNSET, period.adPlaybackState);
116116
}
117117

118118
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,9 @@ public VideoProgressUpdate getContentProgress() {
13581358
AdPlaybackState adPlaybackState = checkNotNull(adPlaybackStates.get(contentPeriod.uid));
13591359
// Calculate the stream position from the current position and the playback state.
13601360
streamPositionMs =
1361-
usToMs(ServerSideAdInsertionUtil.getStreamPositionUs(player, adPlaybackState));
1361+
usToMs(
1362+
ServerSideAdInsertionUtil.getStreamPositionUs(
1363+
player, checkNotNull(adPlaybackState.adsId)));
13621364
if (window.windowStartTimeMs != C.TIME_UNSET) {
13631365
// Add the time since epoch at start of the window for live streams.
13641366
streamPositionMs += window.windowStartTimeMs + period.getPositionInWindowMs();

0 commit comments

Comments
 (0)