问题
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