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:
cc26a92e07

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
This commit is contained in:
ibaker 2021-07-02 18:10:46 +01:00 committed by kim-vde
parent 3bd662eb9a
commit 22247d65c7
3 changed files with 12 additions and 8 deletions

View File

@ -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:

View File

@ -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

View File

@ -18,7 +18,6 @@ package com.google.android.exoplayer2.source;
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.Assertions;
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 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
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);