Android: video gives an error

So, I am trying to use the built-in camera activity to record video using the code below:

Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileURI); videoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 60); startActivityForResult(videoIntent, VIDEO_ACTIVITY); 

When debugging, fileURI has the value: file: ///mnt/sdcard/Spootur/Videos/c14e0eb2-0737-4931-9898-e85d10bab74e.mp4, and for the video test it has the value mExtras:

 Bundle[{output=file:///mnt/sdcard/Spootur/Videos/c14e0eb2-0737-4931-9898-e85d10bab74e.mp4, android.intent.extra.durationLimit=60}] 

When I start recording, everything goes well, but when I turn off the record button to stop recording, the camera application throws this out:

 05-11 01:08:11.325: E/AndroidRuntime(3748): at com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1352) 05-11 01:08:11.325: E/AndroidRuntime(3748): at com.sec.android.app.camera.CamcorderEngine.doStopVideoRecordingSync(CamcorderEngine.java:849) 05-11 01:08:11.325: E/AndroidRuntime(3748): at com.sec.android.app.camera.CeStateRecording.handleRequest(CeStateRecording.java:69) 05-11 01:08:11.325: E/AndroidRuntime(3748): at com.sec.android.app.camera.CeRequestQueue.startFirstRequest(CeRequestQueue.java:123) 05-11 01:08:11.325: E/AndroidRuntime(3748): at com.sec.android.app.camera.CeRequestQueue.access$200(CeRequestQueue.java:32) 05-11 01:08:11.325: E/AndroidRuntime(3748): at com.sec.android.app.camera.CeRequestQueue$MainHandler.handleMessage(CeRequestQueue.java:60) 

Any ideas on what could be causing this and how to fix it? Thanks!

Also: I can confirm that the recorded video file is in this URI.

+1
source share
1 answer

In fact, I found that in some case MediaStore.EXTRA_OUTPUT is not working properly, so another way is to save the 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 } } } 

Try the code above and let me know about your success.

+10
source

Source: https://habr.com/ru/post/1499534/


All Articles