From 22247d65c79568c99773e64480084fcaf96ec94b Mon Sep 17 00:00:00 2001 From: ibaker Date: Fri, 2 Jul 2021 18:10:46 +0100 Subject: [PATCH] Use the content URI as well as mediaId for the auto-generated ad ID MediaItem.mediaId used to default to the content URI, but this changed: https://github.com/google/ExoPlayer/commit/cc26a92e070db8963738beed423bb4699762877f Before the mediaId change linked above, a playlist of different content all with the same ad URI would play the ads for every item. After the change the ad would only play once (because mediaId == "" for every item, so they're all the same). This change restores roughly the original behaviour by always considering both mediaId and the content URI. #minor-release Issue: #9106 PiperOrigin-RevId: 382763618 --- RELEASENOTES.md | 3 +++ docs/ad-insertion.md | 12 ++++++------ .../exoplayer2/source/DefaultMediaSourceFactory.java | 5 +++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index a108714d807..4d42413a780 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -105,6 +105,9 @@ * Support changing ad break positions in the player logic ([#5067](https://github.com/google/ExoPlayer/issues/5067). * Support resuming content with an offset after an ad group. + * Use the content URI when auto-generating an ad ID (in addition to the + media ID and ad tag URI) + ([#9106](https://github.com/google/ExoPlayer/issues/9106). * DRM: * Allow repeated provisioning in `DefaultDrmSession(Manager)`. * PlayerNotificationManager: diff --git a/docs/ad-insertion.md b/docs/ad-insertion.md index 8ca6e00ba76..972f07a9c59 100644 --- a/docs/ad-insertion.md +++ b/docs/ad-insertion.md @@ -67,12 +67,12 @@ described below. ### Playlists with ads ### When playing a [playlist][] with multiple media items, the default behavior is -to request the ad tag and store ad playback state once for each media ID and ad -tag URI combination. This means that users will see ads for every media item -with ads that has a distinct media ID, even if the ad tag URIs match. If a -media item is repeated, the user will see the corresponding ads only once (the -ad playback state stores whether ads have been played, so they are skipped -after their first occurrence). +to request the ad tag and store ad playback state once for each media ID, +content URI and ad tag URI combination. This means that users will see ads for +every media item with ads that has a distinct media ID or content URI, even if +the ad tag URIs match. If a media item is repeated, the user will see the +corresponding ads only once (the ad playback state stores whether ads have been +played, so they are skipped after their first occurrence). It's possible to customize this behavior by passing an opaque ads identifier with which ad playback state for a given media item is linked, based on object diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java b/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java index 5ed17316187..3a2fbdcd3bb 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/DefaultMediaSourceFactory.java @@ -18,7 +18,6 @@ import static com.google.android.exoplayer2.util.Util.castNonNull; import android.content.Context; -import android.util.Pair; import android.util.SparseArray; import androidx.annotation.Nullable; import com.google.android.exoplayer2.C; @@ -40,6 +39,7 @@ import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.Util; +import com.google.common.collect.ImmutableList; import java.util.Arrays; import java.util.List; @@ -426,7 +426,8 @@ private MediaSource maybeWrapWithAdsMediaSource(MediaItem mediaItem, MediaSource new DataSpec(adsConfiguration.adTagUri), /* adsId= */ adsConfiguration.adsId != null ? adsConfiguration.adsId - : Pair.create(mediaItem.mediaId, adsConfiguration.adTagUri), + : ImmutableList.of( + mediaItem.mediaId, mediaItem.playbackProperties.uri, adsConfiguration.adTagUri), /* adMediaSourceFactory= */ this, adsLoader, adViewProvider);