Make SsMediaSource add the media item to the timeline
PiperOrigin-RevId: 313573424
This commit is contained in:
parent
a37374d5a7
commit
a3b721e680
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.source.smoothstreaming;
|
package com.google.android.exoplayer2.source.smoothstreaming;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
@ -54,6 +56,7 @@ import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
|
|||||||
import com.google.android.exoplayer2.upstream.ParsingLoadable;
|
import com.google.android.exoplayer2.upstream.ParsingLoadable;
|
||||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
|
import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -104,7 +107,7 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
public Factory(
|
public Factory(
|
||||||
SsChunkSource.Factory chunkSourceFactory,
|
SsChunkSource.Factory chunkSourceFactory,
|
||||||
@Nullable DataSource.Factory manifestDataSourceFactory) {
|
@Nullable DataSource.Factory manifestDataSourceFactory) {
|
||||||
this.chunkSourceFactory = Assertions.checkNotNull(chunkSourceFactory);
|
this.chunkSourceFactory = checkNotNull(chunkSourceFactory);
|
||||||
this.manifestDataSourceFactory = manifestDataSourceFactory;
|
this.manifestDataSourceFactory = manifestDataSourceFactory;
|
||||||
drmSessionManager = DrmSessionManager.getDummyDrmSessionManager();
|
drmSessionManager = DrmSessionManager.getDummyDrmSessionManager();
|
||||||
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
|
loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
|
||||||
@ -237,21 +240,47 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
* @throws IllegalArgumentException If {@link SsManifest#isLive} is true.
|
* @throws IllegalArgumentException If {@link SsManifest#isLive} is true.
|
||||||
*/
|
*/
|
||||||
public SsMediaSource createMediaSource(SsManifest manifest) {
|
public SsMediaSource createMediaSource(SsManifest manifest) {
|
||||||
|
return createMediaSource(manifest, MediaItem.fromUri(Uri.EMPTY));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new {@link SsMediaSource} using the current parameters and the specified sideloaded
|
||||||
|
* manifest.
|
||||||
|
*
|
||||||
|
* @param manifest The manifest. {@link SsManifest#isLive} must be false.
|
||||||
|
* @param mediaItem The {@link MediaItem} to be included in the timeline.
|
||||||
|
* @return The new {@link SsMediaSource}.
|
||||||
|
* @throws IllegalArgumentException If {@link SsManifest#isLive} is true.
|
||||||
|
*/
|
||||||
|
public SsMediaSource createMediaSource(SsManifest manifest, MediaItem mediaItem) {
|
||||||
Assertions.checkArgument(!manifest.isLive);
|
Assertions.checkArgument(!manifest.isLive);
|
||||||
|
List<StreamKey> streamKeys =
|
||||||
|
mediaItem.playbackProperties != null && !mediaItem.playbackProperties.streamKeys.isEmpty()
|
||||||
|
? mediaItem.playbackProperties.streamKeys
|
||||||
|
: this.streamKeys;
|
||||||
if (!streamKeys.isEmpty()) {
|
if (!streamKeys.isEmpty()) {
|
||||||
manifest = manifest.copy(streamKeys);
|
manifest = manifest.copy(streamKeys);
|
||||||
}
|
}
|
||||||
|
boolean hasUri = mediaItem.playbackProperties != null;
|
||||||
|
boolean hasTag = hasUri && mediaItem.playbackProperties.tag != null;
|
||||||
|
mediaItem =
|
||||||
|
mediaItem
|
||||||
|
.buildUpon()
|
||||||
|
.setMimeType(MimeTypes.APPLICATION_SS)
|
||||||
|
.setUri(hasUri ? mediaItem.playbackProperties.uri : Uri.EMPTY)
|
||||||
|
.setTag(hasTag ? mediaItem.playbackProperties.tag : tag)
|
||||||
|
.setStreamKeys(streamKeys)
|
||||||
|
.build();
|
||||||
return new SsMediaSource(
|
return new SsMediaSource(
|
||||||
|
mediaItem,
|
||||||
manifest,
|
manifest,
|
||||||
/* manifestUri= */ null,
|
|
||||||
/* manifestDataSourceFactory= */ null,
|
/* manifestDataSourceFactory= */ null,
|
||||||
/* manifestParser= */ null,
|
/* manifestParser= */ null,
|
||||||
chunkSourceFactory,
|
chunkSourceFactory,
|
||||||
compositeSequenceableLoaderFactory,
|
compositeSequenceableLoaderFactory,
|
||||||
drmSessionManager,
|
drmSessionManager,
|
||||||
loadErrorHandlingPolicy,
|
loadErrorHandlingPolicy,
|
||||||
livePresentationDelayMs,
|
livePresentationDelayMs);
|
||||||
tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -274,6 +303,7 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
* @deprecated Use {@link #createMediaSource(Uri)} and {@link #addEventListener(Handler,
|
* @deprecated Use {@link #createMediaSource(Uri)} and {@link #addEventListener(Handler,
|
||||||
* MediaSourceEventListener)} instead.
|
* MediaSourceEventListener)} instead.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public SsMediaSource createMediaSource(
|
public SsMediaSource createMediaSource(
|
||||||
Uri manifestUri,
|
Uri manifestUri,
|
||||||
@ -295,7 +325,7 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SsMediaSource createMediaSource(MediaItem mediaItem) {
|
public SsMediaSource createMediaSource(MediaItem mediaItem) {
|
||||||
Assertions.checkNotNull(mediaItem.playbackProperties);
|
checkNotNull(mediaItem.playbackProperties);
|
||||||
@Nullable ParsingLoadable.Parser<? extends SsManifest> manifestParser = this.manifestParser;
|
@Nullable ParsingLoadable.Parser<? extends SsManifest> manifestParser = this.manifestParser;
|
||||||
if (manifestParser == null) {
|
if (manifestParser == null) {
|
||||||
manifestParser = new SsManifestParser();
|
manifestParser = new SsManifestParser();
|
||||||
@ -307,17 +337,27 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
if (!streamKeys.isEmpty()) {
|
if (!streamKeys.isEmpty()) {
|
||||||
manifestParser = new FilteringManifestParser<>(manifestParser, streamKeys);
|
manifestParser = new FilteringManifestParser<>(manifestParser, streamKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean needsTag = mediaItem.playbackProperties.tag == null && tag != null;
|
||||||
|
boolean needsStreamKeys =
|
||||||
|
mediaItem.playbackProperties.streamKeys.isEmpty() && !streamKeys.isEmpty();
|
||||||
|
if (needsTag && needsStreamKeys) {
|
||||||
|
mediaItem = mediaItem.buildUpon().setTag(tag).setStreamKeys(streamKeys).build();
|
||||||
|
} else if (needsTag) {
|
||||||
|
mediaItem = mediaItem.buildUpon().setTag(tag).build();
|
||||||
|
} else if (needsStreamKeys) {
|
||||||
|
mediaItem = mediaItem.buildUpon().setStreamKeys(streamKeys).build();
|
||||||
|
}
|
||||||
return new SsMediaSource(
|
return new SsMediaSource(
|
||||||
|
mediaItem,
|
||||||
/* manifest= */ null,
|
/* manifest= */ null,
|
||||||
mediaItem.playbackProperties.uri,
|
|
||||||
manifestDataSourceFactory,
|
manifestDataSourceFactory,
|
||||||
manifestParser,
|
manifestParser,
|
||||||
chunkSourceFactory,
|
chunkSourceFactory,
|
||||||
compositeSequenceableLoaderFactory,
|
compositeSequenceableLoaderFactory,
|
||||||
drmSessionManager,
|
drmSessionManager,
|
||||||
loadErrorHandlingPolicy,
|
loadErrorHandlingPolicy,
|
||||||
livePresentationDelayMs,
|
livePresentationDelayMs);
|
||||||
mediaItem.playbackProperties.tag != null ? mediaItem.playbackProperties.tag : tag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -343,6 +383,8 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
|
|
||||||
private final boolean sideloadedManifest;
|
private final boolean sideloadedManifest;
|
||||||
private final Uri manifestUri;
|
private final Uri manifestUri;
|
||||||
|
private final MediaItem.PlaybackProperties playbackProperties;
|
||||||
|
private final MediaItem mediaItem;
|
||||||
private final DataSource.Factory manifestDataSourceFactory;
|
private final DataSource.Factory manifestDataSourceFactory;
|
||||||
private final SsChunkSource.Factory chunkSourceFactory;
|
private final SsChunkSource.Factory chunkSourceFactory;
|
||||||
private final CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
private final CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
||||||
@ -352,7 +394,6 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
private final EventDispatcher manifestEventDispatcher;
|
private final EventDispatcher manifestEventDispatcher;
|
||||||
private final ParsingLoadable.Parser<? extends SsManifest> manifestParser;
|
private final ParsingLoadable.Parser<? extends SsManifest> manifestParser;
|
||||||
private final ArrayList<SsMediaPeriod> mediaPeriods;
|
private final ArrayList<SsMediaPeriod> mediaPeriods;
|
||||||
@Nullable private final Object tag;
|
|
||||||
|
|
||||||
private DataSource manifestDataSource;
|
private DataSource manifestDataSource;
|
||||||
private Loader manifestLoader;
|
private Loader manifestLoader;
|
||||||
@ -406,16 +447,15 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
@Nullable Handler eventHandler,
|
@Nullable Handler eventHandler,
|
||||||
@Nullable MediaSourceEventListener eventListener) {
|
@Nullable MediaSourceEventListener eventListener) {
|
||||||
this(
|
this(
|
||||||
|
new MediaItem.Builder().setUri(Uri.EMPTY).setMimeType(MimeTypes.APPLICATION_SS).build(),
|
||||||
manifest,
|
manifest,
|
||||||
/* manifestUri= */ null,
|
|
||||||
/* manifestDataSourceFactory= */ null,
|
/* manifestDataSourceFactory= */ null,
|
||||||
/* manifestParser= */ null,
|
/* manifestParser= */ null,
|
||||||
chunkSourceFactory,
|
chunkSourceFactory,
|
||||||
new DefaultCompositeSequenceableLoaderFactory(),
|
new DefaultCompositeSequenceableLoaderFactory(),
|
||||||
DrmSessionManager.getDummyDrmSessionManager(),
|
DrmSessionManager.getDummyDrmSessionManager(),
|
||||||
new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
|
new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
|
||||||
DEFAULT_LIVE_PRESENTATION_DELAY_MS,
|
DEFAULT_LIVE_PRESENTATION_DELAY_MS);
|
||||||
/* tag= */ null);
|
|
||||||
if (eventHandler != null && eventListener != null) {
|
if (eventHandler != null && eventListener != null) {
|
||||||
addEventListener(eventHandler, eventListener);
|
addEventListener(eventHandler, eventListener);
|
||||||
}
|
}
|
||||||
@ -507,35 +547,38 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
@Nullable Handler eventHandler,
|
@Nullable Handler eventHandler,
|
||||||
@Nullable MediaSourceEventListener eventListener) {
|
@Nullable MediaSourceEventListener eventListener) {
|
||||||
this(
|
this(
|
||||||
|
new MediaItem.Builder().setUri(manifestUri).setMimeType(MimeTypes.APPLICATION_SS).build(),
|
||||||
/* manifest= */ null,
|
/* manifest= */ null,
|
||||||
manifestUri,
|
|
||||||
manifestDataSourceFactory,
|
manifestDataSourceFactory,
|
||||||
manifestParser,
|
manifestParser,
|
||||||
chunkSourceFactory,
|
chunkSourceFactory,
|
||||||
new DefaultCompositeSequenceableLoaderFactory(),
|
new DefaultCompositeSequenceableLoaderFactory(),
|
||||||
DrmSessionManager.getDummyDrmSessionManager(),
|
DrmSessionManager.getDummyDrmSessionManager(),
|
||||||
new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
|
new DefaultLoadErrorHandlingPolicy(minLoadableRetryCount),
|
||||||
livePresentationDelayMs,
|
livePresentationDelayMs);
|
||||||
/* tag= */ null);
|
|
||||||
if (eventHandler != null && eventListener != null) {
|
if (eventHandler != null && eventListener != null) {
|
||||||
addEventListener(eventHandler, eventListener);
|
addEventListener(eventHandler, eventListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SsMediaSource(
|
private SsMediaSource(
|
||||||
|
MediaItem mediaItem,
|
||||||
@Nullable SsManifest manifest,
|
@Nullable SsManifest manifest,
|
||||||
@Nullable Uri manifestUri,
|
|
||||||
@Nullable DataSource.Factory manifestDataSourceFactory,
|
@Nullable DataSource.Factory manifestDataSourceFactory,
|
||||||
@Nullable ParsingLoadable.Parser<? extends SsManifest> manifestParser,
|
@Nullable ParsingLoadable.Parser<? extends SsManifest> manifestParser,
|
||||||
SsChunkSource.Factory chunkSourceFactory,
|
SsChunkSource.Factory chunkSourceFactory,
|
||||||
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
|
||||||
DrmSessionManager drmSessionManager,
|
DrmSessionManager drmSessionManager,
|
||||||
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||||
long livePresentationDelayMs,
|
long livePresentationDelayMs) {
|
||||||
@Nullable Object tag) {
|
|
||||||
Assertions.checkState(manifest == null || !manifest.isLive);
|
Assertions.checkState(manifest == null || !manifest.isLive);
|
||||||
|
this.mediaItem = mediaItem;
|
||||||
|
playbackProperties = checkNotNull(mediaItem.playbackProperties);
|
||||||
this.manifest = manifest;
|
this.manifest = manifest;
|
||||||
this.manifestUri = manifestUri == null ? null : SsUtil.fixManifestUri(manifestUri);
|
this.manifestUri =
|
||||||
|
playbackProperties.uri.equals(Uri.EMPTY)
|
||||||
|
? null
|
||||||
|
: SsUtil.fixManifestUri(playbackProperties.uri);
|
||||||
this.manifestDataSourceFactory = manifestDataSourceFactory;
|
this.manifestDataSourceFactory = manifestDataSourceFactory;
|
||||||
this.manifestParser = manifestParser;
|
this.manifestParser = manifestParser;
|
||||||
this.chunkSourceFactory = chunkSourceFactory;
|
this.chunkSourceFactory = chunkSourceFactory;
|
||||||
@ -544,7 +587,6 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
||||||
this.livePresentationDelayMs = livePresentationDelayMs;
|
this.livePresentationDelayMs = livePresentationDelayMs;
|
||||||
this.manifestEventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null);
|
this.manifestEventDispatcher = createEventDispatcher(/* mediaPeriodId= */ null);
|
||||||
this.tag = tag;
|
|
||||||
sideloadedManifest = manifest != null;
|
sideloadedManifest = manifest != null;
|
||||||
mediaPeriods = new ArrayList<>();
|
mediaPeriods = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@ -554,7 +596,12 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object getTag() {
|
public Object getTag() {
|
||||||
return tag;
|
return playbackProperties.tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(bachinger): add @Override annotation once the method is defined by MediaSource.
|
||||||
|
public MediaItem getMediaItem() {
|
||||||
|
return mediaItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -721,7 +768,7 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
/* isDynamic= */ manifest.isLive,
|
/* isDynamic= */ manifest.isLive,
|
||||||
/* isLive= */ manifest.isLive,
|
/* isLive= */ manifest.isLive,
|
||||||
manifest,
|
manifest,
|
||||||
tag);
|
mediaItem);
|
||||||
} else if (manifest.isLive) {
|
} else if (manifest.isLive) {
|
||||||
if (manifest.dvrWindowLengthUs != C.TIME_UNSET && manifest.dvrWindowLengthUs > 0) {
|
if (manifest.dvrWindowLengthUs != C.TIME_UNSET && manifest.dvrWindowLengthUs > 0) {
|
||||||
startTimeUs = Math.max(startTimeUs, endTimeUs - manifest.dvrWindowLengthUs);
|
startTimeUs = Math.max(startTimeUs, endTimeUs - manifest.dvrWindowLengthUs);
|
||||||
@ -744,7 +791,7 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
/* isDynamic= */ true,
|
/* isDynamic= */ true,
|
||||||
/* isLive= */ true,
|
/* isLive= */ true,
|
||||||
manifest,
|
manifest,
|
||||||
tag);
|
mediaItem);
|
||||||
} else {
|
} else {
|
||||||
long durationUs = manifest.durationUs != C.TIME_UNSET ? manifest.durationUs
|
long durationUs = manifest.durationUs != C.TIME_UNSET ? manifest.durationUs
|
||||||
: endTimeUs - startTimeUs;
|
: endTimeUs - startTimeUs;
|
||||||
@ -758,7 +805,7 @@ public final class SsMediaSource extends BaseMediaSource
|
|||||||
/* isDynamic= */ false,
|
/* isDynamic= */ false,
|
||||||
/* isLive= */ false,
|
/* isLive= */ false,
|
||||||
manifest,
|
manifest,
|
||||||
tag);
|
mediaItem);
|
||||||
}
|
}
|
||||||
refreshSourceInfo(timeline);
|
refreshSourceInfo(timeline);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 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.source.smoothstreaming;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.util.Util.castNonNull;
|
||||||
|
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.offline.StreamKey;
|
||||||
|
import com.google.android.exoplayer2.upstream.FileDataSource;
|
||||||
|
import java.util.Collections;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
/** Unit tests for {@link SsMediaSource}. */
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class SsMediaSourceTest {
|
||||||
|
|
||||||
|
// Tests backwards compatibility
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
|
public void factorySetTag_nullMediaItemTag_setsMediaItemTag() {
|
||||||
|
Object tag = new Object();
|
||||||
|
MediaItem mediaItem = MediaItem.fromUri("http://www.google.com");
|
||||||
|
SsMediaSource.Factory factory =
|
||||||
|
new SsMediaSource.Factory(new FileDataSource.Factory()).setTag(tag);
|
||||||
|
|
||||||
|
MediaItem ssMediaItem = factory.createMediaSource(mediaItem).getMediaItem();
|
||||||
|
|
||||||
|
assertThat(ssMediaItem.playbackProperties).isNotNull();
|
||||||
|
assertThat(ssMediaItem.playbackProperties.uri)
|
||||||
|
.isEqualTo(castNonNull(mediaItem.playbackProperties).uri);
|
||||||
|
assertThat(ssMediaItem.playbackProperties.tag).isEqualTo(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests backwards compatibility
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
|
public void factorySetTag_nonNullMediaItemTag_doesNotOverrideMediaItemTag() {
|
||||||
|
Object factoryTag = new Object();
|
||||||
|
Object mediaItemTag = new Object();
|
||||||
|
MediaItem mediaItem =
|
||||||
|
new MediaItem.Builder().setUri("http://www.google.com").setTag(mediaItemTag).build();
|
||||||
|
SsMediaSource.Factory factory =
|
||||||
|
new SsMediaSource.Factory(new FileDataSource.Factory()).setTag(factoryTag);
|
||||||
|
|
||||||
|
MediaItem ssMediaItem = factory.createMediaSource(mediaItem).getMediaItem();
|
||||||
|
|
||||||
|
assertThat(ssMediaItem.playbackProperties).isNotNull();
|
||||||
|
assertThat(ssMediaItem.playbackProperties.uri)
|
||||||
|
.isEqualTo(castNonNull(mediaItem.playbackProperties).uri);
|
||||||
|
assertThat(ssMediaItem.playbackProperties.tag).isEqualTo(mediaItemTag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests backwards compatibility
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
|
public void factorySetTag_setsDeprecatedMediaSourceTag() {
|
||||||
|
Object tag = new Object();
|
||||||
|
MediaItem mediaItem = MediaItem.fromUri("http://www.google.com");
|
||||||
|
SsMediaSource.Factory factory =
|
||||||
|
new SsMediaSource.Factory(new FileDataSource.Factory()).setTag(tag);
|
||||||
|
|
||||||
|
@Nullable Object mediaSourceTag = factory.createMediaSource(mediaItem).getTag();
|
||||||
|
|
||||||
|
assertThat(mediaSourceTag).isEqualTo(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests backwards compatibility
|
||||||
|
@Test
|
||||||
|
public void factoryCreateMediaSource_setsDeprecatedMediaSourceTag() {
|
||||||
|
Object tag = new Object();
|
||||||
|
MediaItem mediaItem =
|
||||||
|
new MediaItem.Builder().setUri("http://www.google.com").setTag(tag).build();
|
||||||
|
SsMediaSource.Factory factory = new SsMediaSource.Factory(new FileDataSource.Factory());
|
||||||
|
|
||||||
|
@Nullable Object mediaSourceTag = factory.createMediaSource(mediaItem).getTag();
|
||||||
|
|
||||||
|
assertThat(mediaSourceTag).isEqualTo(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests backwards compatibility
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
|
public void factorySetStreamKeys_emptyMediaItemStreamKeys_setsMediaItemStreamKeys() {
|
||||||
|
MediaItem mediaItem = MediaItem.fromUri("http://www.google.com");
|
||||||
|
StreamKey streamKey = new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 1);
|
||||||
|
SsMediaSource.Factory factory =
|
||||||
|
new SsMediaSource.Factory(new FileDataSource.Factory())
|
||||||
|
.setStreamKeys(Collections.singletonList(streamKey));
|
||||||
|
|
||||||
|
MediaItem ssMediaItem = factory.createMediaSource(mediaItem).getMediaItem();
|
||||||
|
|
||||||
|
assertThat(ssMediaItem.playbackProperties).isNotNull();
|
||||||
|
assertThat(ssMediaItem.playbackProperties.uri)
|
||||||
|
.isEqualTo(castNonNull(mediaItem.playbackProperties).uri);
|
||||||
|
assertThat(ssMediaItem.playbackProperties.streamKeys).containsExactly(streamKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests backwards compatibility
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
|
public void factorySetStreamKeys_withMediaItemStreamKeys_doesNotOverrideMediaItemStreamKeys() {
|
||||||
|
StreamKey mediaItemStreamKey = new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 1);
|
||||||
|
MediaItem mediaItem =
|
||||||
|
new MediaItem.Builder()
|
||||||
|
.setUri("http://www.google.com")
|
||||||
|
.setStreamKeys(Collections.singletonList(mediaItemStreamKey))
|
||||||
|
.build();
|
||||||
|
SsMediaSource.Factory factory =
|
||||||
|
new SsMediaSource.Factory(new FileDataSource.Factory())
|
||||||
|
.setStreamKeys(
|
||||||
|
Collections.singletonList(new StreamKey(/* groupIndex= */ 1, /* trackIndex= */ 0)));
|
||||||
|
|
||||||
|
MediaItem ssMediaItem = factory.createMediaSource(mediaItem).getMediaItem();
|
||||||
|
|
||||||
|
assertThat(ssMediaItem.playbackProperties).isNotNull();
|
||||||
|
assertThat(ssMediaItem.playbackProperties.uri)
|
||||||
|
.isEqualTo(castNonNull(mediaItem.playbackProperties).uri);
|
||||||
|
assertThat(ssMediaItem.playbackProperties.streamKeys).containsExactly(mediaItemStreamKey);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user