Android AudioRecord问题

时间:2016-07-25 21:43:10

标签: android audiorecord

在我的应用程序中,我使用AudioRecorder来检测何时收到音频信号。我的应用程序在单个Android设备上运行但在其他设备上测试时遇到错误。即,我收到错误

start() status -38

这是我的代码:

protected AudioTrack mAudioTrack;
protected AudioRecord mRecorder;

protected Runnable mRecordFeed = new Runnable() {

    @Override
    public void run() {

        while (mRecorder.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {

            short[] data = new short[mBufferSize/2]; //the buffer size is in bytes

            // gets the audio output from microphone to short array samples
            mRecorder.read(data, 0, mBufferSize/2);

            mDecoder.appendSignal(data);
        }
    }
};

protected void setupAudioRecorder(){
    Log.d(TAG, "set up audio recorder");
    //make sure that the settings of the recorder match the settings of the decoder
    //most devices cant record anything but 44100 samples in 16bit PCM format...
    mBufferSize = AudioRecord.getMinBufferSize(FSKConfig.SAMPLE_RATE_44100, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);

    //scale up the buffer... reading larger amounts of data
    //minimizes the chance of missing data because of thread priority
    mBufferSize *= 10;

    //again, make sure the recorder settings match the decoder settings
    mRecorder = new AudioRecord(MediaRecorder.AudioSource.MIC, FSKConfig.SAMPLE_RATE_44100, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, mBufferSize);

    if (mRecorder.getState() == AudioRecord.STATE_INITIALIZED) {
        mRecorder.startRecording();

        //start a thread to read the audio data
        Thread thread = new Thread(mRecordFeed);
        thread.setPriority(Thread.MAX_PRIORITY);
        thread.start();
    }
    else {
        Log.i(TAG, "Please check the recorder settings, something is wrong!");
    }
}

这种状态-38意味着什么,我该如何解决?我似乎无法在任何地方找到任何文件。

0 个答案:

没有答案