Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android MediaRecorder错误(1,-2147483648)_Android_Android 4.2 Jelly Bean_Android Mediarecorder - Fatal编程技术网

Android MediaRecorder错误(1,-2147483648)

Android MediaRecorder错误(1,-2147483648),android,android-4.2-jelly-bean,android-mediarecorder,Android,Android 4.2 Jelly Bean,Android Mediarecorder,我正在使用MediaRecorder录制音频,并使用AAC音频将其保存到.mp4。除了装有安卓4.1的Nexus S之外,我试过的所有设备都运行良好。在这些设备上,我要么在start()上得到一个错误(1,-2147483648)(我想),要么继续正常运行,但输出文件总是空的。我拥有必要的权限,因为该应用程序可以在其他设备上运行 mRecorder.reset(); mRecorder.setOnErrorListener(new MediaRecorder.OnErrorListener()

我正在使用MediaRecorder录制音频,并使用AAC音频将其保存到.mp4。除了装有安卓4.1的Nexus S之外,我试过的所有设备都运行良好。在这些设备上,我要么在start()上得到一个错误(1,-2147483648)(我想),要么继续正常运行,但输出文件总是空的。我拥有必要的权限,因为该应用程序可以在其他设备上运行

mRecorder.reset();
mRecorder.setOnErrorListener(new MediaRecorder.OnErrorListener() {

        @Override
        public void onError(MediaRecorder mr, int what, int extra) {
            Log.e("sagasg", what + "   "   + extra);

        }
    });
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    mRecorder.setAudioSamplingRate(SAMPLING_RATE);
    mRecorder.setAudioEncodingBitRate(BIT_RATE);
    mFileName = "unnamed-" + mTimeStarted.year + "-" + mTimeStarted.month + "-" + mTimeStarted.monthDay
            + "-" + mTimeStarted.hour + "-" + mTimeStarted.minute + "-" + mTimeStarted.second;

    mRecorder.setOutputFile(mFilePath + mFileName + mExtension);

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

    mRecorder.start();

这些错误很难调试,但我认为这样就可以了

这是我建议您更改的行:

mRecorder.setOutputFile(mFilePath + mFileName + mExtension);
您应该使用以下选项之一:

或者您也可以尝试:


请注意,对于这两种解决方案中的任何一种,您可能必须捕获一个或多个
IllegalArgumentException
SecurityException
IllegalStateException
,以及
IOException
,我已通过随机更改设置解决了此问题。我搬走的时候它就开始工作了

mRecorder.setAudioSamplingRate(SAMPLING_RATE);
采样率是多少

public static final int SAMPLING_RATE = 48000;
根据文档,AAC支持8-48 kHz,但由于某些原因,它不支持。现在我只需要修复另一个只出现在Nexus S上的bug。现在我明白了为什么开发者更喜欢iOS


编辑:现在它不会因为这个选项而崩溃,只是录音是一个空文件。尝试了其他值,比如24000。同样的结果。我必须坚持默认的采样率。

FileOutputStream会给出相同的结果。嗯,我不知道是否完全一样,因为我这里没有Nexus,但它在我的手机上工作,在Nexus s上崩溃。
mRecorder.setAudioSamplingRate(SAMPLING_RATE);
public static final int SAMPLING_RATE = 48000;