2014-02-27 26 views
0

我想錄制不同的聲音,並使用手機上的「SoundPool」進行播放。 此刻我將聲音保存在「\ res \ raw」文件夾中,並用hashMap加載它。Android:SoundPool/record音頻

我希望你能幫助我。

this.setVolumeControlStream(AudioManager.STREAM_MUSIC); 
spool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); 
soundsMap = new HashMap<Integer, Integer>(); 
soundsMap.put(1, spool.load(context, R.raw.alan1, 1)); 
soundID = soundsMap.get(1); 
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); 
float volume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); 

loopPool = spool.play(soundID, volume, volume, 5, 0, 1f); 

回答

0

你沒有說你要運行什麼問題,但是你的卷處理是不正確的。 在SoundPool.play()中指定的體積應該是從0.0到1.0的浮點值,而返回值AudioManager.getStreamVolume()是0到AudioManager.getStreamMaxVolume()之間的整數。

您應該指定一個1.0(或更小)的體積,系統會相應地縮放它。