我正在尝试将媒体从手机播放到 ExoPlayer。我正在从Environment.getExternalStorageDirectory().getAbsoluteFile();
每当我尝试播放媒体时-我都会收到此错误-
源错误 com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException:无法连接到 /storage/emulated/0/Download/big_buck_bunny_720p_1mb.mp4
还,
引起:java.net.MalformedURLException:无协议:/storage/emulated/0/Download/big_buck_bunny_720p_1mb.mp4
我在这里经过 UriMediaSource mediaSource = buildMediaSource(Uri.parse(link));
此方法使用 Uri
private MediaSource buildMediaSource(Uri uri) {
DataSource.Factory dataSourceFactory = new
DefaultHttpDataSourceFactory("ua", BANDWIDTH_METER);
DashChunkSource.Factory dashChunkSourceFactory = new
DefaultDashChunkSource.Factory(dataSourceFactory);
return new DashMediaSource(uri, dataSourceFactory,
dashChunkSourceFactory, null, null);
}
这就是我获取链接的方式
arrayList1 = video(Environment.getExternalStorageDirectory().getAbsoluteFile());
protected ArrayList<File> video(File file) {
File[] filename = file.listFiles();
ArrayList<File> arrayList2 = new ArrayList<File>();
try {
for (File file1 : filename) {
if (file1.isDirectory()) {
arrayList2.addAll(video(file1));
} else {
if (file1.getName().endsWith(".mp4")) {
arrayList2.add(file1);
}
}
}
}catch (Exception e){
}
return arrayList2;
}