ContentDataSource: Restore ability to open file URIs

PiperOrigin-RevId: 388410558
This commit is contained in:
olly 2021-08-03 10:36:57 +01:00 committed by Andrew Lewis
parent f329adbc23
commit bffa3e0afb

View File

@ -79,16 +79,22 @@ public final class ContentDataSource extends BaseDataSource {
transferInitializing(dataSpec); transferInitializing(dataSpec);
Bundle providerOptions = new Bundle(); AssetFileDescriptor assetFileDescriptor;
if (Util.SDK_INT >= 31) { if ("content".equals(dataSpec.uri.getScheme())) {
Api31.disableTranscoding(providerOptions); Bundle providerOptions = new Bundle();
if (Util.SDK_INT >= 31) {
Api31.disableTranscoding(providerOptions);
}
assetFileDescriptor =
resolver.openTypedAssetFileDescriptor(uri, /* mimeType= */ "*/*", providerOptions);
} else {
// This path supports file URIs, although support may be removed in the future. See
// [Internal ref: b/195384732].
assetFileDescriptor = resolver.openAssetFileDescriptor(uri, "r");
} }
AssetFileDescriptor assetFileDescriptor =
resolver.openTypedAssetFileDescriptor(uri, /* mimeType= */ "*/*", providerOptions);
this.assetFileDescriptor = assetFileDescriptor; this.assetFileDescriptor = assetFileDescriptor;
if (assetFileDescriptor == null) { if (assetFileDescriptor == null) {
// openTypedAssetFileDescriptor returns null if the provider recently crashed. // assetFileDescriptor may be null if the provider recently crashed.
throw new ContentDataSourceException( throw new ContentDataSourceException(
new IOException("Could not open file descriptor for: " + uri), new IOException("Could not open file descriptor for: " + uri),
PlaybackException.ERROR_CODE_IO_UNSPECIFIED); PlaybackException.ERROR_CODE_IO_UNSPECIFIED);