mirror of
https://github.com/samsonjs/media.git
synced 2026-03-25 09:25:53 +00:00
Add setPlayerId(PlayerId) and prepareSourceCalled to BaseMediaSource
Also add getLastCreatedSource to FakeMediaSourceFactory which will be helpful in testing. PiperOrigin-RevId: 563463475
This commit is contained in:
parent
4c792ac907
commit
2ab5841ac2
2 changed files with 35 additions and 2 deletions
|
|
@ -179,12 +179,29 @@ public abstract class BaseMediaSource implements MediaSource {
|
|||
* 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}.
|
||||
* prepared} or has {@linkplain #setPlayerId a player ID set}.
|
||||
*/
|
||||
protected final PlayerId getPlayerId() {
|
||||
return checkStateNotNull(playerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link PlayerId} of the player using this media source.
|
||||
*
|
||||
* @param playerId The player ID to be set.
|
||||
*/
|
||||
protected final void setPlayerId(PlayerId playerId) {
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the source has {@link MediaSource#prepareSource(MediaSourceCaller,
|
||||
* TransferListener, PlayerId)} called.
|
||||
*/
|
||||
protected final boolean prepareSourceCalled() {
|
||||
return !mediaSourceCallers.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void addEventListener(Handler handler, MediaSourceEventListener eventListener) {
|
||||
Assertions.checkNotNull(handler);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@
|
|||
*/
|
||||
package androidx.media3.test.utils;
|
||||
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
|
||||
import androidx.media3.common.AdPlaybackState;
|
||||
import androidx.media3.common.C;
|
||||
import androidx.media3.common.MediaItem;
|
||||
|
|
@ -26,6 +28,7 @@ import androidx.media3.exoplayer.source.MediaSourceFactory;
|
|||
import androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy;
|
||||
import androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
|
||||
/** Fake {@link MediaSourceFactory} that creates a {@link FakeMediaSource}. */
|
||||
@UnstableApi
|
||||
|
|
@ -36,6 +39,18 @@ public final class FakeMediaSourceFactory implements MediaSourceFactory {
|
|||
/** The window UID used by media sources that are created by the factory. */
|
||||
public static final Object DEFAULT_WINDOW_UID = new Object();
|
||||
|
||||
private @MonotonicNonNull FakeMediaSource lastCreatedSource;
|
||||
|
||||
/**
|
||||
* Returns the last created {@link FakeMediaSource}.
|
||||
*
|
||||
* <p>Must be called after at least one {@link FakeMediaSource} is {@link
|
||||
* FakeMediaSourceFactory#createMediaSource(MediaItem) created}.
|
||||
*/
|
||||
public FakeMediaSource getLastCreatedSource() {
|
||||
return checkNotNull(lastCreatedSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaSourceFactory setDrmSessionManagerProvider(
|
||||
DrmSessionManagerProvider drmSessionManagerProvider) {
|
||||
|
|
@ -68,6 +83,7 @@ public final class FakeMediaSourceFactory implements MediaSourceFactory {
|
|||
/* windowOffsetInFirstPeriodUs= */ Util.msToUs(123456789),
|
||||
ImmutableList.of(AdPlaybackState.NONE),
|
||||
mediaItem);
|
||||
return new FakeMediaSource(new FakeTimeline(timelineWindowDefinition));
|
||||
lastCreatedSource = new FakeMediaSource(new FakeTimeline(timelineWindowDefinition));
|
||||
return lastCreatedSource;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue