VerifiyAndSetParameter error when trying to record video

五迷三道 提交于 2019-11-28 01:45:41
Vatsalengg

Buddy you should see answer of following Question, It is working for me and definitely work for you.

Android: Video Recording Throws Error

NOTE : I have same error as follows

at com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1206)

Solution : Working in Android 2.2, 2.3 ... I have done following process to capture photo

int CAMERA_WITH_VIDEO_DATA = 2;
//start photo capture activity...

 Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE, null);
 startActivityForResult(intent, CAMERA_WITH_VIDEO_DATA);

....
....

private void saveVideoFileOnActivityResult(Intent videoIntent){
   FileInputStream fis = null;
   FileOutputStream fos = null;
   File mCurrentVideoFile = null;
   try {
         mCurrentVideoFile = new File("path_to_your_file");
         AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(videoIntent.getData(), "r");
         fis = videoAsset.createInputStream();
         //File videoFile = new File(Environment.getExternalStorageDirectory(),"<VideoFileName>.mp4"); 
         fos = new FileOutputStream(mCurrentVideoFile);

         byte[] buffer = new byte[1024];
         int length;
         while ((length = fis.read(buffer)) > 0) {
               fos.write(buffer, 0, length);
          }       
         //fis.close();
         //fos.close();
   } catch (IOException e) {
      // TODO: handle error
     e.printStackTrace();
   }finally{
       try {
           if(fis!=null)
              fis.close();
           if(fos!=null)
              fos.close();
       } catch (Exception e2) {
        // TODO: handle exception
        e2.printStackTrace();
       }
   } 
   }
....
....

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case CAMERA_WITH_VIDEO_DATA:
//pass data to above method to save it.
saveVideoFileOnActivityResult(data);
break;

default:
break;
}
}

OK, I refined my Logcat to see where the error starts, and the first line in which the program fails is:

05-08 10:46:33.740: E/AndroidRuntime(29786):    at com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1206)

A quick Google search took me to this place, and apparently the MediaStore.EXTRA_OUTPUT DOES NOT work correctly and has issues.

this is the answer that was written there:

Actually, I found in some case MediaStore.EXTRA_OUTPUT doesn't work properly, SO the other trick way is, store your captured video file in onActivityResult()

protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
   super.onActivityResult(requestCode, resultCode, intent);

   if (resultCode == RESULT_OK) {   
      try {
          AssetFileDescriptor videoAsset = getContentResolver().openAssetFileDescriptor(intent.getData(), "r");
          FileInputStream fis = videoAsset.createInputStream();
          File videoFile = new File(Environment.getExternalStorageDirectory(),"<VideoFileName>.mp4"); 
          FileOutputStream fos = new FileOutputStream(videoFile);

          byte[] buffer = new byte[1024];
          int length;
          while ((length = fis.read(buffer)) > 0) {
             fos.write(buffer, 0, length);
         }       
         fis.close();
         fos.close();
         } catch (IOException e) {
            // TODO: handle error
        }
   }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!