Add replaceAdTagParameters() to ImaServerSideAdInsertion.AdsLoader.

PiperOrigin-RevId: 627114711
This commit is contained in:
Googler 2024-04-22 12:06:43 -07:00 committed by Copybara-Service
parent 7aed9d40a0
commit a43ffa8898
3 changed files with 34 additions and 0 deletions

View File

@ -35,6 +35,9 @@
* Promote API that is required for apps to play
[DAI ad streams](https://developers.google.com/ad-manager/dynamic-ad-insertion/full-service)
to stable.
* Add `replaceAdTagParameters(Map <String, String>)` to
`ImaServerSideAdInsertionMediaSource.AdLoader` that allows replacing ad
tag parameters at runtime.
* Session:
* Hide seekbar in the media notification for live streams by not setting
the duration into the platform session metadata

View File

@ -1393,6 +1393,7 @@ package androidx.media3.exoplayer.ima {
public static final class ImaServerSideAdInsertionMediaSource.AdsLoader {
method public androidx.media3.exoplayer.ima.ImaServerSideAdInsertionMediaSource.AdsLoader.State release();
method public void replaceAdTagParameters(java.util.Map<java.lang.String,java.lang.String>);
method public void setPlayer(androidx.media3.common.Player);
}

View File

@ -472,6 +472,36 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
this.player = player;
}
/**
* Replaces all the ad tag parameters used for the upcoming ad requests for a live stream.
*
* @see StreamManager#replaceAdTagParameters(Map<String, String>)
*/
public void replaceAdTagParameters(Map<String, String> adTagParameters) {
if (player == null) {
return;
}
if (player.getPlaybackState() != Player.STATE_IDLE
&& player.getPlaybackState() != Player.STATE_ENDED
&& player.getMediaItemCount() > 0) {
int currentPeriodIndex = player.getCurrentPeriodIndex();
Object adsId =
player
.getCurrentTimeline()
.getPeriod(currentPeriodIndex, new Timeline.Period())
.getAdsId();
if (adsId instanceof String) {
MediaSourceResourceHolder mediaSourceResourceHolder = mediaSourceResources.get(adsId);
if (mediaSourceResourceHolder != null
&& mediaSourceResourceHolder.imaServerSideAdInsertionMediaSource.streamManager
!= null) {
mediaSourceResourceHolder.imaServerSideAdInsertionMediaSource.streamManager
.replaceAdTagParameters(adTagParameters);
}
}
}
}
/**
* Puts the focus on the skip button, if a skip button is present and an ad is playing.
*