最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android AudioRecorder簡單心得分享

 更新時間:2013年10月04日 16:24:50   作者:  
這篇文章介紹了android AudioRecorder簡單心得,有需要的朋友可以參考一下
1.如何創(chuàng)建一個有效的AudioRecorder實例
Android各種設(shè)備的采樣頻率不同,輸入的聲道數(shù)也不同,如果采用固定的采樣頻率和聲道數(shù),那么得到的AudioRecorder不一定能夠正常初始化。
為了正常使用,需要嘗試各種不同的參數(shù),得到在此設(shè)備上可以用的AudioRecorder實例。代碼如下:
復(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.常見錯誤
1.有些設(shè)備上面,即使你得到了有效的AudioRecorder實例,在audioRecord.startRecording()的時候還會報ERROR_BAD_VALUE錯誤。
這有可能是你使用了AudioManager而沒有釋放導(dǎo)致的。
其他錯誤都可以在網(wǎng)絡(luò)上找到答案。

相關(guān)文章

最新評論

阿克陶县| 怀集县| 越西县| 长顺县| 扶绥县| 盱眙县| 繁昌县| 浙江省| 寿阳县| 舞阳县| 杭锦后旗| 双牌县| 临清市| 延边| 宁化县| 大庆市| 闽侯县| 夏津县| 宜都市| 香格里拉县| 澄城县| 会泽县| 沙雅县| 利川市| 长沙市| 清流县| 崇仁县| 乌恰县| 米脂县| 梧州市| 明溪县| 江山市| 温泉县| 杭州市| 阜康市| 永嘉县| 固阳县| 晋中市| 巩义市| 扶风县| 阿拉善右旗|