AudioRecord开始()错误状态-38 [英] AudioRecord start() error status -38

查看:4848
本文介绍了AudioRecord开始()错误状态-38的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个录音机,我不断收到一个特定的错误,我无法找出原因。在我的code我已经检查了录音机是什么状态与日志前后的startRecording()方法之后。

I'm trying to set up an audio recorder and I keep getting a specific error and I can't figure out why. in my code I have checked what state the audio recorder is in with the Log before and after the startrecording() method.

ar = new AudioRecord(audiosource, sampleRate, channelConfiguration,
                audioEncoding, buffersizebytes);
Log.d("info", "ar.getState() before = " + String.valueOf(ar.getState()));
ar.startRecording();
Log.d("info", "ar.getState() after = " +String.valueOf(ar.getState()));

当我运行应用程序,我在logcat中获得这些信息。

When I run the app I'm getting these messages in logcat.

D/info﹕ ar.getState() before = 1
E/AudioRecord﹕ start() status -38
D/info﹕ ar.getState() after = 1

从我的文档状态1可以对应于音频记录在RECORDSTATE_STOPPED或STATE_INITIALIZED既未这两个是在看过调用的startRecording()的时候应该出现问题了。



状态-38我相信这是一个errno.h中code为/ *函数未实现* /是这样指的startRecording()方法,或者在错误陈述了start()函数这是不是一种方法在AudioRecorder类。



我曾尝试多种方法,以确保释放()函数被调用,所以我不认为这是问题在这里。



任何帮助是极大的AP preciated。

from what I have read in the documentation the state 1 can either correspond to the audio recorder being in the RECORDSTATE_STOPPED or the STATE_INITIALIZED states neither of these two should cause a problem when calling startRecording().

The status -38 I believe is a errno.h code for /* Function not implemented */ is this referring to the startRecording() method or as it states in the error the start() function which is not a method for the AudioRecorder class.

I have tried multiple methods to make sure that the release() function was called so I don't think that is the problem here.

Any help is greatly appreciated.

推荐答案

好吧所以这是我认为我需要做的这应该真的AudioRecorder文档中谈及,但这个类似questioin导致我的回答的 AudioRecord对象未初始化
基本上你想要做的是遍历所有的配置,并尝试每个对AudioRecord.ERROR_BAD_VALUE检查也因为我使用其中的长度必须是2的幂的FFT规划我加了一点,如果其他人如果要是有人部分其他运行到了类似的情况。

alright so this is what i think i needed to do this should really be talked about in the AudioRecorder documentation but this similar questioin led me to the answer AudioRecord object not initializing basically what you want to do is loop through all the configurations and try each against the AudioRecord.ERROR_BAD_VALUE check also since I was planning on using a fft in which the length must be a power of 2 i added a little if else if portion if anybody else runs into a similar situation

public AudioRecord findAudioRecord() {
    for (int rate : mSampleRates) {
        for (short audioFormat : new short[]{AudioFormat.ENCODING_PCM_8BIT, AudioFormat.ENCODING_PCM_16BIT}) {
            for (short channelConfig : new short[]{AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO}) {
                try {
                    //Log.d("audioSetup", "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: " + channelConfig);
                    int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);
                    if (bufferSize > 0 && bufferSize <= 256){
                        bufferSize = 256;
                    }else if (bufferSize > 256 && bufferSize <= 512){
                        bufferSize = 512;
                    }else if (bufferSize > 512 && bufferSize <= 1024){
                        bufferSize = 1024;
                    }else if (bufferSize > 1024 && bufferSize <= 2048){
                        bufferSize = 2048;
                    }else if (bufferSize > 2048 && bufferSize <= 4096){
                        bufferSize = 4096;
                    }else if (bufferSize > 4096 && bufferSize <= 8192){
                        bufferSize = 8192;
                    }else if (bufferSize > 8192 && bufferSize <= 16384){
                        bufferSize = 16384;
                    }else{
                        bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);
                    }

                    if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {
                        // check if we can instantiate and have a success
                        AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, rate, channelConfig, audioFormat, bufferSize);

                        if (recorder.getState() == AudioRecord.STATE_INITIALIZED) {
                            Log.d("found", "rate: " + rate + " channelConfig: " + channelConfig + " bufferSize: " + bufferSize + " audioFormat: " + audioFormat);
                            sampleRate = rate;
                            channelConfiguration = channelConfig;
                            audioEncoding = audioFormat;
                            buffersizebytes = bufferSize;
                            return recorder;
                        }
                    }
                } catch (Exception e) {
                    Log.d("audioSetup", rate + "Exception, keep trying.", e);
                    e.printStackTrace();
                }
            }
        }
    }
    return null;
}

似乎很好地工作。感谢您的帮助。

seems to work nicely. thanks for the help.

这篇关于AudioRecord开始()错误状态-38的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆