android mediarecorder崩溃

uelo1irk  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(289)

我只是试着从麦克风上录下声音,除了在android版本4.4 api 19的emulator上,其他设备都可以正常工作。
我是这样做的:

mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    File root = android.os.Environment.getExternalStorageDirectory();
    File file = new File(root.getAbsolutePath() + "/appfolder/Audios");
    if (!file.exists()) {
        file.mkdirs();
    }else{
    }

    fileName =  root.getAbsolutePath() + "/appfolder/Audios/" + String.valueOf(System.currentTimeMillis() + ".mp3");
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

    mRecorder.setAudioEncodingBitRate(128000);
    mRecorder.setAudioSamplingRate(96000);
    mRecorder.setOutputFile(fileName);
    try {
        mRecorder.prepare();
        mRecorder.start();
    } catch (IOException e) {
        e.printStackTrace();
    }

我在使用android 4.4的emulator上得到以下logcat输出:

12-07 19:06:32.422 3596-3596/com.censored.censoredE/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.censored.censored, PID: 3596
    java.lang.RuntimeException: start failed.
        at android.media.MediaRecorder.start(Native Method)
        at com.censored.censored.activities.RecorderActivity.startRecording(RecorderActivity.java:178)
        at com.censored.censored.activities.RecorderActivity.onClick(RecorderActivity.java:107)
        at android.view.View.performClick(View.java:4438)
        at android.view.View$PerformClick.run(View.java:18422)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        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:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)

导致此错误的行是
mrecorder.start();
我做错了什么?为什么这个错误只发生在android 4.4上?
编辑
我发现是因为mediarecorder.audioencoder.aac行。当我把audioencoder放在.amr\u nb上时,它可以与Android4.4一起工作,但是质量非常差,所以这不是最好的解决方案。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题