我正在尝试捕获视频,并且当执行到达recorder.prepare()语句时,例程抛出异常:
private void recordVideoStart(){
if(recorder != null)
{
recorder.stop();
recorder.release();
}
File file = new File("/sdcard/videoTest.3gpp");
try {
file.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
recorder = new MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(file.getAbsolutePath());
recorder.setVideoSize(176, 144);
recorder.setVideoFrameRate(15);
//recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setPreviewDisplay(videoPreview.getSurface());
try {
recorder.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
recorder.start();
}
看着LogCat,我注意到“相机不可用”这一行。
有谁知道这里可能出现的问题以及如何启用视频捕获?
谢谢!
答案 0 :(得分:1)
您需要将摄像机设置为录像机。
recorder.setCamera(Camera.open());
答案 1 :(得分:0)
您是否已在AndroidManifest.xml中添加:
<uses-permission android:name="android.permission.CAMERA" />
答案 2 :(得分:0)
确保清单中包含以下权限。
它需要WRITE_EXTERNAL_STORAGE
才能写入我们的SD卡
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />