亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

android AudioRecorder簡單心得分享

 更新時(shí)間:2013年10月04日 16:24:50   作者:  
這篇文章介紹了android AudioRecorder簡單心得,有需要的朋友可以參考一下
1.如何創(chuàng)建一個(gè)有效的AudioRecorder實(shí)例
Android各種設(shè)備的采樣頻率不同,輸入的聲道數(shù)也不同,如果采用固定的采樣頻率和聲道數(shù),那么得到的AudioRecorder不一定能夠正常初始化。
為了正常使用,需要嘗試各種不同的參數(shù),得到在此設(shè)備上可以用的AudioRecorder實(shí)例。代碼如下:
復(fù)制代碼 代碼如下:

private void createAudioRecord() {  
           for (int sampleRate : new int[]{44100, 8000, 11025, 16000, 22050, 32000,  
            47250, 48000}) {  
        for (short audioFormat : new short[]{  
                AudioFormat.ENCODING_PCM_16BIT,  
                AudioFormat.ENCODING_PCM_8BIT}) {  
            for (short channelConfig : new short[]{  
                    AudioFormat.CHANNEL_IN_MONO,  
                    AudioFormat.CHANNEL_IN_STEREO}) {  

                // Try to initialize  
                try {  
                    recBufSize = AudioRecord.getMinBufferSize(sampleRate,  
                            channelConfig, audioFormat);  

                    if (recBufSize < 0) {  
                        continue;  
                    }  

                    audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,  
                            sampleRate, channelConfig, audioFormat,  
                            recBufSize * 2);  

                    if (audioRecord.getState() == AudioRecord.STATE_INITIALIZED) {  

                        return;  
                    }  

                    audioRecord.release();  
                    audioRecord = null;  
                } catch (Exception e) {  
                    // Do nothing  
                }  
            }  
        }  
    }  

    throw new IllegalStateException(  
            "getInstance() failed : no suitable audio configurations on this device.");  
}

2.常見錯(cuò)誤
1.有些設(shè)備上面,即使你得到了有效的AudioRecorder實(shí)例,在audioRecord.startRecording()的時(shí)候還會報(bào)ERROR_BAD_VALUE錯(cuò)誤。
這有可能是你使用了AudioManager而沒有釋放導(dǎo)致的。
其他錯(cuò)誤都可以在網(wǎng)絡(luò)上找到答案。

相關(guān)文章

最新評論