Commit f4287ed0 by christosts Committed by kim-vde

Add a builder for DownloadRequest

PiperOrigin-RevId: 324616617
parent 129ef7cc
Showing with 168 additions and 170 deletions
...@@ -168,6 +168,7 @@ ...@@ -168,6 +168,7 @@
[#6725](https://github.com/google/ExoPlayer/issues/6725), [#6725](https://github.com/google/ExoPlayer/issues/6725),
[#7066](https://github.com/google/ExoPlayer/issues/7066)). [#7066](https://github.com/google/ExoPlayer/issues/7066)).
* Downloads and caching: * Downloads and caching:
* Add builder in `DownloadRequest`.
* Support passing an `Executor` to `DefaultDownloaderFactory` on which * Support passing an `Executor` to `DefaultDownloaderFactory` on which
data downloads are performed. data downloads are performed.
* Parallelize and merge downloads in `SegmentDownloader` to improve * Parallelize and merge downloads in `SegmentDownloader` to improve
......
...@@ -140,10 +140,13 @@ import java.util.List; ...@@ -140,10 +140,13 @@ import java.util.List;
// Remove actions are not supported anymore. // Remove actions are not supported anymore.
throw new UnsupportedRequestException(); throw new UnsupportedRequestException();
} }
// keySetId and mimeType were not supported. Set keySetId to null and try to infer the mime
// type from the download type. return new DownloadRequest.Builder(id, uri)
return new DownloadRequest( .setMimeType(inferMimeType(downloadType))
id, uri, inferMimeType(downloadType), keys, /* keySetId= */ null, customCacheKey, data); .setStreamKeys(keys)
.setCustomCacheKey(customCacheKey)
.setData(data)
.build();
} }
private static StreamKey readKey(String type, int version, DataInputStream input) private static StreamKey readKey(String type, int version, DataInputStream input)
......
...@@ -434,14 +434,15 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex { ...@@ -434,14 +434,15 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
private static Download getDownloadForCurrentRow(Cursor cursor) { private static Download getDownloadForCurrentRow(Cursor cursor) {
byte[] keySetId = cursor.getBlob(COLUMN_INDEX_KEY_SET_ID); byte[] keySetId = cursor.getBlob(COLUMN_INDEX_KEY_SET_ID);
DownloadRequest request = DownloadRequest request =
new DownloadRequest( new DownloadRequest.Builder(
/* id= */ cursor.getString(COLUMN_INDEX_ID), /* id= */ cursor.getString(COLUMN_INDEX_ID),
/* uri= */ Uri.parse(cursor.getString(COLUMN_INDEX_URI)), /* uri= */ Uri.parse(cursor.getString(COLUMN_INDEX_URI)))
/* mimeType= */ cursor.getString(COLUMN_INDEX_MIME_TYPE), .setMimeType(cursor.getString(COLUMN_INDEX_MIME_TYPE))
/* streamKeys= */ decodeStreamKeys(cursor.getString(COLUMN_INDEX_STREAM_KEYS)), .setStreamKeys(decodeStreamKeys(cursor.getString(COLUMN_INDEX_STREAM_KEYS)))
/* keySetId= */ keySetId.length > 0 ? keySetId : null, .setKeySetId(keySetId.length > 0 ? keySetId : null)
/* customCacheKey= */ cursor.getString(COLUMN_INDEX_CUSTOM_CACHE_KEY), .setCustomCacheKey(cursor.getString(COLUMN_INDEX_CUSTOM_CACHE_KEY))
/* data= */ cursor.getBlob(COLUMN_INDEX_DATA)); .setData(cursor.getBlob(COLUMN_INDEX_DATA))
.build();
DownloadProgress downloadProgress = new DownloadProgress(); DownloadProgress downloadProgress = new DownloadProgress();
downloadProgress.bytesDownloaded = cursor.getLong(COLUMN_INDEX_BYTES_DOWNLOADED); downloadProgress.bytesDownloaded = cursor.getLong(COLUMN_INDEX_BYTES_DOWNLOADED);
downloadProgress.percentDownloaded = cursor.getFloat(COLUMN_INDEX_PERCENT_DOWNLOADED); downloadProgress.percentDownloaded = cursor.getFloat(COLUMN_INDEX_PERCENT_DOWNLOADED);
...@@ -485,14 +486,13 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex { ...@@ -485,14 +486,13 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
* 13 bytes_downloaded integer * 13 bytes_downloaded integer
*/ */
DownloadRequest request = DownloadRequest request =
new DownloadRequest( new DownloadRequest.Builder(
/* id= */ cursor.getString(0), /* id= */ cursor.getString(0), /* uri= */ Uri.parse(cursor.getString(2)))
/* uri= */ Uri.parse(cursor.getString(2)), .setMimeType(inferMimeType(cursor.getString(1)))
/* mimeType= */ inferMimeType(cursor.getString(1)), .setStreamKeys(decodeStreamKeys(cursor.getString(3)))
/* streamKeys= */ decodeStreamKeys(cursor.getString(3)), .setCustomCacheKey(cursor.getString(4))
/* keySetId= */ null, .setData(cursor.getBlob(5))
/* customCacheKey= */ cursor.getString(4), .build();
/* data= */ cursor.getBlob(5));
DownloadProgress downloadProgress = new DownloadProgress(); DownloadProgress downloadProgress = new DownloadProgress();
downloadProgress.bytesDownloaded = cursor.getLong(13); downloadProgress.bytesDownloaded = cursor.getLong(13);
downloadProgress.percentDownloaded = cursor.getFloat(12); downloadProgress.percentDownloaded = cursor.getFloat(12);
......
...@@ -745,14 +745,11 @@ public final class DownloadHelper { ...@@ -745,14 +745,11 @@ public final class DownloadHelper {
public DownloadRequest getDownloadRequest(String id, @Nullable byte[] data) { public DownloadRequest getDownloadRequest(String id, @Nullable byte[] data) {
if (mediaSource == null) { if (mediaSource == null) {
// TODO: add support for DRM (keySetId) [Internal ref: b/158980798] // TODO: add support for DRM (keySetId) [Internal ref: b/158980798]
return new DownloadRequest( return new DownloadRequest.Builder(id, playbackProperties.uri)
id, .setMimeType(playbackProperties.mimeType)
playbackProperties.uri, .setCustomCacheKey(playbackProperties.customCacheKey)
playbackProperties.mimeType, .setData(data)
/* streamKeys= */ Collections.emptyList(), .build();
/* keySetId= */ null,
playbackProperties.customCacheKey,
data);
} }
assertPreparedWithMedia(); assertPreparedWithMedia();
List<StreamKey> streamKeys = new ArrayList<>(); List<StreamKey> streamKeys = new ArrayList<>();
...@@ -767,14 +764,12 @@ public final class DownloadHelper { ...@@ -767,14 +764,12 @@ public final class DownloadHelper {
streamKeys.addAll(mediaPreparer.mediaPeriods[periodIndex].getStreamKeys(allSelections)); streamKeys.addAll(mediaPreparer.mediaPeriods[periodIndex].getStreamKeys(allSelections));
} }
// TODO: add support for DRM (keySetId) [Internal ref: b/158980798] // TODO: add support for DRM (keySetId) [Internal ref: b/158980798]
return new DownloadRequest( return new DownloadRequest.Builder(id, playbackProperties.uri)
id, .setMimeType(playbackProperties.mimeType)
playbackProperties.uri, .setStreamKeys(streamKeys)
playbackProperties.mimeType, .setCustomCacheKey(playbackProperties.customCacheKey)
streamKeys, .setData(data)
/* keySetId= */ null, .build();
playbackProperties.customCacheKey,
data);
} }
// Initialization of array of Lists. // Initialization of array of Lists.
......
...@@ -24,6 +24,7 @@ import androidx.annotation.Nullable; ...@@ -24,6 +24,7 @@ import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableList;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -36,6 +37,64 @@ public final class DownloadRequest implements Parcelable { ...@@ -36,6 +37,64 @@ public final class DownloadRequest implements Parcelable {
/** Thrown when the encoded request data belongs to an unsupported request type. */ /** Thrown when the encoded request data belongs to an unsupported request type. */
public static class UnsupportedRequestException extends IOException {} public static class UnsupportedRequestException extends IOException {}
/** A builder for download requests. */
public static class Builder {
private final String id;
private final Uri uri;
@Nullable private String mimeType;
@Nullable private List<StreamKey> streamKeys;
@Nullable private byte[] keySetId;
@Nullable private String customCacheKey;
@Nullable private byte[] data;
/** Creates a new instance with the specified id and uri. */
public Builder(String id, Uri uri) {
this.id = id;
this.uri = uri;
}
/** Sets the {@link DownloadRequest#mimeType}. */
public Builder setMimeType(@Nullable String mimeType) {
this.mimeType = mimeType;
return this;
}
/** Sets the {@link DownloadRequest#streamKeys}. */
public Builder setStreamKeys(@Nullable List<StreamKey> streamKeys) {
this.streamKeys = streamKeys;
return this;
}
/** Sets the {@link DownloadRequest#keySetId}. */
public Builder setKeySetId(@Nullable byte[] keySetId) {
this.keySetId = keySetId;
return this;
}
/** Sets the {@link DownloadRequest#customCacheKey}. */
public Builder setCustomCacheKey(@Nullable String customCacheKey) {
this.customCacheKey = customCacheKey;
return this;
}
/** Sets the {@link DownloadRequest#data}. */
public Builder setData(@Nullable byte[] data) {
this.data = data;
return this;
}
public DownloadRequest build() {
return new DownloadRequest(
id,
uri,
mimeType,
streamKeys != null ? streamKeys : ImmutableList.of(),
keySetId,
customCacheKey,
data);
}
}
/** The unique content id. */ /** The unique content id. */
public final String id; public final String id;
/** The uri being downloaded. */ /** The uri being downloaded. */
...@@ -66,7 +125,7 @@ public final class DownloadRequest implements Parcelable { ...@@ -66,7 +125,7 @@ public final class DownloadRequest implements Parcelable {
* @param customCacheKey See {@link #customCacheKey}. * @param customCacheKey See {@link #customCacheKey}.
* @param data See {@link #data}. * @param data See {@link #data}.
*/ */
public DownloadRequest( private DownloadRequest(
String id, String id,
Uri uri, Uri uri,
@Nullable String mimeType, @Nullable String mimeType,
......
...@@ -26,7 +26,6 @@ import com.google.android.exoplayer2.util.Util; ...@@ -26,7 +26,6 @@ import com.google.android.exoplayer2.util.Util;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -126,13 +125,9 @@ public class ActionFileTest { ...@@ -126,13 +125,9 @@ public class ActionFileTest {
} }
private static DownloadRequest buildExpectedRequest(Uri uri, byte[] data) { private static DownloadRequest buildExpectedRequest(Uri uri, byte[] data) {
return new DownloadRequest( return new DownloadRequest.Builder(/* id= */ uri.toString(), uri)
/* id= */ uri.toString(), .setMimeType(MimeTypes.VIDEO_UNKNOWN)
uri, .setData(data)
/* mimeType= */ MimeTypes.VIDEO_UNKNOWN, .build();
/* streamKeys= */ Collections.emptyList(),
/* keySetId= */ null,
/* customCacheKey= */ null,
data);
} }
} }
...@@ -385,15 +385,15 @@ public class DefaultDownloadIndexTest { ...@@ -385,15 +385,15 @@ public class DefaultDownloadIndexTest {
private static Download createDownload( private static Download createDownload(
String uri, String mimeType, List<StreamKey> streamKeys, @Nullable String customCacheKey) { String uri, String mimeType, List<StreamKey> streamKeys, @Nullable String customCacheKey) {
DownloadRequest downloadRequest =
new DownloadRequest.Builder(uri, Uri.parse(uri))
.setMimeType(mimeType)
.setStreamKeys(streamKeys)
.setCustomCacheKey(customCacheKey)
.setData(new byte[] {0, 1, 2, 3})
.build();
return new Download( return new Download(
new DownloadRequest( downloadRequest,
uri,
Uri.parse(uri),
mimeType,
streamKeys,
/* keySetId= */ null,
customCacheKey,
/* data= */ new byte[] {0, 1, 2, 3}),
/* state= */ STATE_STOPPED, /* state= */ STATE_STOPPED,
/* startTimeMs= */ 1, /* startTimeMs= */ 1,
/* updateTimeMs= */ 2, /* updateTimeMs= */ 2,
......
...@@ -22,7 +22,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; ...@@ -22,7 +22,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.upstream.DummyDataSource; import com.google.android.exoplayer2.upstream.DummyDataSource;
import com.google.android.exoplayer2.upstream.cache.Cache; import com.google.android.exoplayer2.upstream.cache.Cache;
import com.google.android.exoplayer2.upstream.cache.CacheDataSource; import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
import java.util.Collections;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mockito; import org.mockito.Mockito;
...@@ -42,14 +41,8 @@ public final class DefaultDownloaderFactoryTest { ...@@ -42,14 +41,8 @@ public final class DefaultDownloaderFactoryTest {
Downloader downloader = Downloader downloader =
factory.createDownloader( factory.createDownloader(
new DownloadRequest( new DownloadRequest.Builder(/* id= */ "id", Uri.parse("https://www.test.com/download"))
/* id= */ "id", .build());
Uri.parse("https://www.test.com/download"),
/* mimeType= */ null,
/* streamKeys= */ Collections.emptyList(),
/* keySetId= */ null,
/* customCacheKey= */ null,
/* data= */ null));
assertThat(downloader).isInstanceOf(ProgressiveDownloader.class); assertThat(downloader).isInstanceOf(ProgressiveDownloader.class);
} }
} }
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.offline; package com.google.android.exoplayer2.offline;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static java.util.Arrays.asList;
import android.net.Uri; import android.net.Uri;
import androidx.annotation.GuardedBy; import androidx.annotation.GuardedBy;
...@@ -33,7 +34,6 @@ import com.google.android.exoplayer2.util.Assertions; ...@@ -33,7 +34,6 @@ import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ConditionVariable; import com.google.android.exoplayer2.util.ConditionVariable;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
...@@ -785,14 +785,9 @@ public class DownloadManagerTest { ...@@ -785,14 +785,9 @@ public class DownloadManagerTest {
} }
private static DownloadRequest createDownloadRequest(String id, StreamKey... keys) { private static DownloadRequest createDownloadRequest(String id, StreamKey... keys) {
return new DownloadRequest( return new DownloadRequest.Builder(id, Uri.parse("http://abc.com/ " + id))
id, .setStreamKeys(asList(keys))
Uri.parse("http://abc.com/ " + id), .build();
/* mimeType= */ null,
Arrays.asList(keys),
/* keySetId= */ null,
/* customCacheKey= */ null,
/* data= */ null);
} }
// Internal methods. // Internal methods.
......
...@@ -16,14 +16,13 @@ ...@@ -16,14 +16,13 @@
package com.google.android.exoplayer2.offline; package com.google.android.exoplayer2.offline;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static java.util.Arrays.asList;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import android.net.Uri; import android.net.Uri;
import android.os.Parcel; import android.os.Parcel;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -43,24 +42,10 @@ public class DownloadRequestTest { ...@@ -43,24 +42,10 @@ public class DownloadRequestTest {
@Test @Test
public void mergeRequests_withDifferentIds_fails() { public void mergeRequests_withDifferentIds_fails() {
DownloadRequest request1 =
new DownloadRequest( DownloadRequest request1 = new DownloadRequest.Builder(/* id= */ "id1", uri1).build();
/* id= */ "id1", DownloadRequest request2 = new DownloadRequest.Builder(/* id= */ "id2", uri2).build();
uri1,
/* mimeType= */ null,
/* streamKeys= */ Collections.emptyList(),
/* keySetId= */ null,
/* customCacheKey= */ null,
/* data= */ null);
DownloadRequest request2 =
new DownloadRequest(
/* id= */ "id2",
uri2,
/* mimeType= */ null,
/* streamKeys= */ Collections.emptyList(),
/* keySetId= */ null,
/* customCacheKey= */ null,
/* data= */ null);
try { try {
request1.copyWithMergedRequest(request2); request1.copyWithMergedRequest(request2);
fail(); fail();
...@@ -114,23 +99,17 @@ public class DownloadRequestTest { ...@@ -114,23 +99,17 @@ public class DownloadRequestTest {
byte[] data2 = new byte[] {9, 10, 11}; byte[] data2 = new byte[] {9, 10, 11};
DownloadRequest request1 = DownloadRequest request1 =
new DownloadRequest( new DownloadRequest.Builder(/* id= */ "id1", uri1)
/* id= */ "id1", .setKeySetId(keySetId1)
uri1, .setCustomCacheKey("key1")
/* mimeType= */ null, .setData(data1)
/* streamKeys= */ Collections.emptyList(), .build();
keySetId1,
/* customCacheKey= */ "key1",
data1);
DownloadRequest request2 = DownloadRequest request2 =
new DownloadRequest( new DownloadRequest.Builder(/* id= */ "id1", uri2)
/* id= */ "id1", .setKeySetId(keySetId2)
uri2, .setCustomCacheKey("key2")
/* mimeType= */ null, .setData(data2)
/* streamKeys= */ Collections.emptyList(), .build();
keySetId2,
/* customCacheKey= */ "key2",
data2);
// uri, keySetId, customCacheKey and data should be from the request being merged. // uri, keySetId, customCacheKey and data should be from the request being merged.
DownloadRequest mergedRequest = request1.copyWithMergedRequest(request2); DownloadRequest mergedRequest = request1.copyWithMergedRequest(request2);
...@@ -152,14 +131,12 @@ public class DownloadRequestTest { ...@@ -152,14 +131,12 @@ public class DownloadRequestTest {
streamKeys.add(new StreamKey(1, 2, 3)); streamKeys.add(new StreamKey(1, 2, 3));
streamKeys.add(new StreamKey(4, 5, 6)); streamKeys.add(new StreamKey(4, 5, 6));
DownloadRequest requestToParcel = DownloadRequest requestToParcel =
new DownloadRequest( new DownloadRequest.Builder("id", Uri.parse("https://abc.def/ghi"))
/* id= */ "id", .setStreamKeys(streamKeys)
Uri.parse("https://abc.def/ghi"), .setKeySetId(new byte[] {1, 2, 3, 4, 5})
/* mimeType= */ null, .setCustomCacheKey("key")
streamKeys, .setData(new byte[] {1, 2, 3, 4, 5})
/* keySetId= */ new byte[] {1, 2, 3, 4, 5}, .build();
/* customCacheKey= */ "key",
/* data= */ new byte[] {1, 2, 3, 4, 5});
Parcel parcel = Parcel.obtain(); Parcel parcel = Parcel.obtain();
requestToParcel.writeToParcel(parcel, 0); requestToParcel.writeToParcel(parcel, 0);
parcel.setDataPosition(0); parcel.setDataPosition(0);
...@@ -217,19 +194,6 @@ public class DownloadRequestTest { ...@@ -217,19 +194,6 @@ public class DownloadRequestTest {
} }
private static DownloadRequest createRequest(Uri uri, StreamKey... keys) { private static DownloadRequest createRequest(Uri uri, StreamKey... keys) {
return new DownloadRequest( return new DownloadRequest.Builder(uri.toString(), uri).setStreamKeys(asList(keys)).build();
uri.toString(),
uri,
/* mimeType= */ null,
toList(keys),
/* keySetId= */ null,
/* customCacheKey= */ null,
/* data= */ null);
}
private static List<StreamKey> toList(StreamKey... keys) {
ArrayList<StreamKey> keysList = new ArrayList<>();
Collections.addAll(keysList, keys);
return keysList;
} }
} }
...@@ -92,14 +92,12 @@ public class DashDownloaderTest { ...@@ -92,14 +92,12 @@ public class DashDownloaderTest {
Downloader downloader = Downloader downloader =
factory.createDownloader( factory.createDownloader(
new DownloadRequest( new DownloadRequest.Builder(/* id= */ "id", Uri.parse("https://www.test.com/download"))
"id", .setMimeType(MimeTypes.APPLICATION_MPD)
Uri.parse("https://www.test.com/download"), .setStreamKeys(
MimeTypes.APPLICATION_MPD, Collections.singletonList(
Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)), new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)))
/* keySetId= */ null, .build());
/* customCacheKey= */ null,
/* data= */ null));
assertThat(downloader).isInstanceOf(DashDownloader.class); assertThat(downloader).isInstanceOf(DashDownloader.class);
} }
......
...@@ -220,14 +220,10 @@ public class DownloadManagerDashTest { ...@@ -220,14 +220,10 @@ public class DownloadManagerDashTest {
private DownloadRequest getDownloadRequest(StreamKey... keys) { private DownloadRequest getDownloadRequest(StreamKey... keys) {
ArrayList<StreamKey> keysList = new ArrayList<>(); ArrayList<StreamKey> keysList = new ArrayList<>();
Collections.addAll(keysList, keys); Collections.addAll(keysList, keys);
return new DownloadRequest( return new DownloadRequest.Builder(TEST_ID, TEST_MPD_URI)
TEST_ID, .setMimeType(MimeTypes.APPLICATION_MPD)
TEST_MPD_URI, .setStreamKeys(keysList)
MimeTypes.APPLICATION_MPD, .build();
keysList,
/* keySetId= */ null,
/* customCacheKey= */ null,
null);
} }
private void handleRemoveAction() { private void handleRemoveAction() {
......
...@@ -206,14 +206,11 @@ public class DownloadServiceDashTest { ...@@ -206,14 +206,11 @@ public class DownloadServiceDashTest {
ArrayList<StreamKey> keysList = new ArrayList<>(); ArrayList<StreamKey> keysList = new ArrayList<>();
Collections.addAll(keysList, keys); Collections.addAll(keysList, keys);
DownloadRequest action = DownloadRequest action =
new DownloadRequest( new DownloadRequest.Builder(TEST_ID, TEST_MPD_URI)
TEST_ID, .setMimeType(MimeTypes.APPLICATION_MPD)
TEST_MPD_URI, .setStreamKeys(keysList)
MimeTypes.APPLICATION_MPD, .build();
keysList,
/* keySetId= */ null,
/* customCacheKey= */ null,
null);
testThread.runOnMainThread( testThread.runOnMainThread(
() -> { () -> {
Intent startIntent = Intent startIntent =
......
...@@ -110,14 +110,12 @@ public class HlsDownloaderTest { ...@@ -110,14 +110,12 @@ public class HlsDownloaderTest {
Downloader downloader = Downloader downloader =
factory.createDownloader( factory.createDownloader(
new DownloadRequest( new DownloadRequest.Builder(/* id= */ "id", Uri.parse("https://www.test.com/download"))
"id", .setMimeType(MimeTypes.APPLICATION_M3U8)
Uri.parse("https://www.test.com/download"), .setStreamKeys(
MimeTypes.APPLICATION_M3U8, Collections.singletonList(
Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)), new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)))
/* keySetId= */ null, .build());
/* customCacheKey= */ null,
/* data= */ null));
assertThat(downloader).isInstanceOf(HlsDownloader.class); assertThat(downloader).isInstanceOf(HlsDownloader.class);
} }
......
...@@ -48,14 +48,12 @@ public final class SsDownloaderTest { ...@@ -48,14 +48,12 @@ public final class SsDownloaderTest {
Downloader downloader = Downloader downloader =
factory.createDownloader( factory.createDownloader(
new DownloadRequest( new DownloadRequest.Builder(/* id= */ "id", Uri.parse("https://www.test.com/download"))
"id", .setMimeType(MimeTypes.APPLICATION_SS)
Uri.parse("https://www.test.com/download"), .setStreamKeys(
MimeTypes.APPLICATION_SS, Collections.singletonList(
Collections.singletonList(new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)), new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0)))
/* keySetId= */ null, .build());
/* customCacheKey= */ null,
/* data= */ null));
assertThat(downloader).isInstanceOf(SsDownloader.class); assertThat(downloader).isInstanceOf(SsDownloader.class);
} }
} }
...@@ -198,7 +198,13 @@ public final class DownloadBuilder { ...@@ -198,7 +198,13 @@ public final class DownloadBuilder {
public Download build() { public Download build() {
DownloadRequest request = DownloadRequest request =
new DownloadRequest(id, uri, mimeType, streamKeys, keySetId, cacheKey, customMetadata); new DownloadRequest.Builder(id, uri)
.setMimeType(mimeType)
.setStreamKeys(streamKeys)
.setKeySetId(keySetId)
.setCustomCacheKey(cacheKey)
.setData(customMetadata)
.build();
return new Download( return new Download(
request, request,
state, state,
......
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