未验证 提交 13b46dab 编写于 作者: O ojw28 提交者: GitHub

Merge pull request #3719 from eneim/improve/raw-resource

Improve raw resource data source (recreated)
......@@ -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
* local file URI).
* <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>rtmp: For fetching data over RTMP. Only supported if the project using ExoPlayer has an
* 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_CONTENT = "content";
private static final String SCHEME_RTMP = "rtmp";
private static final String SCHEME_RAW = RawResourceDataSource.RAW_RESOURCE_SCHEME;
private final Context context;
private final TransferListener<? super DataSource> listener;
......@@ -60,6 +64,7 @@ public final class DefaultDataSource implements DataSource {
private DataSource contentDataSource;
private DataSource rtmpDataSource;
private DataSource dataSchemeDataSource;
private DataSource rawResourceDataSource;
private DataSource dataSource;
......@@ -134,6 +139,8 @@ public final class DefaultDataSource implements DataSource {
dataSource = getRtmpDataSource();
} else if (DataSchemeDataSource.SCHEME_DATA.equals(scheme)) {
dataSource = getDataSchemeDataSource();
} else if (SCHEME_RAW.equals(scheme)) {
dataSource = getRawResourceDataSource();
} else {
dataSource = baseDataSource;
}
......@@ -213,4 +220,10 @@ public final class DefaultDataSource implements DataSource {
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);
}
private static final String RAW_RESOURCE_SCHEME = "rawresource";
public static final String RAW_RESOURCE_SCHEME = "rawresource";
private final Resources resources;
private final TransferListener<? super RawResourceDataSource> listener;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册