2
ビデオファイルを自分のストレージに保存し、インテントを使用してアプリケーションからビデオを再生しようとしました。 VLCでそれは私に次のエラーを与えます。VLC:getExternalStorageDirectory()からビデオを再生する
再生エラー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);
はい、動作しますが、Android 7.0に問題がある可能性があります – Mysterious
[FileProvider](https://developer.android.com/reference/android/support/v4/content/FileProvider .html)。面倒ですが、難しくありません。 – cwbowron