I am Recording a video using my android application.when i am trying to read the video from the path after recording i did'nt get the full recorded file. but after some time i can read the full file.i don't know what is the problem? please help. Here is my code
try { videoFile = getOutputMediaFile(MEDIA_TYPE_VIDEO); videothumb = new File(getOutputMediaThumbFile(MEDIA_TYPE_VIDEO), videoFile.getName()); db.insertFileInfo(videoFile.getName(), 0, videoFile.length(), 0, "video/mp4"); if (videoFile == null) { Log.d("", "Error creating media file, check storage permissions: "); safeToTakePicture = true; return null; }
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 {
}
write a method for refreshing gallery
private void refreshGallery(File file){
Intent mediaScanIntent=new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(Uri.fromFile(file));
sendBroadcast(mediaScanIntent);
}