mirror of
https://github.com/androidx/media.git
synced 2025-04-29 22:36:54 +08:00
Add a Factory for DownloadHelper and deprecate forMediaItem() methods
PiperOrigin-RevId: 739909021
This commit is contained in:
parent
ae563dbab0
commit
a1738f96f9
@ -45,6 +45,8 @@
|
||||
`DownloadRequest` carries the resolved byte range, with which a
|
||||
`ProgressiveDownloader` can be created and download the content
|
||||
correspondingly.
|
||||
* Add `DownloadHelper.Factory` with which the static
|
||||
`DownloadHelper.forMediaItem()` methods are replaced.
|
||||
* OkHttp extension:
|
||||
* Cronet extension:
|
||||
* RTMP extension:
|
||||
|
@ -78,6 +78,7 @@ import androidx.media3.exoplayer.upstream.DefaultAllocator;
|
||||
import androidx.media3.extractor.ExtractorsFactory;
|
||||
import androidx.media3.extractor.SeekMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -111,6 +112,113 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
@UnstableApi
|
||||
public final class DownloadHelper {
|
||||
|
||||
/** A factory of {@link DownloadHelper}. */
|
||||
public static final class Factory {
|
||||
@Nullable private DataSource.Factory dataSourceFactory;
|
||||
@Nullable private RenderersFactory renderersFactory;
|
||||
private TrackSelectionParameters trackSelectionParameters;
|
||||
@Nullable private DrmSessionManager drmSessionManager;
|
||||
private boolean debugLoggingEnabled;
|
||||
|
||||
/** Creates a {@link Factory}. */
|
||||
public Factory() {
|
||||
this.trackSelectionParameters = DEFAULT_TRACK_SELECTOR_PARAMETERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link DataSource.Factory} used to load the manifest for adaptive streams or the
|
||||
* {@link SeekMap} for progressive streams. The default is {@code null}.
|
||||
*
|
||||
* <p>A {@link DataSource.Factory} is required for adaptive streams or when requesting partial
|
||||
* downloads for progressive streams. In the latter case, this has to be a {@link
|
||||
* CacheDataSource.Factory} for the {@link Cache} into which downloads will be written.
|
||||
*
|
||||
* @return This factory, for convenience.
|
||||
*/
|
||||
@CanIgnoreReturnValue
|
||||
public Factory setDataSourceFactory(@Nullable DataSource.Factory dataSourceFactory) {
|
||||
this.dataSourceFactory = dataSourceFactory;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link RenderersFactory} creating the renderers for which tracks are selected. The
|
||||
* default is {@code null}.
|
||||
*
|
||||
* <p>This is only used for adaptive streams.
|
||||
*
|
||||
* @return This factory, for convenience.
|
||||
*/
|
||||
@CanIgnoreReturnValue
|
||||
public Factory setRenderersFactory(@Nullable RenderersFactory renderersFactory) {
|
||||
this.renderersFactory = renderersFactory;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link TrackSelectionParameters} for selecting tracks for downloading. The default is
|
||||
* {@link #DEFAULT_TRACK_SELECTOR_PARAMETERS}.
|
||||
*
|
||||
* <p>This is only used for adaptive streams.
|
||||
*
|
||||
* @return This factory, for convenience.
|
||||
*/
|
||||
@CanIgnoreReturnValue
|
||||
public Factory setTrackSelectionParameters(TrackSelectionParameters trackSelectionParameters) {
|
||||
this.trackSelectionParameters = trackSelectionParameters;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link DrmSessionManager}. Used to help determine which tracks can be selected. The
|
||||
* default is {@code null}.
|
||||
*
|
||||
* @return This factory, for convenience.
|
||||
*/
|
||||
@CanIgnoreReturnValue
|
||||
public Factory setDrmSessionManager(@Nullable DrmSessionManager drmSessionManager) {
|
||||
this.drmSessionManager = drmSessionManager;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to log debug information. The default is {@code false}.
|
||||
*
|
||||
* @return This factory, for convenience.
|
||||
*/
|
||||
@CanIgnoreReturnValue
|
||||
public Factory setDebugLoggingEnabled(boolean debugLoggingEnabled) {
|
||||
this.debugLoggingEnabled = debugLoggingEnabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link DownloadHelper}.
|
||||
*
|
||||
* @param mediaItem The {@link MediaItem} to download.
|
||||
* @throws IllegalStateException If the corresponding module is missing for DASH, HLS or
|
||||
* SmoothStreaming media items.
|
||||
* @throws IllegalArgumentException If the {@code dataSourceFactory} is null for adaptive
|
||||
* streams.
|
||||
*/
|
||||
public DownloadHelper create(MediaItem mediaItem) {
|
||||
boolean isProgressive = isProgressive(checkNotNull(mediaItem.localConfiguration));
|
||||
Assertions.checkArgument(isProgressive || dataSourceFactory != null);
|
||||
return new DownloadHelper(
|
||||
mediaItem,
|
||||
isProgressive && dataSourceFactory == null
|
||||
? null
|
||||
: createMediaSourceInternal(
|
||||
mediaItem, castNonNull(dataSourceFactory), drmSessionManager),
|
||||
trackSelectionParameters,
|
||||
renderersFactory != null
|
||||
? new DefaultRendererCapabilitiesList.Factory(renderersFactory)
|
||||
.createRendererCapabilitiesList()
|
||||
: new UnreleaseableRendererCapabilitiesList(new RendererCapabilities[0]),
|
||||
debugLoggingEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
/** Default track selection parameters for downloading. */
|
||||
public static final DefaultTrackSelector.Parameters DEFAULT_TRACK_SELECTOR_PARAMETERS =
|
||||
DefaultTrackSelector.Parameters.DEFAULT
|
||||
@ -172,241 +280,126 @@ public final class DownloadHelper {
|
||||
public static class LiveContentUnsupportedException extends IOException {}
|
||||
|
||||
/**
|
||||
* Creates a {@link DownloadHelper} for the given progressive media item.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param mediaItem A {@link MediaItem}.
|
||||
* @return A {@link DownloadHelper} for progressive streams.
|
||||
* @throws IllegalStateException If the media item is of type DASH, HLS or SmoothStreaming.
|
||||
* @deprecated Use {@link Factory#create(MediaItem)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static DownloadHelper forMediaItem(Context context, MediaItem mediaItem) {
|
||||
Assertions.checkArgument(isProgressive(checkNotNull(mediaItem.localConfiguration)));
|
||||
return forMediaItem(
|
||||
mediaItem,
|
||||
DEFAULT_TRACK_SELECTOR_PARAMETERS,
|
||||
/* renderersFactory= */ null,
|
||||
/* dataSourceFactory= */ null,
|
||||
/* drmSessionManager= */ null);
|
||||
return new DownloadHelper.Factory().create(mediaItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DownloadHelper} for the given media item.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param mediaItem A {@link MediaItem}.
|
||||
* @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest for adaptive
|
||||
* streams or the {@link SeekMap} for progressive streams. In the latter case, this has to be
|
||||
* a {@link CacheDataSource.Factory} for the {@link Cache} into which downloads will be
|
||||
* written.
|
||||
* @throws IllegalStateException If the corresponding module is missing for DASH, HLS or
|
||||
* SmoothStreaming media items.
|
||||
* @deprecated Use {@link Factory#create(MediaItem)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static DownloadHelper forMediaItem(
|
||||
Context context, MediaItem mediaItem, DataSource.Factory dataSourceFactory) {
|
||||
return forMediaItem(context, mediaItem, dataSourceFactory, /* debugLoggingEnabled= */ false);
|
||||
return new DownloadHelper.Factory().setDataSourceFactory(dataSourceFactory).create(mediaItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DownloadHelper} for the given media item.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param mediaItem A {@link MediaItem}.
|
||||
* @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest for adaptive
|
||||
* streams or the {@link SeekMap} for progressive streams. In the latter case, this has to be
|
||||
* a {@link CacheDataSource.Factory} for the {@link Cache} into which downloads will be
|
||||
* written.
|
||||
* @param debugLoggingEnabled Whether to log debug information.
|
||||
* @throws IllegalStateException If the corresponding module is missing for DASH, HLS or
|
||||
* SmoothStreaming media items.
|
||||
* @deprecated Use {@link Factory#create(MediaItem)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static DownloadHelper forMediaItem(
|
||||
Context context,
|
||||
MediaItem mediaItem,
|
||||
DataSource.Factory dataSourceFactory,
|
||||
boolean debugLoggingEnabled) {
|
||||
return forMediaItem(
|
||||
mediaItem,
|
||||
getDefaultTrackSelectorParameters(context),
|
||||
/* renderersFactory= */ null,
|
||||
dataSourceFactory,
|
||||
/* drmSessionManager= */ null,
|
||||
debugLoggingEnabled);
|
||||
return new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(dataSourceFactory)
|
||||
.setDebugLoggingEnabled(debugLoggingEnabled)
|
||||
.create(mediaItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DownloadHelper} for the given media item.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param mediaItem A {@link MediaItem}.
|
||||
* @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
|
||||
* selected.
|
||||
* @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest for adaptive
|
||||
* streams or the {@link SeekMap} for progressive streams. This argument is required for
|
||||
* adaptive streams or when requesting partial downloads for progressive streams. In the
|
||||
* latter case, this has to be a {@link CacheDataSource.Factory} for the {@link Cache} into
|
||||
* which downloads will be written.
|
||||
* @throws IllegalStateException If the corresponding module is missing for DASH, HLS or
|
||||
* SmoothStreaming media items.
|
||||
* @throws IllegalArgumentException If the {@code dataSourceFactory} is null for adaptive streams.
|
||||
* @deprecated Use {@link Factory#create(MediaItem)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static DownloadHelper forMediaItem(
|
||||
Context context,
|
||||
MediaItem mediaItem,
|
||||
@Nullable RenderersFactory renderersFactory,
|
||||
@Nullable DataSource.Factory dataSourceFactory) {
|
||||
return forMediaItem(
|
||||
context, mediaItem, renderersFactory, dataSourceFactory, /* debugLoggingEnabled= */ false);
|
||||
return new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(dataSourceFactory)
|
||||
.setRenderersFactory(renderersFactory)
|
||||
.create(mediaItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DownloadHelper} for the given media item.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param mediaItem A {@link MediaItem}.
|
||||
* @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
|
||||
* selected.
|
||||
* @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest for adaptive
|
||||
* streams or the {@link SeekMap} for progressive streams. This argument is required for
|
||||
* adaptive streams or when requesting partial downloads for progressive streams. In the
|
||||
* latter case, this has to be a {@link CacheDataSource.Factory} for the {@link Cache} into
|
||||
* which downloads will be written.
|
||||
* @param debugLoggingEnabled Whether to log debug information.
|
||||
* @throws IllegalStateException If the corresponding module is missing for DASH, HLS or
|
||||
* SmoothStreaming media items.
|
||||
* @throws IllegalArgumentException If the {@code dataSourceFactory} is null for adaptive streams.
|
||||
* @deprecated Use {@link Factory#create(MediaItem)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static DownloadHelper forMediaItem(
|
||||
Context context,
|
||||
MediaItem mediaItem,
|
||||
@Nullable RenderersFactory renderersFactory,
|
||||
@Nullable DataSource.Factory dataSourceFactory,
|
||||
boolean debugLoggingEnabled) {
|
||||
return forMediaItem(
|
||||
mediaItem,
|
||||
DEFAULT_TRACK_SELECTOR_PARAMETERS,
|
||||
renderersFactory,
|
||||
dataSourceFactory,
|
||||
/* drmSessionManager= */ null,
|
||||
debugLoggingEnabled);
|
||||
return new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(dataSourceFactory)
|
||||
.setRenderersFactory(renderersFactory)
|
||||
.setDebugLoggingEnabled(debugLoggingEnabled)
|
||||
.create(mediaItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DownloadHelper} for the given media item.
|
||||
*
|
||||
* @param mediaItem A {@link MediaItem}.
|
||||
* @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
|
||||
* selected.
|
||||
* @param trackSelectionParameters {@link TrackSelectionParameters} for selecting tracks for
|
||||
* downloading.
|
||||
* @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest for adaptive
|
||||
* streams or the {@link SeekMap} for progressive streams. This argument is required for
|
||||
* adaptive streams or when requesting partial downloads for progressive streams. In the
|
||||
* latter case, this has to be a {@link CacheDataSource.Factory} for the {@link Cache} into
|
||||
* which downloads will be written.
|
||||
* @throws IllegalStateException If the corresponding module is missing for DASH, HLS or
|
||||
* SmoothStreaming media items.
|
||||
* @throws IllegalArgumentException If the {@code dataSourceFactory} is null for adaptive streams.
|
||||
* @deprecated Use {@link Factory#create(MediaItem)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static DownloadHelper forMediaItem(
|
||||
MediaItem mediaItem,
|
||||
TrackSelectionParameters trackSelectionParameters,
|
||||
@Nullable RenderersFactory renderersFactory,
|
||||
@Nullable DataSource.Factory dataSourceFactory) {
|
||||
return forMediaItem(
|
||||
mediaItem,
|
||||
trackSelectionParameters,
|
||||
renderersFactory,
|
||||
dataSourceFactory,
|
||||
/* debugLoggingEnabled= */ false);
|
||||
return new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(dataSourceFactory)
|
||||
.setTrackSelectionParameters(trackSelectionParameters)
|
||||
.setRenderersFactory(renderersFactory)
|
||||
.create(mediaItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DownloadHelper} for the given media item.
|
||||
*
|
||||
* @param mediaItem A {@link MediaItem}.
|
||||
* @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
|
||||
* selected.
|
||||
* @param trackSelectionParameters {@link TrackSelectionParameters} for selecting tracks for
|
||||
* downloading.
|
||||
* @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest for adaptive
|
||||
* streams or the {@link SeekMap} for progressive streams. This argument is required for
|
||||
* adaptive streams or when requesting partial downloads for progressive streams. In the
|
||||
* latter case, this has to be a {@link CacheDataSource.Factory} for the {@link Cache} into
|
||||
* which downloads will be written.
|
||||
* @param debugLoggingEnabled Whether to log debug information.
|
||||
* @throws IllegalStateException If the corresponding module is missing for DASH, HLS or
|
||||
* SmoothStreaming media items.
|
||||
* @throws IllegalArgumentException If the {@code dataSourceFactory} is null for adaptive streams.
|
||||
* @deprecated Use {@link Factory#create(MediaItem)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static DownloadHelper forMediaItem(
|
||||
MediaItem mediaItem,
|
||||
TrackSelectionParameters trackSelectionParameters,
|
||||
@Nullable RenderersFactory renderersFactory,
|
||||
@Nullable DataSource.Factory dataSourceFactory,
|
||||
boolean debugLoggingEnabled) {
|
||||
return forMediaItem(
|
||||
mediaItem,
|
||||
trackSelectionParameters,
|
||||
renderersFactory,
|
||||
dataSourceFactory,
|
||||
/* drmSessionManager= */ null,
|
||||
debugLoggingEnabled);
|
||||
return new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(dataSourceFactory)
|
||||
.setTrackSelectionParameters(trackSelectionParameters)
|
||||
.setRenderersFactory(renderersFactory)
|
||||
.setDebugLoggingEnabled(debugLoggingEnabled)
|
||||
.create(mediaItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DownloadHelper} for the given media item.
|
||||
*
|
||||
* @param mediaItem A {@link MediaItem}.
|
||||
* @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
|
||||
* selected.
|
||||
* @param trackSelectionParameters {@link TrackSelectionParameters} for selecting tracks for
|
||||
* downloading.
|
||||
* @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest for adaptive
|
||||
* streams or the {@link SeekMap} for progressive streams. This argument is required for
|
||||
* adaptive streams or when requesting partial downloads for progressive streams. In the
|
||||
* latter case, this has to be a {@link CacheDataSource.Factory} for the {@link Cache} into
|
||||
* which downloads will be written.
|
||||
* @param drmSessionManager An optional {@link DrmSessionManager}. Used to help determine which
|
||||
* tracks can be selected.
|
||||
* @throws IllegalStateException If the corresponding module is missing for DASH, HLS or
|
||||
* SmoothStreaming media items.
|
||||
* @throws IllegalArgumentException If the {@code dataSourceFactory} is null for adaptive streams.
|
||||
* @deprecated Use {@link Factory#create(MediaItem)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static DownloadHelper forMediaItem(
|
||||
MediaItem mediaItem,
|
||||
TrackSelectionParameters trackSelectionParameters,
|
||||
@Nullable RenderersFactory renderersFactory,
|
||||
@Nullable DataSource.Factory dataSourceFactory,
|
||||
@Nullable DrmSessionManager drmSessionManager) {
|
||||
return forMediaItem(
|
||||
mediaItem,
|
||||
trackSelectionParameters,
|
||||
renderersFactory,
|
||||
dataSourceFactory,
|
||||
drmSessionManager,
|
||||
/* debugLoggingEnabled= */ false);
|
||||
return new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(dataSourceFactory)
|
||||
.setTrackSelectionParameters(trackSelectionParameters)
|
||||
.setRenderersFactory(renderersFactory)
|
||||
.setDrmSessionManager(drmSessionManager)
|
||||
.create(mediaItem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DownloadHelper} for the given media item.
|
||||
*
|
||||
* @param mediaItem A {@link MediaItem}.
|
||||
* @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
|
||||
* selected.
|
||||
* @param trackSelectionParameters {@link TrackSelectionParameters} for selecting tracks for
|
||||
* downloading.
|
||||
* @param dataSourceFactory A {@link DataSource.Factory} used to load the manifest for adaptive
|
||||
* streams or the {@link SeekMap} for progressive streams. This argument is required for
|
||||
* adaptive streams or when requesting partial downloads for progressive streams. In the
|
||||
* latter case, this has to be a {@link CacheDataSource.Factory} for the {@link Cache} into
|
||||
* which downloads will be written.
|
||||
* @param drmSessionManager An optional {@link DrmSessionManager}. Used to help determine which
|
||||
* tracks can be selected.
|
||||
* @param debugLoggingEnabled Whether to log debug information.
|
||||
* @throws IllegalStateException If the corresponding module is missing for DASH, HLS or
|
||||
* SmoothStreaming media items.
|
||||
* @throws IllegalArgumentException If the {@code dataSourceFactory} is null for adaptive streams.
|
||||
* @deprecated Use {@link Factory#create(MediaItem)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static DownloadHelper forMediaItem(
|
||||
MediaItem mediaItem,
|
||||
TrackSelectionParameters trackSelectionParameters,
|
||||
@ -414,20 +407,13 @@ public final class DownloadHelper {
|
||||
@Nullable DataSource.Factory dataSourceFactory,
|
||||
@Nullable DrmSessionManager drmSessionManager,
|
||||
boolean debugLoggingEnabled) {
|
||||
boolean isProgressive = isProgressive(checkNotNull(mediaItem.localConfiguration));
|
||||
Assertions.checkArgument(isProgressive || dataSourceFactory != null);
|
||||
return new DownloadHelper(
|
||||
mediaItem,
|
||||
isProgressive && dataSourceFactory == null
|
||||
? null
|
||||
: createMediaSourceInternal(
|
||||
mediaItem, castNonNull(dataSourceFactory), drmSessionManager),
|
||||
trackSelectionParameters,
|
||||
renderersFactory != null
|
||||
? new DefaultRendererCapabilitiesList.Factory(renderersFactory)
|
||||
.createRendererCapabilitiesList()
|
||||
: new UnreleaseableRendererCapabilitiesList(new RendererCapabilities[0]),
|
||||
debugLoggingEnabled);
|
||||
return new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(dataSourceFactory)
|
||||
.setTrackSelectionParameters(trackSelectionParameters)
|
||||
.setRenderersFactory(renderersFactory)
|
||||
.setDrmSessionManager(drmSessionManager)
|
||||
.setDebugLoggingEnabled(debugLoggingEnabled)
|
||||
.create(mediaItem);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -141,8 +141,7 @@ public class DownloadHelperTest {
|
||||
public void prepare_withoutMediaSource_tracksInfoNotAvailable() throws Exception {
|
||||
// DownloadHelper will be constructed without MediaSource if no DataSource.Factory is provided.
|
||||
DownloadHelper downloadHelper =
|
||||
DownloadHelper.forMediaItem(
|
||||
getApplicationContext(), MediaItem.fromUri("asset:///media/mp4/sample.mp4"));
|
||||
new DownloadHelper.Factory().create(MediaItem.fromUri("asset:///media/mp4/sample.mp4"));
|
||||
|
||||
boolean tracksInfoAvailable = prepareDownloadHelper(downloadHelper);
|
||||
|
||||
@ -153,10 +152,9 @@ public class DownloadHelperTest {
|
||||
public void prepare_prepareProgressiveSource_tracksInfoNotAvailable() throws Exception {
|
||||
Context context = getApplicationContext();
|
||||
DownloadHelper downloadHelper =
|
||||
DownloadHelper.forMediaItem(
|
||||
context,
|
||||
MediaItem.fromUri("asset:///media/mp4/sample.mp4"),
|
||||
new DefaultDataSource.Factory(context));
|
||||
new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(new DefaultDataSource.Factory(context))
|
||||
.create(MediaItem.fromUri("asset:///media/mp4/sample.mp4"));
|
||||
|
||||
boolean tracksInfoAvailable = prepareDownloadHelper(downloadHelper);
|
||||
|
||||
@ -489,12 +487,10 @@ public class DownloadHelperTest {
|
||||
public void
|
||||
getDownloadRequest_createsDownloadRequestWithConcreteTimeRange_requestContainsConcreteByteRange()
|
||||
throws Exception {
|
||||
Context context = getApplicationContext();
|
||||
DownloadHelper downloadHelper =
|
||||
DownloadHelper.forMediaItem(
|
||||
context,
|
||||
MediaItem.fromUri("asset:///media/mp4/long_1080p_lowbitrate.mp4"),
|
||||
new DefaultDataSource.Factory(context));
|
||||
new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(new DefaultDataSource.Factory(getApplicationContext()))
|
||||
.create(MediaItem.fromUri("asset:///media/mp4/long_1080p_lowbitrate.mp4"));
|
||||
prepareDownloadHelper(downloadHelper);
|
||||
|
||||
DownloadRequest downloadRequest =
|
||||
@ -510,12 +506,10 @@ public class DownloadHelperTest {
|
||||
public void
|
||||
getDownloadRequest_createsDownloadRequestWithUnsetStartPosition_requestContainsConcreteByteRange()
|
||||
throws Exception {
|
||||
Context context = getApplicationContext();
|
||||
DownloadHelper downloadHelper =
|
||||
DownloadHelper.forMediaItem(
|
||||
context,
|
||||
MediaItem.fromUri("asset:///media/mp4/long_1080p_lowbitrate.mp4"),
|
||||
new DefaultDataSource.Factory(context));
|
||||
new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(new DefaultDataSource.Factory(getApplicationContext()))
|
||||
.create(MediaItem.fromUri("asset:///media/mp4/long_1080p_lowbitrate.mp4"));
|
||||
prepareDownloadHelper(downloadHelper);
|
||||
|
||||
DownloadRequest downloadRequest =
|
||||
@ -530,12 +524,10 @@ public class DownloadHelperTest {
|
||||
@Test
|
||||
public void getDownloadRequest_createsDownloadRequestWithUnsetLength_requestContainsUnsetLength()
|
||||
throws Exception {
|
||||
Context context = getApplicationContext();
|
||||
DownloadHelper downloadHelper =
|
||||
DownloadHelper.forMediaItem(
|
||||
context,
|
||||
MediaItem.fromUri("asset:///media/mp4/long_1080p_lowbitrate.mp4"),
|
||||
new DefaultDataSource.Factory(context));
|
||||
new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(new DefaultDataSource.Factory(getApplicationContext()))
|
||||
.create(MediaItem.fromUri("asset:///media/mp4/long_1080p_lowbitrate.mp4"));
|
||||
prepareDownloadHelper(downloadHelper);
|
||||
|
||||
DownloadRequest downloadRequest =
|
||||
@ -551,12 +543,10 @@ public class DownloadHelperTest {
|
||||
public void
|
||||
getDownloadRequest_createsDownloadRequestForTooShortStreamWithTimeRange_requestContainsUnsetLength()
|
||||
throws Exception {
|
||||
Context context = getApplicationContext();
|
||||
DownloadHelper downloadHelper =
|
||||
DownloadHelper.forMediaItem(
|
||||
context,
|
||||
MediaItem.fromUri("asset:///media/mp4/sample.mp4"),
|
||||
new DefaultDataSource.Factory(context));
|
||||
new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(new DefaultDataSource.Factory(getApplicationContext()))
|
||||
.create(MediaItem.fromUri("asset:///media/mp4/sample.mp4"));
|
||||
prepareDownloadHelper(downloadHelper);
|
||||
|
||||
DownloadRequest downloadRequest =
|
||||
@ -572,12 +562,10 @@ public class DownloadHelperTest {
|
||||
public void
|
||||
getDownloadRequest_createsDownloadRequestWithoutTimeRange_requestContainsNullByteRange()
|
||||
throws Exception {
|
||||
Context context = getApplicationContext();
|
||||
DownloadHelper downloadHelper =
|
||||
DownloadHelper.forMediaItem(
|
||||
getApplicationContext(),
|
||||
MediaItem.fromUri("asset:///media/mp4/sample.mp4"),
|
||||
new DefaultDataSource.Factory(context));
|
||||
new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(new DefaultDataSource.Factory(getApplicationContext()))
|
||||
.create(MediaItem.fromUri("asset:///media/mp4/sample.mp4"));
|
||||
prepareDownloadHelper(downloadHelper);
|
||||
|
||||
DownloadRequest downloadRequest = downloadHelper.getDownloadRequest(/* data= */ null);
|
||||
@ -612,11 +600,10 @@ public class DownloadHelperTest {
|
||||
(handler, videoListener, audioListener, metadata, text) ->
|
||||
new Renderer[] {textRenderer, audioRenderer, videoRenderer};
|
||||
DownloadHelper downloadHelper =
|
||||
DownloadHelper.forMediaItem(
|
||||
MediaItem.fromUri("asset:///media/mp4/sample.mp4"),
|
||||
DownloadHelper.DEFAULT_TRACK_SELECTOR_PARAMETERS,
|
||||
renderersFactory,
|
||||
new DefaultDataSource.Factory(getApplicationContext()));
|
||||
new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(new DefaultDataSource.Factory(getApplicationContext()))
|
||||
.setRenderersFactory(renderersFactory)
|
||||
.create(MediaItem.fromUri("asset:///media/mp4/sample.mp4"));
|
||||
|
||||
prepareDownloadHelper(downloadHelper);
|
||||
downloadHelper.release();
|
||||
@ -634,8 +621,7 @@ public class DownloadHelperTest {
|
||||
new Thread(
|
||||
() -> {
|
||||
try {
|
||||
downloadHelper.set(
|
||||
DownloadHelper.forMediaItem(getApplicationContext(), testMediaItem));
|
||||
downloadHelper.set(new DownloadHelper.Factory().create(testMediaItem));
|
||||
} catch (Throwable e) {
|
||||
exception.set(e);
|
||||
}
|
||||
@ -662,11 +648,10 @@ public class DownloadHelperTest {
|
||||
(handler, videoListener, audioListener, metadata, text) ->
|
||||
new Renderer[] {videoRenderer};
|
||||
downloadHelper.set(
|
||||
DownloadHelper.forMediaItem(
|
||||
getApplicationContext(),
|
||||
testMediaItem,
|
||||
renderersFactory,
|
||||
new FakeDataSource.Factory()));
|
||||
new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(new FakeDataSource.Factory())
|
||||
.setRenderersFactory(renderersFactory)
|
||||
.create(testMediaItem));
|
||||
} catch (Throwable e) {
|
||||
exception.set(e);
|
||||
}
|
||||
@ -692,11 +677,10 @@ public class DownloadHelperTest {
|
||||
(handler, videoListener, audioListener, metadata, text) ->
|
||||
new Renderer[] {videoRenderer};
|
||||
downloadHelper.set(
|
||||
DownloadHelper.forMediaItem(
|
||||
testMediaItem,
|
||||
TrackSelectionParameters.DEFAULT,
|
||||
renderersFactory,
|
||||
new FakeDataSource.Factory()));
|
||||
new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(new FakeDataSource.Factory())
|
||||
.setRenderersFactory(renderersFactory)
|
||||
.create(testMediaItem));
|
||||
} catch (Throwable e) {
|
||||
exception.set(e);
|
||||
}
|
||||
@ -723,16 +707,16 @@ public class DownloadHelperTest {
|
||||
(handler, videoListener, audioListener, metadata, text) ->
|
||||
new Renderer[] {videoRenderer};
|
||||
downloadHelper.set(
|
||||
DownloadHelper.forMediaItem(
|
||||
testMediaItem,
|
||||
TrackSelectionParameters.DEFAULT,
|
||||
renderersFactory,
|
||||
new FakeDataSource.Factory(),
|
||||
new DefaultDrmSessionManager.Builder()
|
||||
.build(
|
||||
new HttpMediaDrmCallback(
|
||||
/* defaultLicenseUrl= */ null,
|
||||
new DefaultDataSource.Factory(getApplicationContext())))));
|
||||
new DownloadHelper.Factory()
|
||||
.setDataSourceFactory(new FakeDataSource.Factory())
|
||||
.setRenderersFactory(renderersFactory)
|
||||
.setDrmSessionManager(
|
||||
new DefaultDrmSessionManager.Builder()
|
||||
.build(
|
||||
new HttpMediaDrmCallback(
|
||||
/* defaultLicenseUrl= */ null,
|
||||
new DefaultDataSource.Factory(getApplicationContext()))))
|
||||
.create(testMediaItem));
|
||||
} catch (Throwable e) {
|
||||
exception.set(e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user