VLC:无法播放来自getExternalStorageDirectory()的视频

时间:2017-08-15 08:23:26

标签: android video file-permissions

我已将我的视频文件保存到我的存储空间,并试图通过使用Intent从我的应用程序播放视频..在其他播放器文件播放正常,但当我尝试使用VLC播放该文件时,它会出现以下错误; < / p>

  

播放错误Vlc遇到此媒体的错误。请试试   刷新媒体库。

  

无法播放位置/storage/emulated/0/myFolder/file.mov。

保存方法

private String SaveToDir(String DownloadUrl) {

    try {

        File dir = new File(Environment
                .getExternalStorageDirectory(),
                "myFolder");
        if (dir.exists() == false) {
            dir.mkdirs();
        }

        URL url = new URL(DownloadUrl);
        String fileName = DownloadUrl.substring(DownloadUrl.lastIndexOf('/') + 1);
        File file = new File(dir, fileName);
        if (file.exists()) {
            return file.getAbsolutePath();
        } else {
            long startTime = System.currentTimeMillis();
            Log.d("DownloadManager", "download url:" + url);
            Log.d("DownloadManager", "download file name:" + fileName);

            URLConnection uconn = url.openConnection();
            uconn.setReadTimeout(TIMEOUT_CONNECTION);
            uconn.setConnectTimeout(TIMEOUT_SOCKET);

            InputStream is = uconn.getInputStream();
            BufferedInputStream bufferinstream = new BufferedInputStream(is);

            BufferedOutputStream outStream = null;
            outStream = new BufferedOutputStream(new FileOutputStream(file));
            byte[] buf = new byte[5000];
            int len;
            while ((len = bufferinstream.read(buf)) > 0) {
                outStream.write(buf, 0, len);
            }

            outStream.flush();
            outStream.close();
            makeFileAvailable(file);
            Log.d("DownloadManager", "download ready in" + ((System.currentTimeMillis() - startTime) / 1000) + "sec");
            int dotindex = fileName.lastIndexOf('.');
            if (dotindex >= 0) {
                fileName = fileName.substring(0, dotindex);

            }
            return file.getAbsolutePath();
        }
    } catch (IOException e) {
        Log.d("DownloadManager", "Error:" + e);
        e.printStackTrace();
        return "";
    }

}

意图

 String responselink = SaveToDir(getImgUrl());
 String type = FileUtils.getMimeType(responselink);

 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(responselink));
 intent.setDataAndType(Uri.parse(responselink), type);                              
 intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);                                
 intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
 generalPropListener.getSelfContext().startActivity(intent);

1 个答案:

答案 0 :(得分:0)

尝试预先&#34; file://&#34;回应链接。

相关问题