我正在尝试使用HLSDownloader下载hls文件,但是我没有得到最好的结果。我的代码:
// Main download function
AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
downloadHls(VIDEO_URL);
return null;
}
};
asyncTask.execute();
...
// This is the main tool to download hls
private HlsDownloader hlsDownloader;
private void downloadHls(String masterHLS) {
hlsDownloader = getHlsDownloader(masterHLS);
try {
hlsDownloader.download(this);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private HlsDownloader getHlsDownloader(String mediaPlaylistUri) {
File downloadFolder = new File(getFilesDir(), "video_id_2");
SimpleCache cache = new SimpleCache(downloadFolder, new NoOpCacheEvictor());
DefaultHttpDataSourceFactory factory = new DefaultHttpDataSourceFactory("ExoPlayer", null);
CacheDataSource cacheDataSource =
new CacheDataSource(cache, factory.createDataSource(), CacheDataSource.FLAG_BLOCK_ON_CACHE);
// Create a downloader for the first variant in a master playlist.
return new HlsDownloader(
Uri.parse(mediaPlaylistUri), new DownloaderConstructorHelper(cache, factory));
}
似乎下载开始,并且我正在下载,但是我无法访问下载的文件(也许不存在),所以我不知道我的编码是否正确。一些帮助,将不胜感激。
已编辑
:目前,我已经下载了多个文件块(我忘记在清单中添加写许可权),所有文件都命名为* .ve.exo扩展文件,但我不知道如何播放它们,有什么主意吗?