2011-11-16 112 views
4

我的目标是使用Android相机拍摄视频并录制 麦克风的声音。视频+录音机Android

我使用Google代码,但无法获得任何工作示例或代码。

我已经试过是


 recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 
     recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); 

     CamcorderProfile cpHigh = CamcorderProfile 
       .get(CamcorderProfile.QUALITY_HIGH); 
     recorder.setProfile(cpHigh); 
     recorder.setOutputFile("/sdcard/videocapture_example.mp4"); 
     recorder.setMaxDuration(50000); // 50 seconds 
     recorder.setMaxFileSize(5000000); // Approximately 5 megabytes 

     recorder.setVideoSize(320, 240); 
     recorder.setVideoFrameRate(15); 

我得到一个RuntimeException

了java.lang.RuntimeException:setAudioSource失败。

以下行

recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 

试图用更换

recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 

但这也不管用。

+0

请张贴你得到了错误。 – 2011-11-16 12:30:12

+1

检查代码之前,你是否试图在真实的设备上? –

+1

@alextsc java.lang.RuntimeException:无法启动活动java.lang.RuntimeException:setAudioSource失败。 –

回答

4

不要忘记在manifest.xml文件设置权限

<uses-permission android:name="android.permission.RECORD_AUDIO"/> 
<uses-permission android:name="android.permission.RECORD_VIDEO"/> 
<uses-permission android:name="android.permission.CAMERA" /> 
+0

没有RECORD_VIDEO这样的权限,不确定它是否在您发布后的某个阶段被删除 – Chris

1

这是android中的一个错误。见http://code.google.com/p/android/issues/detail?id=4075

你可以只尝试这个办法:

recorder.setAudioSource(0); // Or 1, don't know which Enum is right. 

因为在枚举不匹配。

+0

如果我们只是想捕捉视频没有音频..将不可能? –

+0

更新了我的答案。 – Niels

+0

尝试n得到相同的错误 –