mediaRecorder java.langRuntimeException停止失败 - 录制音频

时间:2014-05-03 04:43:35

标签: java android android-mediarecorder

我试图录制音频,而且需要高质量。

这个代码在很多设备上运行良好,但是在某些设备上,例如galaxy s4 mini,moto G,甚至是Galaxy s4和HTC one mini,它都行不通。

这是我的录音方法

public class RecordingHandler {

    private static MediaRecorder recorder;

    static void beginRecording(String output) throws Exception {

        ditchMediaRecorder();
        File outFile = new File(output);
        if (outFile.exists())
            outFile.delete();
        recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setAudioEncoder(MediaRecorder.getAudioSourceMax());
        recorder.setAudioEncodingBitRate(16);
        recorder.setAudioSamplingRate(44100);
        recorder.setOutputFile(output);
        recorder.prepare();
        recorder.start();
    }

    static void ditchMediaRecorder() {
        // if we have the recorder, release it
        if (recorder != null)
            recorder.release();
    }

    static void stopRecording() {
        if (recorder != null) {

            try {
                recorder.stop();
            } catch (RuntimeException stopException) {
                // handle cleanup here
                Log.d("Recording Handler", "Runtime Exception");
            }
        }
    }

}

我得到的错误

java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
at com.appulse.beatbox.RecordingHandler.stopRecording(RecordingHandler.java:34)
at com.appulse.beatbox.SoundRecord$5.onTouch(SoundRecord.java:347)
at android.view.View.dispatchTouchEvent(View.java:7784)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2169)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1613)
at android.app.Activity.dispatchTouchEvent(Activity.java:2539)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2117)
at android.view.View.dispatchPointerEvent(View.java:8005)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4300)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4179)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3714)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3764)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3733)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3844)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3741)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3901)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3714)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3764)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3733)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3741)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3714)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5973)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5946)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5909)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6057)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:214)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:134)
at android.app.ActivityThread.main(ActivityThread.java:5872)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案