ExoPlayer:Uri:无法加载本地媒体Android

Avi*_*ran 1 android exoplayer exoplayer2.x

我正在尝试将手机中的媒体播放到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

我在这里经过乌里 MediaSource 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);
}
Run Code Online (Sandbox Code Playgroud)

这就是我获得链接的方式

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;
}
Run Code Online (Sandbox Code Playgroud)

mar*_*ger 5

使用FileDataSource。以下代码段通过资产uri(例如file:///android_asset/video.mp4或其他文件uri)为mp4创建MediaSource:

  private MediaSource buildMediaSource(Uri uri) {
    DataSource.Factory dataSourceFactory = new FileDataSourceFactory();
    return new ExtractorMediaSource(uri, dataSourceFactory, 
        new DefaultExtractorsFactory(), null, null);
  }
Run Code Online (Sandbox Code Playgroud)