android - VLC : Cant Play Video from getExternalStorageDirectory()

标签 android video file-permissions

我已将我的视频文件保存到我的存储中,并尝试使用 Intent 从我的应用程序播放视频。在其他播放器上该文件播放正常但是当我尝试使用 VLC 播放该文件时出现以下错误;

Playback Error Vlc encountered an error with this media. Please try refreshing the media library.

The location /storage/emulated/0/myFolder/file.mov cannot be played.

保存方法

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 "";
    }

}

Intent

 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);

最佳答案

尝试在 responseLink 前加上“file://”。

关于android - VLC : Cant Play Video from getExternalStorageDirectory(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45689073/

相关文章:

video - 使用 FFMPEG 将视频转换为 PowerPoint 2016 兼容的视频格式

wordpress - WordPress中的文件权限无法正常工作

java - Android的SettingsActivity中如何让修改密码提示确认?

android - ActiveAndroid schema迁移DB版本,版本可以分批递增吗?

java - 如何为 VLCJ 添加或安装 native x64 库?

inno-setup - 在 Inno Setup 中修改选定的目录访问权限

java - 如何在 Windows 7 上使用 NIO 库更改 Java 中的文件权限

android - 在 firefox 或任何其他适用于 windows/桌面 linux 的浏览器中像 appstore 一样列出

android - 在Android中以编程方式启动5ghz wifi热点

python - 使用opencv和python从视频中提取帧