2015-10-05 55 views
1

我想在我的應用程序中使用mediarecorder來錄製語音。 我正是在http://developer.android.com/reference/android/media/MediaRecorder.html下描述的,但exception總是拋出start()方法。 代碼應該被罰款,因爲我也嘗試了所謂的Mediarecorder從谷歌的代碼示例,但我得到同樣的exception:Android:Mediarecoder在啓動時拋出IllegalStateException()

mRecorder = new MediaRecorder(); 
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); 
mRecorder.setOutputFile(mFileName); 
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); 

    try { 
     mRecorder.prepare(); 
    } catch (IOException e) { 
     Log.e(TAG, "prepare() failed"); 
    } 
    mRecorder.start(); 

我已經添加的權限(android.permission.WRITE_EXTERNAL_STORAGE and android.permission.RECORD_AUDIO)至AndroidManifest.xml,和我上啓動應用程序我的智能手機。

有誰知道什麼可能會導致Exception以及需要做什麼?

+0

研究MediaRecorder的生命週期。 – Kedarnath

+0

提供顯示非法狀態異常的日誌 –

回答

1

感謝您的意見。我能解決這個問題。事實上,我有一個缺少mRecorder.release(),所以似乎啓動方法被調用兩次。

相關問題