mirror of
https://github.com/androidx/media.git
synced 2025-05-09 08:30:43 +08:00
Plumb PlayerId to MediaSource.
MediaSource can be reused with other Player instances after they have been released, so we need to set the PlayerId when preparing the source. Access can mostly be handled by the implementation in BaseMediaSource. PiperOrigin-RevId: 408878824
This commit is contained in:
parent
f7bb6e0a23
commit
5d8bb7ddd2
@ -276,7 +276,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
Handler eventHandler = new Handler(applicationLooper);
|
||||
queue = new MediaPeriodQueue(analyticsCollector, eventHandler);
|
||||
mediaSourceList = new MediaSourceList(/* listener= */ this, analyticsCollector, eventHandler);
|
||||
mediaSourceList =
|
||||
new MediaSourceList(/* listener= */ this, analyticsCollector, eventHandler, playerId);
|
||||
|
||||
// Note: The documentation for Process.THREAD_PRIORITY_AUDIO that states "Applications can
|
||||
// not normally change to this priority" is incorrect.
|
||||
|
@ -26,6 +26,7 @@ import androidx.media3.common.util.Log;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.datasource.TransferListener;
|
||||
import androidx.media3.exoplayer.analytics.AnalyticsCollector;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.drm.DrmSession;
|
||||
import androidx.media3.exoplayer.drm.DrmSessionEventListener;
|
||||
import androidx.media3.exoplayer.source.LoadEventInfo;
|
||||
@ -71,6 +72,7 @@ import java.util.Set;
|
||||
|
||||
private static final String TAG = "MediaSourceList";
|
||||
|
||||
private final PlayerId playerId;
|
||||
private final List<MediaSourceHolder> mediaSourceHolders;
|
||||
private final IdentityHashMap<MediaPeriod, MediaSourceHolder> mediaSourceByMediaPeriod;
|
||||
private final Map<Object, MediaSourceHolder> mediaSourceByUid;
|
||||
@ -94,11 +96,14 @@ import java.util.Set;
|
||||
* source events.
|
||||
* @param analyticsCollectorHandler The {@link Handler} to call {@link AnalyticsCollector} methods
|
||||
* on.
|
||||
* @param playerId The {@link PlayerId} of the player using this list.
|
||||
*/
|
||||
public MediaSourceList(
|
||||
MediaSourceListInfoRefreshListener listener,
|
||||
@Nullable AnalyticsCollector analyticsCollector,
|
||||
Handler analyticsCollectorHandler) {
|
||||
Handler analyticsCollectorHandler,
|
||||
PlayerId playerId) {
|
||||
this.playerId = playerId;
|
||||
mediaSourceListInfoListener = listener;
|
||||
shuffleOrder = new DefaultShuffleOrder(0);
|
||||
mediaSourceByMediaPeriod = new IdentityHashMap<>();
|
||||
@ -441,7 +446,7 @@ import java.util.Set;
|
||||
childSources.put(holder, new MediaSourceAndListener(mediaSource, caller, eventListener));
|
||||
mediaSource.addEventListener(Util.createHandlerForCurrentOrMainLooper(), eventListener);
|
||||
mediaSource.addDrmEventListener(Util.createHandlerForCurrentOrMainLooper(), eventListener);
|
||||
mediaSource.prepareSource(caller, mediaTransferListener);
|
||||
mediaSource.prepareSource(caller, mediaTransferListener, playerId);
|
||||
}
|
||||
|
||||
private void maybeReleaseChildSource(MediaSourceHolder mediaSourceHolder) {
|
||||
|
@ -30,6 +30,7 @@ import androidx.media3.common.TrackGroupArray;
|
||||
import androidx.media3.common.util.Clock;
|
||||
import androidx.media3.common.util.HandlerWrapper;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory;
|
||||
import androidx.media3.exoplayer.source.MediaPeriod;
|
||||
import androidx.media3.exoplayer.source.MediaSource;
|
||||
@ -145,7 +146,8 @@ public final class MetadataRetriever {
|
||||
case MESSAGE_PREPARE_SOURCE:
|
||||
MediaItem mediaItem = (MediaItem) msg.obj;
|
||||
mediaSource = mediaSourceFactory.createMediaSource(mediaItem);
|
||||
mediaSource.prepareSource(mediaSourceCaller, /* mediaTransferListener= */ null);
|
||||
mediaSource.prepareSource(
|
||||
mediaSourceCaller, /* mediaTransferListener= */ null, PlayerId.UNSET);
|
||||
mediaSourceHandler.sendEmptyMessage(MESSAGE_CHECK_FOR_FAILURE);
|
||||
return true;
|
||||
case MESSAGE_CHECK_FOR_FAILURE:
|
||||
|
@ -41,6 +41,7 @@ import androidx.media3.exoplayer.ExoPlaybackException;
|
||||
import androidx.media3.exoplayer.Renderer;
|
||||
import androidx.media3.exoplayer.RendererCapabilities;
|
||||
import androidx.media3.exoplayer.RenderersFactory;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.audio.AudioRendererEventListener;
|
||||
import androidx.media3.exoplayer.drm.DrmSessionManager;
|
||||
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory;
|
||||
@ -959,7 +960,8 @@ public final class DownloadHelper {
|
||||
public boolean handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MESSAGE_PREPARE_SOURCE:
|
||||
mediaSource.prepareSource(/* caller= */ this, /* mediaTransferListener= */ null);
|
||||
mediaSource.prepareSource(
|
||||
/* caller= */ this, /* mediaTransferListener= */ null, PlayerId.UNSET);
|
||||
mediaSourceHandler.sendEmptyMessage(MESSAGE_CHECK_FOR_FAILURE);
|
||||
return true;
|
||||
case MESSAGE_CHECK_FOR_FAILURE:
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package androidx.media3.exoplayer.source;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkStateNotNull;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -22,6 +24,7 @@ import androidx.media3.common.Timeline;
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.datasource.TransferListener;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.drm.DrmSessionEventListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -43,6 +46,7 @@ public abstract class BaseMediaSource implements MediaSource {
|
||||
|
||||
@Nullable private Looper looper;
|
||||
@Nullable private Timeline timeline;
|
||||
@Nullable private PlayerId playerId;
|
||||
|
||||
public BaseMediaSource() {
|
||||
mediaSourceCallers = new ArrayList<>(/* initialCapacity= */ 1);
|
||||
@ -53,7 +57,7 @@ public abstract class BaseMediaSource implements MediaSource {
|
||||
|
||||
/**
|
||||
* Starts source preparation and enables the source, see {@link #prepareSource(MediaSourceCaller,
|
||||
* TransferListener)}. This method is called at most once until the next call to {@link
|
||||
* TransferListener, PlayerId)}. This method is called at most once until the next call to {@link
|
||||
* #releaseSourceInternal()}.
|
||||
*
|
||||
* @param mediaTransferListener The transfer listener which should be informed of any media data
|
||||
@ -162,6 +166,16 @@ public abstract class BaseMediaSource implements MediaSource {
|
||||
return !enabledMediaSourceCallers.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link PlayerId} of the player using this media source.
|
||||
*
|
||||
* <p>Must only be used when the media source is {@link #prepareSourceInternal(TransferListener)
|
||||
* prepared}.
|
||||
*/
|
||||
protected final PlayerId getPlayerId() {
|
||||
return checkStateNotNull(playerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void addEventListener(Handler handler, MediaSourceEventListener eventListener) {
|
||||
Assertions.checkNotNull(handler);
|
||||
@ -188,9 +202,12 @@ public abstract class BaseMediaSource implements MediaSource {
|
||||
|
||||
@Override
|
||||
public final void prepareSource(
|
||||
MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener) {
|
||||
MediaSourceCaller caller,
|
||||
@Nullable TransferListener mediaTransferListener,
|
||||
PlayerId playerId) {
|
||||
Looper looper = Looper.myLooper();
|
||||
Assertions.checkArgument(this.looper == null || this.looper == looper);
|
||||
this.playerId = playerId;
|
||||
@Nullable Timeline timeline = this.timeline;
|
||||
mediaSourceCallers.add(caller);
|
||||
if (this.looper == null) {
|
||||
@ -228,6 +245,7 @@ public abstract class BaseMediaSource implements MediaSource {
|
||||
if (mediaSourceCallers.isEmpty()) {
|
||||
looper = null;
|
||||
timeline = null;
|
||||
playerId = null;
|
||||
enabledMediaSourceCallers.clear();
|
||||
releaseSourceInternal();
|
||||
} else {
|
||||
|
@ -119,7 +119,7 @@ public abstract class CompositeMediaSource<T> extends BaseMediaSource {
|
||||
childSources.put(id, new MediaSourceAndListener<>(mediaSource, caller, eventListener));
|
||||
mediaSource.addEventListener(Assertions.checkNotNull(eventHandler), eventListener);
|
||||
mediaSource.addDrmEventListener(Assertions.checkNotNull(eventHandler), eventListener);
|
||||
mediaSource.prepareSource(caller, mediaTransferListener);
|
||||
mediaSource.prepareSource(caller, mediaTransferListener, getPlayerId());
|
||||
if (!isEnabled()) {
|
||||
mediaSource.disable(caller);
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import androidx.media3.common.Timeline;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.datasource.TransferListener;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.drm.DrmSessionEventListener;
|
||||
import androidx.media3.exoplayer.upstream.Allocator;
|
||||
import java.io.IOException;
|
||||
@ -35,7 +36,7 @@ import java.io.IOException;
|
||||
* provide a new timeline whenever the structure of the media changes. The MediaSource
|
||||
* provides these timelines by calling {@link MediaSourceCaller#onSourceInfoRefreshed} on the
|
||||
* {@link MediaSourceCaller}s passed to {@link #prepareSource(MediaSourceCaller,
|
||||
* TransferListener)}.
|
||||
* TransferListener, PlayerId)}.
|
||||
* <li>To provide {@link MediaPeriod} instances for the periods in its timeline. MediaPeriods are
|
||||
* obtained by calling {@link #createPeriod(MediaPeriodId, Allocator, long)}, and provide a
|
||||
* way for the player to load and read the media.
|
||||
@ -173,6 +174,16 @@ public interface MediaSource {
|
||||
/** Returns the {@link MediaItem} whose media is provided by the source. */
|
||||
MediaItem getMediaItem();
|
||||
|
||||
/**
|
||||
* @deprecated Implement {@link #prepareSource(MediaSourceCaller, TransferListener, PlayerId)}
|
||||
* instead.
|
||||
*/
|
||||
@Deprecated
|
||||
default void prepareSource(
|
||||
MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener) {
|
||||
prepareSource(caller, mediaTransferListener, PlayerId.UNSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a {@link MediaSourceCaller}. Starts source preparation if needed and enables the
|
||||
* source for the creation of {@link MediaPeriod MediaPerods}.
|
||||
@ -190,15 +201,20 @@ public interface MediaSource {
|
||||
* transfers. May be null if no listener is available. Note that this listener should be only
|
||||
* informed of transfers related to the media loads and not of auxiliary loads for manifests
|
||||
* and other data.
|
||||
* @param playerId The {@link PlayerId} of the player using this media source.
|
||||
*/
|
||||
void prepareSource(MediaSourceCaller caller, @Nullable TransferListener mediaTransferListener);
|
||||
void prepareSource(
|
||||
MediaSourceCaller caller,
|
||||
@Nullable TransferListener mediaTransferListener,
|
||||
PlayerId playerId);
|
||||
|
||||
/**
|
||||
* Throws any pending error encountered while loading or refreshing source information.
|
||||
*
|
||||
* <p>Should not be called directly from application code.
|
||||
*
|
||||
* <p>Must only be called after {@link #prepareSource(MediaSourceCaller, TransferListener)}.
|
||||
* <p>Must only be called after {@link #prepareSource(MediaSourceCaller, TransferListener,
|
||||
* PlayerId)}.
|
||||
*/
|
||||
void maybeThrowSourceInfoRefreshError() throws IOException;
|
||||
|
||||
@ -207,7 +223,8 @@ public interface MediaSource {
|
||||
*
|
||||
* <p>Should not be called directly from application code.
|
||||
*
|
||||
* <p>Must only be called after {@link #prepareSource(MediaSourceCaller, TransferListener)}.
|
||||
* <p>Must only be called after {@link #prepareSource(MediaSourceCaller, TransferListener,
|
||||
* PlayerId)}.
|
||||
*
|
||||
* @param caller The {@link MediaSourceCaller} enabling the source.
|
||||
*/
|
||||
|
@ -171,7 +171,7 @@ public final class ServerSideInsertedAdsMediaSource extends BaseMediaSource
|
||||
}
|
||||
mediaSource.addEventListener(handler, /* eventListener= */ this);
|
||||
mediaSource.addDrmEventListener(handler, /* eventListener= */ this);
|
||||
mediaSource.prepareSource(/* caller= */ this, mediaTransferListener);
|
||||
mediaSource.prepareSource(/* caller= */ this, mediaTransferListener, getPlayerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,7 +29,9 @@ import androidx.media3.common.PlaybackParameters;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.common.Timeline;
|
||||
import androidx.media3.common.TracksInfo;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.source.MediaSource.MediaPeriodId;
|
||||
import androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller;
|
||||
import androidx.media3.exoplayer.source.SinglePeriodTimeline;
|
||||
import androidx.media3.exoplayer.source.ads.SinglePeriodAdTimeline;
|
||||
import androidx.media3.exoplayer.trackselection.ExoTrackSelection;
|
||||
@ -84,7 +86,8 @@ public final class MediaPeriodQueueTest {
|
||||
new MediaSourceList(
|
||||
mock(MediaSourceList.MediaSourceListInfoRefreshListener.class),
|
||||
/* analyticsCollector= */ null,
|
||||
new Handler(Looper.getMainLooper()));
|
||||
new Handler(Looper.getMainLooper()),
|
||||
PlayerId.UNSET);
|
||||
rendererCapabilities = new RendererCapabilities[0];
|
||||
trackSelector = mock(TrackSelector.class);
|
||||
allocator = mock(Allocator.class);
|
||||
@ -744,7 +747,8 @@ public final class MediaPeriodQueueTest {
|
||||
new MediaSourceList.MediaSourceHolder(fakeMediaSource, /* useLazyPreparation= */ false);
|
||||
mediaSourceList.setMediaSources(
|
||||
ImmutableList.of(mediaSourceHolder), new FakeShuffleOrder(/* length= */ 1));
|
||||
mediaSourceHolder.mediaSource.prepareSourceInternal(/* mediaTransferListener */ null);
|
||||
mediaSourceHolder.mediaSource.prepareSource(
|
||||
mock(MediaSourceCaller.class), /* mediaTransferListener */ null, PlayerId.UNSET);
|
||||
|
||||
Timeline playlistTimeline = mediaSourceList.createTimeline();
|
||||
firstPeriodUid = playlistTimeline.getUidOfPeriod(/* periodIndex= */ 0);
|
||||
|
@ -29,6 +29,7 @@ import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.common.Timeline;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.source.MediaSource;
|
||||
import androidx.media3.exoplayer.source.ShuffleOrder;
|
||||
import androidx.media3.test.utils.FakeMediaSource;
|
||||
@ -57,7 +58,8 @@ public class MediaSourceListTest {
|
||||
new MediaSourceList(
|
||||
mock(MediaSourceList.MediaSourceListInfoRefreshListener.class),
|
||||
/* analyticsCollector= */ null,
|
||||
Util.createHandlerForCurrentOrMainLooper());
|
||||
Util.createHandlerForCurrentOrMainLooper(),
|
||||
PlayerId.UNSET);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -95,30 +97,30 @@ public class MediaSourceListTest {
|
||||
// Verify prepare is called once on prepare.
|
||||
verify(mockMediaSource1, times(0))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
verify(mockMediaSource2, times(0))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
|
||||
mediaSourceList.prepare(/* mediaTransferListener= */ null);
|
||||
assertThat(mediaSourceList.isPrepared()).isTrue();
|
||||
// Verify prepare is called once on prepare.
|
||||
verify(mockMediaSource1, times(1))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
verify(mockMediaSource2, times(1))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
|
||||
mediaSourceList.release();
|
||||
mediaSourceList.prepare(/* mediaTransferListener= */ null);
|
||||
// Verify prepare is called a second time on re-prepare.
|
||||
verify(mockMediaSource1, times(2))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
verify(mockMediaSource2, times(2))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -185,10 +187,10 @@ public class MediaSourceListTest {
|
||||
// Verify sources are prepared.
|
||||
verify(mockMediaSource1, times(1))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
verify(mockMediaSource2, times(1))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
|
||||
// Set media items again. The second holder is re-used.
|
||||
MediaSource mockMediaSource3 = mock(MediaSource.class);
|
||||
@ -206,7 +208,7 @@ public class MediaSourceListTest {
|
||||
assertThat(mediaSources.get(1).isRemoved).isFalse();
|
||||
verify(mockMediaSource2, times(2))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -225,10 +227,10 @@ public class MediaSourceListTest {
|
||||
// Verify lazy initialization does not call prepare on sources.
|
||||
verify(mockMediaSource1, times(0))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
verify(mockMediaSource2, times(0))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
|
||||
for (int i = 0; i < mediaSources.size(); i++) {
|
||||
assertThat(mediaSources.get(i).firstWindowIndexInChild).isEqualTo(i);
|
||||
@ -262,10 +264,10 @@ public class MediaSourceListTest {
|
||||
// Verify prepare is called on sources when added.
|
||||
verify(mockMediaSource1, times(1))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
verify(mockMediaSource2, times(1))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -390,7 +392,7 @@ public class MediaSourceListTest {
|
||||
new ShuffleOrder.DefaultShuffleOrder(/* length= */ 1));
|
||||
verify(mockMediaSource, times(0))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
mediaSourceList.release();
|
||||
verify(mockMediaSource, times(0)).releaseSource(any(MediaSource.MediaSourceCaller.class));
|
||||
assertThat(mediaSourceHolder.isRemoved).isFalse();
|
||||
@ -409,7 +411,7 @@ public class MediaSourceListTest {
|
||||
new ShuffleOrder.DefaultShuffleOrder(/* length= */ 1));
|
||||
verify(mockMediaSource, times(1))
|
||||
.prepareSource(
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull());
|
||||
any(MediaSource.MediaSourceCaller.class), /* mediaTransferListener= */ isNull(), any());
|
||||
mediaSourceList.release();
|
||||
verify(mockMediaSource, times(1)).releaseSource(any(MediaSource.MediaSourceCaller.class));
|
||||
assertThat(mediaSourceHolder.isRemoved).isFalse();
|
||||
|
@ -24,6 +24,7 @@ import androidx.media3.common.C;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.media3.common.Timeline;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.source.MediaSource.MediaPeriodId;
|
||||
import androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller;
|
||||
import androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder;
|
||||
@ -644,7 +645,7 @@ public final class ConcatenatingMediaSourceTest {
|
||||
() -> {
|
||||
MediaSourceCaller caller = mock(MediaSourceCaller.class);
|
||||
mediaSource.addMediaSources(Arrays.asList(createMediaSources(2)));
|
||||
mediaSource.prepareSource(caller, /* mediaTransferListener= */ null);
|
||||
mediaSource.prepareSource(caller, /* mediaTransferListener= */ null, PlayerId.UNSET);
|
||||
mediaSource.moveMediaSource(
|
||||
/* currentIndex= */ 0,
|
||||
/* newIndex= */ 1,
|
||||
|
@ -31,6 +31,7 @@ import androidx.media3.common.C;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.Timeline;
|
||||
import androidx.media3.datasource.DataSpec;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.source.MediaPeriod;
|
||||
import androidx.media3.exoplayer.source.MediaSource.MediaPeriodId;
|
||||
import androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller;
|
||||
@ -118,7 +119,8 @@ public final class AdsMediaSourceTest {
|
||||
adMediaSourceFactory,
|
||||
mockAdsLoader,
|
||||
mockAdViewProvider);
|
||||
adsMediaSource.prepareSource(mockMediaSourceCaller, /* mediaTransferListener= */ null);
|
||||
adsMediaSource.prepareSource(
|
||||
mockMediaSourceCaller, /* mediaTransferListener= */ null, PlayerId.UNSET);
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
verify(mockAdsLoader)
|
||||
.start(
|
||||
|
@ -39,6 +39,7 @@ import androidx.media3.common.Player;
|
||||
import androidx.media3.common.Timeline;
|
||||
import androidx.media3.exoplayer.ExoPlayer;
|
||||
import androidx.media3.exoplayer.analytics.AnalyticsListener;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory;
|
||||
import androidx.media3.test.utils.CapturingRenderersFactory;
|
||||
import androidx.media3.test.utils.DumpFileAsserts;
|
||||
@ -105,7 +106,9 @@ public final class ServerSideInsertedAdMediaSourceTest {
|
||||
|
||||
mediaSource.setAdPlaybackState(adPlaybackState);
|
||||
mediaSource.prepareSource(
|
||||
(source, timeline) -> timelineReference.set(timeline), /* mediaTransferListener= */ null);
|
||||
(source, timeline) -> timelineReference.set(timeline),
|
||||
/* mediaTransferListener= */ null,
|
||||
PlayerId.UNSET);
|
||||
runMainLooperUntil(() -> timelineReference.get() != null);
|
||||
|
||||
Timeline timeline = timelineReference.get();
|
||||
|
@ -30,6 +30,7 @@ import androidx.media3.common.util.Util;
|
||||
import androidx.media3.datasource.ByteArrayDataSource;
|
||||
import androidx.media3.datasource.DataSource;
|
||||
import androidx.media3.datasource.FileDataSource;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.source.MediaSource;
|
||||
import androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller;
|
||||
import androidx.media3.exoplayer.upstream.ParsingLoadable;
|
||||
@ -484,7 +485,7 @@ public final class DashMediaSourceTest {
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
};
|
||||
mediaSource.prepareSource(caller, /* mediaTransferListener= */ null);
|
||||
mediaSource.prepareSource(caller, /* mediaTransferListener= */ null, PlayerId.UNSET);
|
||||
while (!countDownLatch.await(/* timeout= */ 10, MILLISECONDS)) {
|
||||
ShadowLooper.idleMainLooper();
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import androidx.media3.common.StreamKey;
|
||||
import androidx.media3.common.Timeline;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.datasource.DataSource;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.hls.playlist.HlsMediaPlaylist;
|
||||
import androidx.media3.exoplayer.hls.playlist.HlsPlaylistParser;
|
||||
import androidx.media3.exoplayer.source.MediaSource;
|
||||
@ -752,7 +753,7 @@ public class HlsMediaSourceTest {
|
||||
List<Timeline> timelines = new ArrayList<>();
|
||||
MediaSource.MediaSourceCaller mediaSourceCaller = (source, timeline) -> timelines.add(timeline);
|
||||
|
||||
mediaSource.prepareSource(mediaSourceCaller, null);
|
||||
mediaSource.prepareSource(mediaSourceCaller, /* mediaTransferListener= */ null, PlayerId.UNSET);
|
||||
runMainLooperUntil(() -> timelines.size() == 1);
|
||||
mediaSource.onPrimaryPlaylistRefreshed(secondPlaylist);
|
||||
runMainLooperUntil(() -> timelines.size() == 2);
|
||||
@ -785,7 +786,9 @@ public class HlsMediaSourceTest {
|
||||
throws TimeoutException {
|
||||
AtomicReference<Timeline> receivedTimeline = new AtomicReference<>();
|
||||
mediaSource.prepareSource(
|
||||
(source, timeline) -> receivedTimeline.set(timeline), /* mediaTransferListener= */ null);
|
||||
(source, timeline) -> receivedTimeline.set(timeline),
|
||||
/* mediaTransferListener= */ null,
|
||||
PlayerId.UNSET);
|
||||
runMainLooperUntil(() -> receivedTimeline.get() != null);
|
||||
return receivedTimeline.get();
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import androidx.media3.common.Timeline;
|
||||
import androidx.media3.common.util.Assertions;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.source.LoadEventInfo;
|
||||
import androidx.media3.exoplayer.source.MediaLoadData;
|
||||
import androidx.media3.exoplayer.source.MediaPeriod;
|
||||
@ -117,7 +118,8 @@ public class MediaSourceTestRunner {
|
||||
final IOException[] prepareError = new IOException[1];
|
||||
runOnPlaybackThread(
|
||||
() -> {
|
||||
mediaSource.prepareSource(mediaSourceListener, /* mediaTransferListener= */ null);
|
||||
mediaSource.prepareSource(
|
||||
mediaSourceListener, /* mediaTransferListener= */ null, PlayerId.UNSET);
|
||||
try {
|
||||
// TODO: This only catches errors that are set synchronously in prepareSource. To
|
||||
// capture async errors we'll need to poll maybeThrowSourceInfoRefreshError until the
|
||||
|
@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.common.Timeline.Window;
|
||||
import androidx.media3.exoplayer.analytics.PlayerId;
|
||||
import androidx.media3.exoplayer.source.MediaSource;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@ -42,7 +43,8 @@ public class FakeMediaSourceFactoryTest {
|
||||
int firstWindowIndex = timeline.getFirstWindowIndex(/* shuffleModeEnabled= */ false);
|
||||
reportedMediaItem.set(timeline.getWindow(firstWindowIndex, new Window()).mediaItem);
|
||||
},
|
||||
/* mediaTransferListener= */ null);
|
||||
/* mediaTransferListener= */ null,
|
||||
PlayerId.UNSET);
|
||||
|
||||
assertThat(reportedMediaItem.get()).isSameInstanceAs(mediaItem);
|
||||
assertThat(mediaSource.getMediaItem()).isSameInstanceAs(mediaItem);
|
||||
|
Loading…
x
Reference in New Issue
Block a user