视频+音频录制器 Android

4

我的目标是使用Android相机捕捉视频并录制来自麦克风的声音。

我搜索了代码,但没有找到任何可行的示例或代码。

我尝试过的是


        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);

但是这也不起作用。

请发布您收到的错误。 - user658042
1
在检查代码之前,你有在真实设备上尝试吗? - Sherif elKhatib
1
@alextsc java.lang.RuntimeException: 无法启动活动 java.lang.RuntimeException: setAudioSource 失败。 - Vishal Khakhkhar
@Sherif 是的..我正在实际设备上工作 - Vishal Khakhkhar
+1个好问题,附有清晰的描述。 - Paresh Mayani
2个回答

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" />

您好,关于您的帖子中提到的RECORD_VIDEO权限,实际上并不存在这个权限。不确定是否在您发帖后的某个阶段被移除了。 - Chris

1

您可以尝试使用库:vrecorder,但是我对这个错误没有解决方法。 - Niels

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接