Allow content id to be set in DownloadHelper.getDownloadRequest

PiperOrigin-RevId: 245388082
This commit is contained in:
eguven 2019-04-26 10:25:21 +01:00 committed by Oliver Woodman
parent 249f6a77ee
commit c97ee9429b

View File

@ -578,16 +578,27 @@ public final class DownloadHelper {
/** /**
* Builds a {@link DownloadRequest} for downloading the selected tracks. Must not be called until * Builds a {@link DownloadRequest} for downloading the selected tracks. Must not be called until
* after preparation completes. * after preparation completes. The uri of the {@link DownloadRequest} will be used as content id.
* *
* @param data Application provided data to store in {@link DownloadRequest#data}. * @param data Application provided data to store in {@link DownloadRequest#data}.
* @return The built {@link DownloadRequest}. * @return The built {@link DownloadRequest}.
*/ */
public DownloadRequest getDownloadRequest(@Nullable byte[] data) { public DownloadRequest getDownloadRequest(@Nullable byte[] data) {
String downloadId = uri.toString(); return getDownloadRequest(uri.toString(), data);
}
/**
* Builds a {@link DownloadRequest} for downloading the selected tracks. Must not be called until
* after preparation completes.
*
* @param id The unique content id.
* @param data Application provided data to store in {@link DownloadRequest#data}.
* @return The built {@link DownloadRequest}.
*/
public DownloadRequest getDownloadRequest(String id, @Nullable byte[] data) {
if (mediaSource == null) { if (mediaSource == null) {
return new DownloadRequest( return new DownloadRequest(
downloadId, downloadType, uri, /* streamKeys= */ Collections.emptyList(), cacheKey, data); id, downloadType, uri, /* streamKeys= */ Collections.emptyList(), cacheKey, data);
} }
assertPreparedWithMedia(); assertPreparedWithMedia();
List<StreamKey> streamKeys = new ArrayList<>(); List<StreamKey> streamKeys = new ArrayList<>();
@ -601,7 +612,7 @@ public final class DownloadHelper {
} }
streamKeys.addAll(mediaPreparer.mediaPeriods[periodIndex].getStreamKeys(allSelections)); streamKeys.addAll(mediaPreparer.mediaPeriods[periodIndex].getStreamKeys(allSelections));
} }
return new DownloadRequest(downloadId, downloadType, uri, streamKeys, cacheKey, data); return new DownloadRequest(id, downloadType, uri, streamKeys, cacheKey, data);
} }
// Initialization of array of Lists. // Initialization of array of Lists.