VLC:无法从 getExternalStorageDirectory() 播放视频
VLC: Cant Play Video from getExternalStorageDirectory()
我已将我的视频文件保存到我的存储中并尝试使用 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 "";
}
}
意图
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);
尝试将 "file://" 添加到 responseLink。
我已将我的视频文件保存到我的存储中并尝试使用 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 "";
}
}
意图
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);
尝试将 "file://" 添加到 responseLink。