从字符串创建MPD文件 [英] Create MPD file from String
问题描述
我设法创建了一个MPD文件,当通过URL将其馈送到 ExoPlayer 2.6.0 时,该文件可以完美播放(该MPD托管在测试服务器中).
I've managed to create a MPD file that is perfectly playable when fed to ExoPlayer 2.6.0 via an URL (the MPD is hosted in a testing server).
但是,我需要在Android中创建此MPD文件并将其提供给ExoPlayer,而无需向服务器请求该文件.到目前为止,我已经尝试理解DashManifest& DashManifestParser没有成功.有什么想法如何在Android中创建文件并将其直接提供给ExoPlayer吗?
However, I need to create this MPD file in Android and feed it to ExoPlayer without requesting the file to the server. So far I've tried to understand the classes DashManifest & DashManifestParser with no success. Any ideas how to create the file in Android and feed it directly to ExoPlayer?
推荐答案
播放DASH流时,您需要创建DashMediaSource.Factory.第一个参数是DashChunkSource,它读取清单定义的媒体文件.第二个参数是用于读取清单的DataSource.Factory.
When playing an DASH stream you need to create a DashMediaSource.Factory. The first parameter is the DashChunkSource which reads the media files defined by your manifest. The second parameter is the DataSource.Factory to read the manifest.
因此,您需要提供一个DataSource.Factory,它创建一个DataSource来读取清单.请参见以下代码段中的manifestDataSourceFactory
:
So you need to provide a DataSource.Factory which creates a DataSource to read your manifest. See the manifestDataSourceFactory
in the snippet below:
DashMediaSource.Factory dashMediaSourceFactory = new DashMediaSource.Factory(
new DefaultDashChunkSource.Factory(mediaDataSourceFactory),
manifestDataSourceFactory);
dashMediaSourceFactory.createMediaSource(manifestUri);
a)本地磁盘上的静态mpd
如果清单存储为本地文件,则可以使用DefaultDataSourceFactory并将文件路径作为manifestUri
传递:
If your manifest is stored as a local file you can use a DefaultDataSourceFactory and pass the file path as the manifestUri
:
DataSource.Factory manifestDataSourceFactory = new DefaultDataSourceFactory(context, userAgent);
b)内存清单
如果清单在内存中,则可以为ByteArrayDataSource提供一个自定义DataSource.Factory:
If your manifest is in memory you can provide a ByteArrayDataSource with a custom DataSource.Factory:
DataSource.Factory manifestDataSourceFactory = new DataSource.Factory() {
@Override
public DataSource createDataSource() {
return new ByteArrayDataSource(manifestString.getBytes());
}
};
这篇关于从字符串创建MPD文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!