【问题标题】:Video + Audio Recorder Android视频 + 录音机 Android
【发布时间】:2011-12-30 09:42:34
【问题描述】:

我的目标是使用 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);

但这也不起作用。

【问题讨论】:

  • 请发布您遇到的错误。
  • 在检查代码之前,您是在真机上尝试吗?
  • @alextsc java.lang.RuntimeException: 无法启动活动 java.lang.RuntimeException: setAudioSource failed.
  • @Sherif 是的 .. 我正在使用真实设备本身
  • +1 好问题,好描述

标签: android video-capture android-camera


【解决方案1】:

别忘了在 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这样的权限,不知道是不是在你发帖后的某个阶段被删除了
【解决方案2】:

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

你可以试试这个:

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

因为枚举中存在不匹配。

【讨论】:

  • 您可以尝试使用库:vrecorder,但我没有修复此错误。
猜你喜欢
  • 2012-08-08
  • 1970-01-01
  • 1970-01-01
  • 2016-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-02
相关资源
最近更新 更多