mirror of
https://github.com/androidx/media.git
synced 2025-04-29 22:36:54 +08:00
Remove some hard-coding of file
and content
URI schemes
PiperOrigin-RevId: 751417429
This commit is contained in:
parent
fe59718805
commit
8bf658cd79
@ -47,6 +47,7 @@ import android.app.Service;
|
|||||||
import android.app.UiModeManager;
|
import android.app.UiModeManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
@ -419,7 +420,8 @@ public final class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isMediaStoreExternalContentUri(Uri uri) {
|
private static boolean isMediaStoreExternalContentUri(Uri uri) {
|
||||||
if (!"content".equals(uri.getScheme()) || !MediaStore.AUTHORITY.equals(uri.getAuthority())) {
|
if (!Objects.equals(uri.getScheme(), ContentResolver.SCHEME_CONTENT)
|
||||||
|
|| !Objects.equals(uri.getAuthority(), MediaStore.AUTHORITY)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List<String> pathSegments = uri.getPathSegments();
|
List<String> pathSegments = uri.getPathSegments();
|
||||||
@ -467,7 +469,7 @@ public final class Util {
|
|||||||
@UnstableApi
|
@UnstableApi
|
||||||
public static boolean isLocalFileUri(Uri uri) {
|
public static boolean isLocalFileUri(Uri uri) {
|
||||||
String scheme = uri.getScheme();
|
String scheme = uri.getScheme();
|
||||||
return TextUtils.isEmpty(scheme) || "file".equals(scheme);
|
return TextUtils.isEmpty(scheme) || Objects.equals(scheme, ContentResolver.SCHEME_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns true if the code path is currently running on an emulator. */
|
/** Returns true if the code path is currently running on an emulator. */
|
||||||
|
@ -32,6 +32,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/** A {@link DataSource} for reading from a content URI. */
|
/** A {@link DataSource} for reading from a content URI. */
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
@ -81,7 +82,7 @@ public final class ContentDataSource extends BaseDataSource {
|
|||||||
transferInitializing(dataSpec);
|
transferInitializing(dataSpec);
|
||||||
|
|
||||||
AssetFileDescriptor assetFileDescriptor;
|
AssetFileDescriptor assetFileDescriptor;
|
||||||
if ("content".equals(uri.getScheme())) {
|
if (Objects.equals(uri.getScheme(), ContentResolver.SCHEME_CONTENT)) {
|
||||||
Bundle providerOptions = new Bundle();
|
Bundle providerOptions = new Bundle();
|
||||||
// We don't want compatible media transcoding.
|
// We don't want compatible media transcoding.
|
||||||
providerOptions.putBoolean(MediaStore.EXTRA_ACCEPT_ORIGINAL_MEDIA_FORMAT, true);
|
providerOptions.putBoolean(MediaStore.EXTRA_ACCEPT_ORIGINAL_MEDIA_FORMAT, true);
|
||||||
|
@ -122,7 +122,7 @@ public final class DefaultDataSource implements DataSource {
|
|||||||
private static final String TAG = "DefaultDataSource";
|
private static final String TAG = "DefaultDataSource";
|
||||||
|
|
||||||
private static final String SCHEME_ASSET = "asset";
|
private static final String SCHEME_ASSET = "asset";
|
||||||
private static final String SCHEME_CONTENT = "content";
|
private static final String SCHEME_CONTENT = ContentResolver.SCHEME_CONTENT;
|
||||||
private static final String SCHEME_RTMP = "rtmp";
|
private static final String SCHEME_RTMP = "rtmp";
|
||||||
private static final String SCHEME_UDP = "udp";
|
private static final String SCHEME_UDP = "udp";
|
||||||
private static final String SCHEME_DATA = DataSchemeDataSource.SCHEME_DATA;
|
private static final String SCHEME_DATA = DataSchemeDataSource.SCHEME_DATA;
|
||||||
|
@ -46,6 +46,7 @@ import androidx.media3.common.util.Assertions;
|
|||||||
import androidx.media3.common.util.Log;
|
import androidx.media3.common.util.Log;
|
||||||
import androidx.media3.common.util.MediaFormatUtil;
|
import androidx.media3.common.util.MediaFormatUtil;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.datasource.DataSource;
|
import androidx.media3.datasource.DataSource;
|
||||||
import androidx.media3.datasource.DataSourceUtil;
|
import androidx.media3.datasource.DataSourceUtil;
|
||||||
import androidx.media3.datasource.DataSpec;
|
import androidx.media3.datasource.DataSpec;
|
||||||
@ -287,11 +288,8 @@ public final class MediaExtractorCompat {
|
|||||||
*/
|
*/
|
||||||
public void setDataSource(Context context, Uri uri, @Nullable Map<String, String> headers)
|
public void setDataSource(Context context, Uri uri, @Nullable Map<String, String> headers)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
String scheme = uri.getScheme();
|
if (Util.isLocalFileUri(uri)) {
|
||||||
String path = uri.getPath();
|
setDataSource(checkNotNull(uri.getPath()));
|
||||||
if ((scheme == null || scheme.equals("file")) && path != null) {
|
|
||||||
// If the URI scheme is null or file, treat it as a local file path
|
|
||||||
setDataSource(path);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user