当前位置: 代码迷 >> Android >> 三星手机下录音崩溃的有关问题
  详细解决方案

三星手机下录音崩溃的有关问题

热度:83   发布时间:2016-05-01 13:06:18.0
三星手机上录音崩溃的问题
某些三星手机的音频驱动好像是改过的,在 HTC 手机上跑的好好的程序,拿到三星上就录音崩溃。我目前的手机是三星GT-I8150,我的源码如下:
Java code
public class AndroidAudioRecordManager{    public int frequency =8000;    public int channelConfiguration = AudioFormat.CHANNEL_CONFIGURATION_MONO;    public int audioEncoding = AudioFormat.ENCODING_PCM_16BIT;    int recBufSize, playBufSize;    AudioRecord audioRecord;    boolean isRecording = false;    private long filterCtxPtr = 0;    Thread recordThread=null;        private native void putAudioData(long filterCtxPtr, byte[] buffer,            int dataLen);    public void startParametersFromFilter(long filterCtxPtr, int rate,            int channel, int bits)    {        this.filterCtxPtr = filterCtxPtr;        frequency = rate;        recBufSize = AudioRecord.getMinBufferSize(frequency,                channelConfiguration, audioEncoding);        audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,                frequency, channelConfiguration, audioEncoding,                recBufSize);        isRecording = true;        recordThread=new AudioRecordThread();        recordThread.start();    }    public void stopFromFilter()    {        isRecording = false;        try        {            recordThread.join();        } catch (InterruptedException e)        {        }            }    class AudioRecordThread extends Thread    {        public void run()        {            android.os.Process.setThreadPriority(-19);            try            {                byte[] buffer = new byte[recBufSize];                int rstat=audioRecord.getRecordingState();                int dstat=audioRecord.getState();                if(dstat!=AudioRecord.STATE_INITIALIZED)                {                    return;                }                Thread.sleep(1000);                audioRecord.startRecording();                while(isRecording)                {                    int bufferReadResult = audioRecord.read(buffer, 0, 320);                    putAudioData(filterCtxPtr, buffer, bufferReadResult);                }                audioRecord.stop();            } catch (Throwable t)            {            }            finally            {                audioRecord.release();                audioRecord=null;            }        }    }};


执行到 int bufferReadResult = audioRecord.read(buffer, 0, 320); 这一句,bufferReadResult 始终是 -110。请有经验的大虾帮帮忙,高分相赠,非常感谢!

------解决方案--------------------
sampleRateInHz the sample rate expressed in Hertz. 44100Hz is currently the only rate that is guaranteed to work on all devices, but other rates such as 22050, 16000, and 11025 may work on some devices. 

api说明,把采样率设置为44100hz试试。
------解决方案--------------------
logcat有没有报错?会不会和线程有关?
------解决方案--------------------
系统有录音的功能,录完后,你只要将录完的文件拷入指定地方就可以了
------解决方案--------------------
不同手机音频系统具体实现有些区别,有些未必是按标准做的,因此还是得具体问题具体分析,把错误打印贴出来供大家分析。
------解决方案--------------------
可能是因为其他声音播放线程与该线程冲突。
  相关解决方案