2011-11-16 79 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得到相同的錯誤 –