mirror of
https://github.com/androidx/media.git
synced 2025-05-04 06:00:37 +08:00
DefaultDownloaderFactory: upgrade deprecated call
Replace the use of Downloader deprecrated constructor calls. PiperOrigin-RevId: 322357118
This commit is contained in:
parent
d77ce9eda0
commit
6ace2c9460
@ -51,15 +51,15 @@
|
|||||||
# Constructors accessed via reflection in DefaultDownloaderFactory
|
# Constructors accessed via reflection in DefaultDownloaderFactory
|
||||||
-dontnote com.google.android.exoplayer2.source.dash.offline.DashDownloader
|
-dontnote com.google.android.exoplayer2.source.dash.offline.DashDownloader
|
||||||
-keepclassmembers class com.google.android.exoplayer2.source.dash.offline.DashDownloader {
|
-keepclassmembers class com.google.android.exoplayer2.source.dash.offline.DashDownloader {
|
||||||
<init>(android.net.Uri, java.util.List, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
|
<init>(com.google.android.exoplayer2.MediaItem, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
|
||||||
}
|
}
|
||||||
-dontnote com.google.android.exoplayer2.source.hls.offline.HlsDownloader
|
-dontnote com.google.android.exoplayer2.source.hls.offline.HlsDownloader
|
||||||
-keepclassmembers class com.google.android.exoplayer2.source.hls.offline.HlsDownloader {
|
-keepclassmembers class com.google.android.exoplayer2.source.hls.offline.HlsDownloader {
|
||||||
<init>(android.net.Uri, java.util.List, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
|
<init>(com.google.android.exoplayer2.MediaItem, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
|
||||||
}
|
}
|
||||||
-dontnote com.google.android.exoplayer2.source.smoothstreaming.offline.SsDownloader
|
-dontnote com.google.android.exoplayer2.source.smoothstreaming.offline.SsDownloader
|
||||||
-keepclassmembers class com.google.android.exoplayer2.source.smoothstreaming.offline.SsDownloader {
|
-keepclassmembers class com.google.android.exoplayer2.source.smoothstreaming.offline.SsDownloader {
|
||||||
<init>(android.net.Uri, java.util.List, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
|
<init>(com.google.android.exoplayer2.MediaItem, com.google.android.exoplayer2.upstream.cache.CacheDataSource$Factory, java.util.concurrent.Executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Constructors accessed via reflection in DefaultMediaSourceFactory
|
# Constructors accessed via reflection in DefaultMediaSourceFactory
|
||||||
|
@ -304,6 +304,8 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void putDownloadInternal(Download download, SQLiteDatabase database) {
|
private void putDownloadInternal(Download download, SQLiteDatabase database) {
|
||||||
|
byte[] keySetId =
|
||||||
|
download.request.keySetId == null ? Util.EMPTY_BYTE_ARRAY : download.request.keySetId;
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(COLUMN_ID, download.request.id);
|
values.put(COLUMN_ID, download.request.id);
|
||||||
values.put(COLUMN_MIME_TYPE, download.request.mimeType);
|
values.put(COLUMN_MIME_TYPE, download.request.mimeType);
|
||||||
@ -319,7 +321,7 @@ public final class DefaultDownloadIndex implements WritableDownloadIndex {
|
|||||||
values.put(COLUMN_FAILURE_REASON, download.failureReason);
|
values.put(COLUMN_FAILURE_REASON, download.failureReason);
|
||||||
values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded());
|
values.put(COLUMN_PERCENT_DOWNLOADED, download.getPercentDownloaded());
|
||||||
values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded());
|
values.put(COLUMN_BYTES_DOWNLOADED, download.getBytesDownloaded());
|
||||||
values.put(COLUMN_KEY_SET_ID, download.request.keySetId);
|
values.put(COLUMN_KEY_SET_ID, keySetId);
|
||||||
database.replaceOrThrow(tableName, /* nullColumnHack= */ null, values);
|
database.replaceOrThrow(tableName, /* nullColumnHack= */ null, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,13 +432,14 @@ 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);
|
||||||
DownloadRequest request =
|
DownloadRequest request =
|
||||||
new DownloadRequest(
|
new DownloadRequest(
|
||||||
/* 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),
|
/* mimeType= */ cursor.getString(COLUMN_INDEX_MIME_TYPE),
|
||||||
/* streamKeys= */ decodeStreamKeys(cursor.getString(COLUMN_INDEX_STREAM_KEYS)),
|
/* streamKeys= */ decodeStreamKeys(cursor.getString(COLUMN_INDEX_STREAM_KEYS)),
|
||||||
/* keySetId= */ cursor.getBlob(COLUMN_INDEX_KEY_SET_ID),
|
/* keySetId= */ keySetId.length > 0 ? keySetId : null,
|
||||||
/* customCacheKey= */ cursor.getString(COLUMN_INDEX_CUSTOM_CACHE_KEY),
|
/* customCacheKey= */ cursor.getString(COLUMN_INDEX_CUSTOM_CACHE_KEY),
|
||||||
/* data= */ cursor.getBlob(COLUMN_INDEX_DATA));
|
/* data= */ cursor.getBlob(COLUMN_INDEX_DATA));
|
||||||
DownloadProgress downloadProgress = new DownloadProgress();
|
DownloadProgress downloadProgress = new DownloadProgress();
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.offline;
|
package com.google.android.exoplayer2.offline;
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
@ -24,7 +23,6 @@ import com.google.android.exoplayer2.upstream.cache.CacheDataSource;
|
|||||||
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 java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -95,9 +93,15 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
|
|||||||
if (constructor == null) {
|
if (constructor == null) {
|
||||||
throw new IllegalStateException("Module missing for content type " + contentType);
|
throw new IllegalStateException("Module missing for content type " + contentType);
|
||||||
}
|
}
|
||||||
|
MediaItem mediaItem =
|
||||||
|
new MediaItem.Builder()
|
||||||
|
.setUri(request.uri)
|
||||||
|
.setStreamKeys(request.streamKeys)
|
||||||
|
.setCustomCacheKey(request.customCacheKey)
|
||||||
|
.setDrmKeySetId(request.keySetId)
|
||||||
|
.build();
|
||||||
try {
|
try {
|
||||||
return constructor.newInstance(
|
return constructor.newInstance(mediaItem, cacheDataSourceFactory, executor);
|
||||||
request.uri, request.streamKeys, cacheDataSourceFactory, executor);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Failed to instantiate downloader for content type " + contentType);
|
"Failed to instantiate downloader for content type " + contentType);
|
||||||
@ -140,7 +144,7 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
|
|||||||
try {
|
try {
|
||||||
return clazz
|
return clazz
|
||||||
.asSubclass(Downloader.class)
|
.asSubclass(Downloader.class)
|
||||||
.getConstructor(Uri.class, List.class, CacheDataSource.Factory.class, Executor.class);
|
.getConstructor(MediaItem.class, CacheDataSource.Factory.class, Executor.class);
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
// The downloader is present, but the expected constructor is missing.
|
// The downloader is present, but the expected constructor is missing.
|
||||||
throw new IllegalStateException("Downloader constructor missing", e);
|
throw new IllegalStateException("Downloader constructor missing", e);
|
||||||
|
@ -48,11 +48,8 @@ public final class DownloadRequest implements Parcelable {
|
|||||||
@Nullable public final String mimeType;
|
@Nullable public final String mimeType;
|
||||||
/** Stream keys to be downloaded. If empty, all streams will be downloaded. */
|
/** Stream keys to be downloaded. If empty, all streams will be downloaded. */
|
||||||
public final List<StreamKey> streamKeys;
|
public final List<StreamKey> streamKeys;
|
||||||
/**
|
/** The key set id of the offline licence if the content is protected with DRM. */
|
||||||
* The key set id of the offline licence if the content is protected with DRM, or empty if no
|
@Nullable public final byte[] keySetId;
|
||||||
* license is needed.
|
|
||||||
*/
|
|
||||||
public final byte[] keySetId;
|
|
||||||
/**
|
/**
|
||||||
* Custom key for cache indexing, or null. Must be null for DASH, HLS and SmoothStreaming
|
* Custom key for cache indexing, or null. Must be null for DASH, HLS and SmoothStreaming
|
||||||
* downloads.
|
* downloads.
|
||||||
@ -88,8 +85,7 @@ public final class DownloadRequest implements Parcelable {
|
|||||||
ArrayList<StreamKey> mutableKeys = new ArrayList<>(streamKeys);
|
ArrayList<StreamKey> mutableKeys = new ArrayList<>(streamKeys);
|
||||||
Collections.sort(mutableKeys);
|
Collections.sort(mutableKeys);
|
||||||
this.streamKeys = Collections.unmodifiableList(mutableKeys);
|
this.streamKeys = Collections.unmodifiableList(mutableKeys);
|
||||||
this.keySetId =
|
this.keySetId = keySetId != null ? Arrays.copyOf(keySetId, keySetId.length) : null;
|
||||||
keySetId != null ? Arrays.copyOf(keySetId, keySetId.length) : Util.EMPTY_BYTE_ARRAY;
|
|
||||||
this.customCacheKey = customCacheKey;
|
this.customCacheKey = customCacheKey;
|
||||||
this.data = data != null ? Arrays.copyOf(data, data.length) : Util.EMPTY_BYTE_ARRAY;
|
this.data = data != null ? Arrays.copyOf(data, data.length) : Util.EMPTY_BYTE_ARRAY;
|
||||||
}
|
}
|
||||||
@ -104,7 +100,7 @@ public final class DownloadRequest implements Parcelable {
|
|||||||
mutableStreamKeys.add(in.readParcelable(StreamKey.class.getClassLoader()));
|
mutableStreamKeys.add(in.readParcelable(StreamKey.class.getClassLoader()));
|
||||||
}
|
}
|
||||||
streamKeys = Collections.unmodifiableList(mutableStreamKeys);
|
streamKeys = Collections.unmodifiableList(mutableStreamKeys);
|
||||||
keySetId = castNonNull(in.createByteArray());
|
keySetId = in.createByteArray();
|
||||||
customCacheKey = in.readString();
|
customCacheKey = in.readString();
|
||||||
data = castNonNull(in.createByteArray());
|
data = castNonNull(in.createByteArray());
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public final class DownloadBuilder {
|
|||||||
private Uri uri;
|
private Uri uri;
|
||||||
@Nullable private String mimeType;
|
@Nullable private String mimeType;
|
||||||
private List<StreamKey> streamKeys;
|
private List<StreamKey> streamKeys;
|
||||||
private byte[] keySetId;
|
@Nullable private byte[] keySetId;
|
||||||
@Nullable private String cacheKey;
|
@Nullable private String cacheKey;
|
||||||
private byte[] customMetadata;
|
private byte[] customMetadata;
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ public final class DownloadBuilder {
|
|||||||
Uri.parse("uri"),
|
Uri.parse("uri"),
|
||||||
/* mimeType= */ null,
|
/* mimeType= */ null,
|
||||||
/* streamKeys= */ Collections.emptyList(),
|
/* streamKeys= */ Collections.emptyList(),
|
||||||
/* keySetId= */ new byte[0],
|
/* keySetId= */ null,
|
||||||
/* cacheKey= */ null,
|
/* cacheKey= */ null,
|
||||||
/* customMetadata= */ new byte[0]);
|
/* customMetadata= */ new byte[0]);
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ public final class DownloadBuilder {
|
|||||||
Uri uri,
|
Uri uri,
|
||||||
@Nullable String mimeType,
|
@Nullable String mimeType,
|
||||||
List<StreamKey> streamKeys,
|
List<StreamKey> streamKeys,
|
||||||
byte[] keySetId,
|
@Nullable byte[] keySetId,
|
||||||
@Nullable String cacheKey,
|
@Nullable String cacheKey,
|
||||||
byte[] customMetadata) {
|
byte[] customMetadata) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user