我正在使用我的 android 应用程序录制视频。当我在录制后尝试从路径中读取视频时,我没有得到完整的录制文件。 但过了一段时间我可以阅读完整的文件。我不知道是什么问题? 请帮忙。 这是我的代码
尝试{ videoFile = getOutputMediaFile(MEDIA_TYPE_VIDEO); videothumb = new File(getOutputMediaThumbFile(MEDIA_TYPE_VIDEO), videoFile.getName()); db.insertFileInfo(videoFile.getName(), 0, videoFile.length(), 0, "video/mp4"); 如果(videoFile == null){ Log.d("", "创建媒体文件出错,检查存储权限:"); safeToTakePicture = true; 返回空值;
videothumb.createNewFile();
videoFile.createNewFile();
Thread.sleep(10000);
upVFile = new File(videoFile.getAbsolutePath());
FileOutputStream fos = new FileOutputStream(videoFile);
FileOutputStream ftos = new FileOutputStream(videothumb);
thumb = Bitmap.createScaledBitmap(bmv, 200, 200, false);
thumb.compress(Bitmap.CompressFormat.JPEG, 90, ftos);
ftos.flush();
ftos.close();
bmv.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmv.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
baos.close();
String encodedImage = new String(Base64.encodeBase64(b));
editor.putString("image_data", encodedImage);
editor.commit();
editor.putString(IMAGE_NAME, videoFile.getName());
editor.commit();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
最佳答案
写一个刷新图库的方法
private void refreshGallery(File file){
Intent mediaScanIntent=new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(Uri.fromFile(file));
sendBroadcast(mediaScanIntent);
}
关于android - 录制的视频无法立即从文件位置读取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36265120/