所以我想使用内置的摄像头活动使用低于code录制视频:
意图videoIntent =新的意图(MediaStore.ACTION_VIDEO_CAPTURE);
videoIntent.putExtra(MediaStore.EXTRA_OUTPUT,了fileURI);
videoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60);
startActivityForResult(videoIntent,VIDEO_ACTIVITY);
在调试过程中,了fileURI具有值:文件:///mnt/sdcard/Spootur/Videos/c14e0eb2-0737-4931-9898-e85d10bab74e.mp4,和videoIntent具有一个mExtras值:
Bundle[{output=file:///mnt/sdcard/Spootur/Videos/c14e0eb2-0737-4931-9898-e85d10bab74e.mp4, android.intent.extra.durationLimit = 60}]当我开始录制,它会很好,但是当我reclick录制按钮停止录制,相机应用抛出这样的:
1月五日至11号:08:11.325:E / AndroidRuntime(3748):在com.sec.android.app.camera.CamcorderEngine.renameTempFile(CamcorderEngine.java:1352)
1月5号至11号:08:11.325:E / AndroidRuntime(3748):在com.sec.android.app.camera.CamcorderEngine.doStopVideoRecordingSync(CamcorderEngine.java:849)
1月5号至11号:08:11.325:E / AndroidRuntime(3748):在com.sec.android.app.camera.CeStateRecording.handleRequest(CeStateRecording.java:69)
1月5号至11号:08:11.325:E / AndroidRuntime(3748):在com.sec.android.app.camera.CeRequestQueue.startFirstRequest(CeRequestQueue.java:123)
1月5号至11号:08:11.325:E / AndroidRuntime(3748):在com.sec.android.app.camera.CeRequestQueue.access $ 200(CeRequestQueue.java:32)
1月5号至11号:08:11.325:E / AndroidRuntime(3748):在com.sec.android.app.camera.CeRequestQueue $ MainHandler.handleMessage(CeRequestQueue.java:60)
什么可能会造成这个问题以及如何解决它的任何想法?谢谢!
另外:我可以证实,录制的视频文件是在那个URI
解决方案其实,我发现在某些情况下, MediaStore.EXTRA_OUTPUT
工作不正常,
所以其他招方式,存放在 onActivityResult捕获的视频文件()
保护无效onActivityResult(INT申请code,INT结果code,意图意图){
super.onActivityResult(要求code,因此code,意图);
如果(结果code == RESULT_OK)
{
尝试 {
AssetFileDescriptor videoAsset = getContentResolver()openAssetFileDescriptor(intent.getData(),R)。
的FileInputStream FIS = videoAsset.createInputStream();
文件videoFile =新的文件(Environment.getExternalStorageDirectory(),< VideoFileName> .MP4);
FileOutputStream中FOS =新的FileOutputStream(videoFile);
byte []的缓冲区=新的字节[1024];
INT长;
而((长度= fis.read(缓冲液))大于0){
fos.write(缓冲液,0,长度);
}
fis.close();
fos.close();
}赶上(IOException异常E){
// TODO:处理错误
}
}
}
试试上面的code,让我知道你的成功。
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.