问题描述
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);
在调试期间,FileMi具有以下值:文件:///mnt/sdcard/spootur/videos/c14e0eb2-0737-4931-9898-4931-9898-4931-9898-4931-9898- 4931-9898- 4931-9898- 4931-9898- 4931-9898- 4931-9898- 4931-9898-E85D10BAB74E.MP4和videointent具有mextras值:
Bundle[{output=file:///mnt/sdcard/Spootur/Videos/c14e0eb2-0737-4931-9898-e85d10bab74e.mp4, android.intent.extra.durationLimit=60}]
当我开始录制时,它变得很好,但是当我重新点击记录按钮停止录制时,相机应用程序抛出这个:
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)
任何可能导致这个的想法以及如何解决它?谢谢!
还:我可以确认录制的视频文件位于该URI.
推荐答案
实际上,我发现在某些情况下MediaStore.EXTRA_OUTPUT不正常工作, 因此,其他特技方式是,将捕获的视频文件存储在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 } } }
尝试上面的代码,让我知道你的成功.
问题描述
So I'm trying to use the built in camera activity to record a video using the below code:
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);
During debugging, fileURI has a value of: file:///mnt/sdcard/Spootur/Videos/c14e0eb2-0737-4931-9898-e85d10bab74e.mp4, and videoIntent has an mExtras value of:
Bundle[{output=file:///mnt/sdcard/Spootur/Videos/c14e0eb2-0737-4931-9898-e85d10bab74e.mp4, android.intent.extra.durationLimit=60}]
When I start recording, it goes fine, but when I reclick the record button to stop recording, the camera app throws this:
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 of what could be causing this and how to fix it? Thanks!
Also: I can confirm that the recorded video file is at that URI.
推荐答案
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 } } }
Try the above code and let me know about your success.