mirror of
https://github.com/androidx/media.git
synced 2025-05-14 11:09:53 +08:00
Merge pull request #3719 from eneim/improve/raw-resource
Improve raw resource data source (recreated)
This commit is contained in:
commit
13b46dab93
@ -31,6 +31,9 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
* /path/to/media/media.mp4 because the implementation assumes that a URI without a scheme is a
|
* /path/to/media/media.mp4 because the implementation assumes that a URI without a scheme is a
|
||||||
* local file URI).
|
* local file URI).
|
||||||
* <li>asset: For fetching data from an asset in the application's apk (e.g. asset:///media.mp4).
|
* <li>asset: For fetching data from an asset in the application's apk (e.g. asset:///media.mp4).
|
||||||
|
* <li>rawresource: For fetching data from a raw resource in the applications' apk
|
||||||
|
* (e.g. rawresource:///resourceId, where rawResourceId is the integer identifier of the raw
|
||||||
|
* resource).</li>
|
||||||
* <li>content: For fetching data from a content URI (e.g. content://authority/path/123).
|
* <li>content: For fetching data from a content URI (e.g. content://authority/path/123).
|
||||||
* <li>rtmp: For fetching data over RTMP. Only supported if the project using ExoPlayer has an
|
* <li>rtmp: For fetching data over RTMP. Only supported if the project using ExoPlayer has an
|
||||||
* explicit dependency on ExoPlayer's RTMP extension.</li>
|
* explicit dependency on ExoPlayer's RTMP extension.</li>
|
||||||
@ -48,6 +51,7 @@ public final class DefaultDataSource implements DataSource {
|
|||||||
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";
|
||||||
private static final String SCHEME_RTMP = "rtmp";
|
private static final String SCHEME_RTMP = "rtmp";
|
||||||
|
private static final String SCHEME_RAW = RawResourceDataSource.RAW_RESOURCE_SCHEME;
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private final TransferListener<? super DataSource> listener;
|
private final TransferListener<? super DataSource> listener;
|
||||||
@ -60,6 +64,7 @@ public final class DefaultDataSource implements DataSource {
|
|||||||
private DataSource contentDataSource;
|
private DataSource contentDataSource;
|
||||||
private DataSource rtmpDataSource;
|
private DataSource rtmpDataSource;
|
||||||
private DataSource dataSchemeDataSource;
|
private DataSource dataSchemeDataSource;
|
||||||
|
private DataSource rawResourceDataSource;
|
||||||
|
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
@ -134,6 +139,8 @@ public final class DefaultDataSource implements DataSource {
|
|||||||
dataSource = getRtmpDataSource();
|
dataSource = getRtmpDataSource();
|
||||||
} else if (DataSchemeDataSource.SCHEME_DATA.equals(scheme)) {
|
} else if (DataSchemeDataSource.SCHEME_DATA.equals(scheme)) {
|
||||||
dataSource = getDataSchemeDataSource();
|
dataSource = getDataSchemeDataSource();
|
||||||
|
} else if (SCHEME_RAW.equals(scheme)) {
|
||||||
|
dataSource = getRawResourceDataSource();
|
||||||
} else {
|
} else {
|
||||||
dataSource = baseDataSource;
|
dataSource = baseDataSource;
|
||||||
}
|
}
|
||||||
@ -213,4 +220,10 @@ public final class DefaultDataSource implements DataSource {
|
|||||||
return dataSchemeDataSource;
|
return dataSchemeDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DataSource getRawResourceDataSource() {
|
||||||
|
if (rawResourceDataSource == null) {
|
||||||
|
rawResourceDataSource = new RawResourceDataSource(context, listener);
|
||||||
|
}
|
||||||
|
return rawResourceDataSource;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public final class RawResourceDataSource implements DataSource {
|
|||||||
return Uri.parse(RAW_RESOURCE_SCHEME + ":///" + rawResourceId);
|
return Uri.parse(RAW_RESOURCE_SCHEME + ":///" + rawResourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String RAW_RESOURCE_SCHEME = "rawresource";
|
public static final String RAW_RESOURCE_SCHEME = "rawresource";
|
||||||
|
|
||||||
private final Resources resources;
|
private final Resources resources;
|
||||||
private final TransferListener<? super RawResourceDataSource> listener;
|
private final TransferListener<? super RawResourceDataSource> listener;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user