Commit a9913e54 by bachinger

Add the media item to PositionInfo

PiperOrigin-RevId: 392914515
parent e5a39eca
......@@ -790,6 +790,7 @@ public final class CastPlayer extends BasePlayer {
new PositionInfo(
window.uid,
period.windowIndex,
window.mediaItem,
period.uid,
period.windowIndex,
/* positionMs= */ windowDurationMs,
......@@ -802,6 +803,7 @@ public final class CastPlayer extends BasePlayer {
new PositionInfo(
window.uid,
period.windowIndex,
window.mediaItem,
period.uid,
period.windowIndex,
/* positionMs= */ window.getDefaultPositionMs(),
......@@ -904,6 +906,7 @@ public final class CastPlayer extends BasePlayer {
new PositionInfo(
window.uid,
period.windowIndex,
window.mediaItem,
period.uid,
period.windowIndex,
getCurrentPosition(),
......@@ -1082,17 +1085,19 @@ public final class CastPlayer extends BasePlayer {
private PositionInfo getCurrentPositionInfo() {
Timeline currentTimeline = getCurrentTimeline();
@Nullable
Object newPeriodUid =
!currentTimeline.isEmpty()
? currentTimeline.getPeriod(getCurrentPeriodIndex(), period, /* setIds= */ true).uid
: null;
@Nullable
Object newWindowUid =
newPeriodUid != null ? currentTimeline.getWindow(period.windowIndex, window).uid : null;
@Nullable Object newPeriodUid = null;
@Nullable Object newWindowUid = null;
@Nullable MediaItem newMediaItem = null;
if (!currentTimeline.isEmpty()) {
newPeriodUid =
currentTimeline.getPeriod(getCurrentPeriodIndex(), period, /* setIds= */ true).uid;
newWindowUid = currentTimeline.getWindow(period.windowIndex, window).uid;
newMediaItem = window.mediaItem;
}
return new PositionInfo(
newWindowUid,
getCurrentWindowIndex(),
newMediaItem,
newPeriodUid,
getCurrentPeriodIndex(),
getCurrentPosition(),
......
......@@ -380,6 +380,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 2,
/* windowIndex= */ 1,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(2).build(),
/* periodUid= */ 2,
/* periodIndex= */ 1,
/* positionMs= */ 2000,
......@@ -390,6 +391,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 3,
/* windowIndex= */ 0,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(3).build(),
/* periodUid= */ 3,
/* periodIndex= */ 0,
/* positionMs= */ 1000,
......@@ -660,6 +662,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build(),
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ 1234,
......@@ -670,6 +673,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ null,
/* windowIndex= */ 0,
/* mediaItem= */ null,
/* periodUid= */ null,
/* periodIndex= */ 0,
/* positionMs= */ 0,
......@@ -744,6 +748,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build(),
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ 1234,
......@@ -754,6 +759,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 2,
/* windowIndex= */ 0,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(2).build(),
/* periodUid= */ 2,
/* periodIndex= */ 0,
/* positionMs= */ 0,
......@@ -825,6 +831,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build(),
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ 0, // position at which we receive the timeline change
......@@ -835,6 +842,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 2,
/* windowIndex= */ 0,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(2).build(),
/* periodUid= */ 2,
/* periodIndex= */ 0,
/* positionMs= */ 0,
......@@ -937,6 +945,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build(),
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ 0,
......@@ -947,6 +956,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 2,
/* windowIndex= */ 1,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(2).build(),
/* periodUid= */ 2,
/* periodIndex= */ 1,
/* positionMs= */ 1234,
......@@ -992,10 +1002,12 @@ public class CastPlayerTest {
updateTimeLine(mediaItems, mediaQueueItemIds, /* currentItemId= */ 1);
castPlayer.seekTo(/* windowIndex= */ 0, /* positionMs= */ 1234);
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build();
Player.PositionInfo oldPosition =
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
mediaItem,
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ 0,
......@@ -1006,6 +1018,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
mediaItem,
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ 1234,
......@@ -1076,6 +1089,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build(),
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ 12500,
......@@ -1086,6 +1100,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 2,
/* windowIndex= */ 1,
new MediaItem.Builder().setUri(Uri.EMPTY).setTag(2).build(),
/* periodUid= */ 2,
/* periodIndex= */ 1,
/* positionMs= */ 0,
......@@ -1120,10 +1135,12 @@ public class CastPlayerTest {
mediaItems, mediaQueueItemIds, currentItemId, streamTypes, durationsMs, positionMs);
castPlayer.seekBack();
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build();
Player.PositionInfo oldPosition =
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
mediaItem,
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ 2 * C.DEFAULT_SEEK_BACK_INCREMENT_MS,
......@@ -1134,6 +1151,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
mediaItem,
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ C.DEFAULT_SEEK_BACK_INCREMENT_MS,
......@@ -1166,10 +1184,12 @@ public class CastPlayerTest {
mediaItems, mediaQueueItemIds, currentItemId, streamTypes, durationsMs, positionMs);
castPlayer.seekForward();
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setTag(1).build();
Player.PositionInfo oldPosition =
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
mediaItem,
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ 0,
......@@ -1180,6 +1200,7 @@ public class CastPlayerTest {
new Player.PositionInfo(
/* windowUid= */ 1,
/* windowIndex= */ 0,
mediaItem,
/* periodUid= */ 1,
/* periodIndex= */ 0,
/* positionMs= */ C.DEFAULT_SEEK_FORWARD_INCREMENT_MS,
......
......@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.ext.ima;
import android.os.Looper;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.testutil.StubExoPlayer;
......@@ -32,6 +33,7 @@ import com.google.android.exoplayer2.util.ListenerSet;
private final Timeline.Period period;
private final Object windowUid = new Object();
private final Object periodUid = new Object();
private final MediaItem mediaItem = MediaItem.fromUri("http://google.com/0");
private Timeline timeline;
@Player.State private int state;
......@@ -72,6 +74,7 @@ import com.google.android.exoplayer2.util.ListenerSet;
new PositionInfo(
windowUid,
/* windowIndex= */ 0,
mediaItem,
periodUid,
/* periodIndex= */ 0,
this.positionMs,
......@@ -89,6 +92,7 @@ import com.google.android.exoplayer2.util.ListenerSet;
new PositionInfo(
windowUid,
/* windowIndex= */ 0,
mediaItem,
periodUid,
/* periodIndex= */ 0,
positionMs,
......@@ -119,6 +123,7 @@ import com.google.android.exoplayer2.util.ListenerSet;
new PositionInfo(
windowUid,
/* windowIndex= */ 0,
mediaItem,
periodUid,
/* periodIndex= */ 0,
this.positionMs,
......@@ -136,6 +141,7 @@ import com.google.android.exoplayer2.util.ListenerSet;
new PositionInfo(
windowUid,
/* windowIndex= */ 0,
mediaItem,
periodUid,
/* periodIndex= */ 0,
positionMs,
......
......@@ -56,6 +56,7 @@ import com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer;
import com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
......@@ -281,6 +282,7 @@ public final class ImaAdsLoaderTest {
new Player.PositionInfo(
/* windowUid= */ new Object(),
/* windowIndex= */ 0,
/* mediaItem= */ MediaItem.fromUri("http://google.com/0"),
/* periodUid= */ new Object(),
/* periodIndex= */ 0,
/* positionMs= */ 10_000,
......@@ -290,6 +292,7 @@ public final class ImaAdsLoaderTest {
new Player.PositionInfo(
/* windowUid= */ new Object(),
/* windowIndex= */ 1,
/* mediaItem= */ MediaItem.fromUri("http://google.com/1"),
/* periodUid= */ new Object(),
/* periodIndex= */ 0,
/* positionMs= */ 20_000,
......
......@@ -32,6 +32,7 @@ import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
import com.google.android.exoplayer2.util.BundleableUtils;
import com.google.android.exoplayer2.util.FlagSet;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoSize;
......@@ -468,13 +469,15 @@ public interface Player {
final class PositionInfo implements Bundleable {
/**
* The UID of the window, or {@code null}, if the timeline is {@link Timeline#isEmpty() empty}.
* The UID of the window, or {@code null} if the timeline is {@link Timeline#isEmpty() empty}.
*/
@Nullable public final Object windowUid;
/** The window index. */
public final int windowIndex;
/** The media item, or {@code null} if the timeline is {@link Timeline#isEmpty() empty}. */
@Nullable public final MediaItem mediaItem;
/**
* The UID of the period, or {@code null}, if the timeline is {@link Timeline#isEmpty() empty}.
* The UID of the period, or {@code null} if the timeline is {@link Timeline#isEmpty() empty}.
*/
@Nullable public final Object periodUid;
/** The period index. */
......@@ -498,10 +501,37 @@ public interface Player {
*/
public final int adIndexInAdGroup;
/**
* @deprecated Use {@link #PositionInfo(Object, int, MediaItem, Object, int, long, long, int,
* int)} instead.
*/
@Deprecated
public PositionInfo(
@Nullable Object windowUid,
int windowIndex,
@Nullable Object periodUid,
int periodIndex,
long positionMs,
long contentPositionMs,
int adGroupIndex,
int adIndexInAdGroup) {
this(
windowUid,
windowIndex,
MediaItem.EMPTY,
periodUid,
periodIndex,
positionMs,
contentPositionMs,
adGroupIndex,
adIndexInAdGroup);
}
/** Creates an instance. */
public PositionInfo(
@Nullable Object windowUid,
int windowIndex,
@Nullable MediaItem mediaItem,
@Nullable Object periodUid,
int periodIndex,
long positionMs,
......@@ -510,6 +540,7 @@ public interface Player {
int adIndexInAdGroup) {
this.windowUid = windowUid;
this.windowIndex = windowIndex;
this.mediaItem = mediaItem;
this.periodUid = periodUid;
this.periodIndex = periodIndex;
this.positionMs = positionMs;
......@@ -534,7 +565,8 @@ public interface Player {
&& adGroupIndex == that.adGroupIndex
&& adIndexInAdGroup == that.adIndexInAdGroup
&& Objects.equal(windowUid, that.windowUid)
&& Objects.equal(periodUid, that.periodUid);
&& Objects.equal(periodUid, that.periodUid)
&& Objects.equal(mediaItem, that.mediaItem);
}
@Override
......@@ -542,6 +574,7 @@ public interface Player {
return Objects.hashCode(
windowUid,
windowIndex,
mediaItem,
periodUid,
periodIndex,
windowIndex,
......@@ -556,6 +589,7 @@ public interface Player {
@Retention(RetentionPolicy.SOURCE)
@IntDef({
FIELD_WINDOW_INDEX,
FIELD_MEDIA_ITEM,
FIELD_PERIOD_INDEX,
FIELD_POSITION_MS,
FIELD_CONTENT_POSITION_MS,
......@@ -565,11 +599,12 @@ public interface Player {
private @interface FieldNumber {}
private static final int FIELD_WINDOW_INDEX = 0;
private static final int FIELD_PERIOD_INDEX = 1;
private static final int FIELD_POSITION_MS = 2;
private static final int FIELD_CONTENT_POSITION_MS = 3;
private static final int FIELD_AD_GROUP_INDEX = 4;
private static final int FIELD_AD_INDEX_IN_AD_GROUP = 5;
private static final int FIELD_MEDIA_ITEM = 1;
private static final int FIELD_PERIOD_INDEX = 2;
private static final int FIELD_POSITION_MS = 3;
private static final int FIELD_CONTENT_POSITION_MS = 4;
private static final int FIELD_AD_GROUP_INDEX = 5;
private static final int FIELD_AD_INDEX_IN_AD_GROUP = 6;
/**
* {@inheritDoc}
......@@ -581,6 +616,7 @@ public interface Player {
public Bundle toBundle() {
Bundle bundle = new Bundle();
bundle.putInt(keyForField(FIELD_WINDOW_INDEX), windowIndex);
bundle.putBundle(keyForField(FIELD_MEDIA_ITEM), BundleableUtils.toNullableBundle(mediaItem));
bundle.putInt(keyForField(FIELD_PERIOD_INDEX), periodIndex);
bundle.putLong(keyForField(FIELD_POSITION_MS), positionMs);
bundle.putLong(keyForField(FIELD_CONTENT_POSITION_MS), contentPositionMs);
......@@ -595,6 +631,10 @@ public interface Player {
private static PositionInfo fromBundle(Bundle bundle) {
int windowIndex =
bundle.getInt(keyForField(FIELD_WINDOW_INDEX), /* defaultValue= */ C.INDEX_UNSET);
@Nullable
MediaItem mediaItem =
BundleableUtils.fromNullableBundle(
MediaItem.CREATOR, bundle.getBundle(keyForField(FIELD_MEDIA_ITEM)));
int periodIndex =
bundle.getInt(keyForField(FIELD_PERIOD_INDEX), /* defaultValue= */ C.INDEX_UNSET);
long positionMs =
......@@ -608,6 +648,7 @@ public interface Player {
return new PositionInfo(
/* windowUid= */ null,
windowIndex,
mediaItem,
/* periodUid= */ null,
periodIndex,
positionMs,
......
......@@ -32,6 +32,7 @@ public class PositionInfoTest {
new PositionInfo(
/* windowUid= */ null,
/* windowIndex= */ 23,
new MediaItem.Builder().setMediaId("1234").build(),
/* periodUid= */ null,
/* periodIndex= */ 11,
/* positionMs= */ 8787L,
......@@ -48,6 +49,7 @@ public class PositionInfoTest {
new PositionInfo(
/* windowUid= */ new Object(),
/* windowIndex= */ 23,
MediaItem.fromUri("https://exoplayer.dev"),
/* periodUid= */ null,
/* periodIndex= */ 11,
/* positionMs= */ 8787L,
......@@ -65,6 +67,7 @@ public class PositionInfoTest {
new PositionInfo(
/* windowUid= */ null,
/* windowIndex= */ 23,
MediaItem.fromUri("https://exoplayer.dev"),
/* periodUid= */ new Object(),
/* periodIndex= */ 11,
/* positionMs= */ 8787L,
......
......@@ -1360,6 +1360,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
@Nullable Object oldPeriodUid = null;
int oldWindowIndex = oldMaskingWindowIndex;
int oldPeriodIndex = C.INDEX_UNSET;
@Nullable MediaItem oldMediaItem = null;
Timeline.Period oldPeriod = new Timeline.Period();
if (!oldPlaybackInfo.timeline.isEmpty()) {
oldPeriodUid = oldPlaybackInfo.periodId.periodUid;
......@@ -1367,6 +1368,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
oldWindowIndex = oldPeriod.windowIndex;
oldPeriodIndex = oldPlaybackInfo.timeline.getIndexOfPeriod(oldPeriodUid);
oldWindowUid = oldPlaybackInfo.timeline.getWindow(oldWindowIndex, window).uid;
oldMediaItem = window.mediaItem;
}
long oldPositionUs;
long oldContentPositionUs;
......@@ -1397,6 +1399,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
return new PositionInfo(
oldWindowUid,
oldWindowIndex,
oldMediaItem,
oldPeriodUid,
oldPeriodIndex,
C.usToMs(oldPositionUs),
......@@ -1410,16 +1413,19 @@ import java.util.concurrent.CopyOnWriteArraySet;
@Nullable Object newPeriodUid = null;
int newWindowIndex = getCurrentWindowIndex();
int newPeriodIndex = C.INDEX_UNSET;
@Nullable MediaItem newMediaItem = null;
if (!playbackInfo.timeline.isEmpty()) {
newPeriodUid = playbackInfo.periodId.periodUid;
playbackInfo.timeline.getPeriodByUid(newPeriodUid, period);
newPeriodIndex = playbackInfo.timeline.getIndexOfPeriod(newPeriodUid);
newWindowUid = playbackInfo.timeline.getWindow(newWindowIndex, window).uid;
newMediaItem = window.mediaItem;
}
long positionMs = C.usToMs(discontinuityWindowStartPositionUs);
return new PositionInfo(
newWindowUid,
newWindowIndex,
newMediaItem,
newPeriodUid,
newPeriodIndex,
positionMs,
......
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.testutil;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.drm.DrmSessionManagerProvider;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ads.AdPlaybackState;
import com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
/** Fake {@link MediaSourceFactory} that creates a {@link FakeMediaSource}. */
public 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();
@Override
public MediaSourceFactory setDrmSessionManagerProvider(
@Nullable DrmSessionManagerProvider drmSessionManagerProvider) {
throw new UnsupportedOperationException();
}
@Deprecated
@Override
public MediaSourceFactory setDrmSessionManager(@Nullable DrmSessionManager drmSessionManager) {
throw new UnsupportedOperationException();
}
@Deprecated
@Override
public MediaSourceFactory setDrmHttpDataSourceFactory(
@Nullable HttpDataSource.Factory drmHttpDataSourceFactory) {
throw new UnsupportedOperationException();
}
@Deprecated
@Override
public MediaSourceFactory setDrmUserAgent(@Nullable String userAgent) {
throw new UnsupportedOperationException();
}
@Override
public MediaSourceFactory setLoadErrorHandlingPolicy(
@Nullable LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
throw new UnsupportedOperationException();
}
@Override
public int[] getSupportedTypes() {
return new int[] {C.TYPE_OTHER};
}
@Override
public MediaSource createMediaSource(MediaItem mediaItem) {
TimelineWindowDefinition timelineWindowDefinition =
new TimelineWindowDefinition(
/* periodCount= */ 1,
/* id= */ DEFAULT_WINDOW_UID,
/* isSeekable= */ true,
/* isDynamic= */ false,
/* isLive= */ false,
/* isPlaceholder= */ false,
/* durationUs= */ 1000 * C.MICROS_PER_SECOND,
/* defaultPositionUs= */ 2 * C.MICROS_PER_SECOND,
/* windowOffsetInFirstPeriodUs= */ C.msToUs(123456789),
AdPlaybackState.NONE,
mediaItem);
return new FakeMediaSource(new FakeTimeline(timelineWindowDefinition));
}
}
......@@ -28,6 +28,7 @@ import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
......@@ -45,6 +46,7 @@ public class TestExoPlayerBuilder {
private BandwidthMeter bandwidthMeter;
@Nullable private Renderer[] renderers;
@Nullable private RenderersFactory renderersFactory;
@Nullable private MediaSourceFactory mediaSourceFactory;
private boolean useLazyPreparation;
private @MonotonicNonNull Looper looper;
private long seekBackIncrementMs;
......@@ -220,6 +222,26 @@ public class TestExoPlayerBuilder {
}
/**
* Returns the {@link MediaSourceFactory} that will be used by the player, or null if no {@link
* MediaSourceFactory} has been set yet and no default is available.
*/
@Nullable
public MediaSourceFactory getMediaSourceFactory() {
return mediaSourceFactory;
}
/**
* Sets the {@link MediaSourceFactory} to be used by the player.
*
* @param mediaSourceFactory The {@link MediaSourceFactory} to be used by the player.
* @return This builder.
*/
public TestExoPlayerBuilder setMediaSourceFactory(MediaSourceFactory mediaSourceFactory) {
this.mediaSourceFactory = mediaSourceFactory;
return this;
}
/**
* Sets the seek back increment to be used by the player.
*
* @param seekBackIncrementMs The seek back increment to be used by the player.
......@@ -277,16 +299,20 @@ public class TestExoPlayerBuilder {
};
}
return new ExoPlayer.Builder(context, playerRenderersFactory)
.setTrackSelector(trackSelector)
.setLoadControl(loadControl)
.setBandwidthMeter(bandwidthMeter)
.setAnalyticsCollector(new AnalyticsCollector(clock))
.setClock(clock)
.setUseLazyPreparation(useLazyPreparation)
.setLooper(looper)
.setSeekBackIncrementMs(seekBackIncrementMs)
.setSeekForwardIncrementMs(seekForwardIncrementMs)
.build();
ExoPlayer.Builder builder =
new ExoPlayer.Builder(context, playerRenderersFactory)
.setTrackSelector(trackSelector)
.setLoadControl(loadControl)
.setBandwidthMeter(bandwidthMeter)
.setAnalyticsCollector(new AnalyticsCollector(clock))
.setClock(clock)
.setUseLazyPreparation(useLazyPreparation)
.setLooper(looper)
.setSeekBackIncrementMs(seekBackIncrementMs)
.setSeekForwardIncrementMs(seekForwardIncrementMs);
if (mediaSourceFactory != null) {
builder.setMediaSourceFactory(mediaSourceFactory);
}
return builder.build();
}
}
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.testutil;
import static com.google.common.truth.Truth.assertThat;
import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.Timeline.Window;
import com.google.android.exoplayer2.source.MediaSource;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.junit.runner.RunWith;
/** Unit test for {@link FakeMediaSourceFactory}. */
@RunWith(AndroidJUnit4.class)
public class FakeMediaSourceFactoryTest {
@Test
public void createMediaSource_mediaItemIsSameInstance() {
FakeMediaSourceFactory fakeMediaSourceFactory = new FakeMediaSourceFactory();
MediaItem mediaItem = MediaItem.fromUri("http://google.com/0");
@Nullable AtomicReference<MediaItem> reportedMediaItem = new AtomicReference<>();
MediaSource mediaSource = fakeMediaSourceFactory.createMediaSource(mediaItem);
mediaSource.prepareSource(
(source, timeline) -> {
int firstWindowIndex = timeline.getFirstWindowIndex(/* shuffleModeEnabled= */ false);
reportedMediaItem.set(timeline.getWindow(firstWindowIndex, new Window()).mediaItem);
},
/* mediaTransferListener= */ null);
assertThat(reportedMediaItem.get()).isSameInstanceAs(mediaItem);
assertThat(mediaSource.getMediaItem()).isSameInstanceAs(mediaItem);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment