2013-10-24 111 views
2

我嘗試錄製音頻,只有音頻,和我在Android 4.1.2但不是這個錯誤在4.3:的Android MediaRecorder啓動失敗處於無效狀態4

下面是代碼:

​​

這裏的日誌:

10-24 08:34:02.777: E/MediaRecorder(13491): start called in an invalid state: 4 
10-24 08:34:02.777: D/AndroidRuntime(13491): Shutting down VM 
10-24 08:34:02.777: W/dalvikvm(13491): threadid=1: thread exiting with uncaught exception (group=0x40e5b440) 
10-24 08:34:02.823: E/AndroidRuntime(13491): FATAL EXCEPTION: main 
10-24 08:34:02.823: E/AndroidRuntime(13491): java.lang.IllegalStateException 
10-24 08:34:02.823: E/AndroidRuntime(13491): at android.media.MediaRecorder.start(Native Method) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at com.androtest.audio.startRecord(AudioActivity.java:357) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at com.androtest.audio.onOptionsItemSelected(AudioActivity.java:307) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at android.app.Activity.onMenuItemSelected(Activity.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at com.android.internal.view.menu.ActionMenuView.invokeItem(ActionMenuView.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at com.android.internal.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at android.view.View.performClick(View.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at android.view.View$PerformClick.run(View.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at android.os.Handler.handleCallback(Handler.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at android.os.Handler.dispatchMessage(Handler.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at android.os.Looper.loop(Looper.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at android.app.ActivityThread.main(ActivityThread.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at java.lang.reflect.Method.invokeNative(Native Method) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at java.lang.reflect.Method.invoke(Method.java:511) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java) 
10-24 08:34:02.823: E/AndroidRuntime(13491): at dalvik.system.NativeStart.main(Native Method) 

我讀過幾百個線程對這個錯誤,但我無法找到任何解決我的問題...

回答

4

好吧,我找出我的問題是什麼。 此:

final String audioName = getDate(System.currentTimeMillis()).replaceAll(" ", "_"); 

返回包含該字符的字符串: 「:」 通過替換它:

final String audioName = (getDate(System.currentTimeMillis()).replaceAll(" ", "_")).replaceAll(":", "-"); 

解決了我的問題。

5

我有相同的錯誤,並通過修復文件的路徑來解決它。所以如果你的狀態是4,檢查你是否有輸出文件路徑設置,如果它確實存在

0

我有同樣的問題,然後意識到我的輸出文件的路徑是不正確的。糾正路徑解決了我的問題。

相關問題