Added a isLocalFileUrlOrPath(Uri) method to remove manual checks
Also replaced the manual checks with a call to this method
This commit is contained in:
parent
c667feca4b
commit
cdb6ac4073
@ -293,15 +293,12 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean uriIsLocalFile(Uri uri) {
|
|
||||||
return URI_FILE_SCHEME.equals(uri.getScheme()) || TextUtils.isEmpty(uri.getScheme());
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(23)
|
@TargetApi(23)
|
||||||
private boolean requiresPermission(Uri uri) {
|
private boolean requiresPermission(Uri uri) {
|
||||||
return Util.SDK_INT >= 23 && uriIsLocalFile(uri)
|
return Util.SDK_INT >= 23
|
||||||
|
&& Util.isLocalFileUri(uri)
|
||||||
&& checkSelfPermission(permission.READ_EXTERNAL_STORAGE)
|
&& checkSelfPermission(permission.READ_EXTERNAL_STORAGE)
|
||||||
!= PackageManager.PERMISSION_GRANTED;
|
!= PackageManager.PERMISSION_GRANTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal methods
|
// Internal methods
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
package com.google.android.exoplayer.upstream;
|
package com.google.android.exoplayer.upstream;
|
||||||
|
|
||||||
import com.google.android.exoplayer.util.Assertions;
|
import com.google.android.exoplayer.util.Assertions;
|
||||||
|
import com.google.android.exoplayer.util.Util;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -36,7 +36,6 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public final class DefaultUriDataSource implements UriDataSource {
|
public final class DefaultUriDataSource implements UriDataSource {
|
||||||
|
|
||||||
private static final String SCHEME_FILE = "file";
|
|
||||||
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 = "content";
|
||||||
|
|
||||||
@ -119,7 +118,7 @@ public final class DefaultUriDataSource implements UriDataSource {
|
|||||||
Assertions.checkState(dataSource == null);
|
Assertions.checkState(dataSource == null);
|
||||||
// Choose the correct source for the scheme.
|
// Choose the correct source for the scheme.
|
||||||
String scheme = dataSpec.uri.getScheme();
|
String scheme = dataSpec.uri.getScheme();
|
||||||
if (SCHEME_FILE.equals(scheme) || TextUtils.isEmpty(scheme)) {
|
if (Util.isLocalFileUri(dataSpec.uri)) {
|
||||||
if (dataSpec.uri.getPath().startsWith("/android_asset/")) {
|
if (dataSpec.uri.getPath().startsWith("/android_asset/")) {
|
||||||
dataSource = assetDataSource;
|
dataSource = assetDataSource;
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,6 +25,7 @@ import android.content.Context;
|
|||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@ -106,12 +107,13 @@ public final class Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the URL points to a file on the local device
|
* Returns true if the URI is a path to a local file or a reference to a local file.
|
||||||
*
|
*
|
||||||
* @param url The URL to test
|
* @param uri The uri to test.
|
||||||
*/
|
*/
|
||||||
public static boolean isUrlLocalFile(URL url) {
|
public static boolean isLocalFileUri(Uri uri) {
|
||||||
return url.getProtocol().equals("file");
|
String scheme = uri.getScheme();
|
||||||
|
return TextUtils.isEmpty(scheme) || scheme.equals("file");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user