Create MPD file from String

对着背影说爱祢 提交于 2019-12-11 21:17:27

问题


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).

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?


回答1:


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.

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) Static mpd on local disk

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) in-memory manifest

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());
    }
};


来源:https://stackoverflow.com/questions/48626074/create-mpd-file-from-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!