Skip to content

Commit

Permalink
Use the content URI as well as mediaId for the auto-generated ad ID
Browse files Browse the repository at this point in the history
MediaItem.mediaId used to default to the content URI, but this changed:
cc26a92

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.

Issue: #9106
PiperOrigin-RevId: 382763618
  • Loading branch information
icbaker committed Jul 16, 2021
1 parent 306b2e6 commit 278593f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
([#9004](https://github.com/google/ExoPlayer/issues/9004)).
* Forward the FRAME-RATE value from the master playlist to renditions.
([#8960](https://github.com/google/ExoPlayer/issues/8960)).
* Ad playback:
* 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)`.
* Metadata:
Expand Down
12 changes: 6 additions & 6 deletions docs/ad-insertion.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -427,7 +427,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);
Expand Down

0 comments on commit 278593f

Please sign in to comment.