我想录制不同的声音并在手机上使用“SoundPool”播放。
目前,我将声音保存在“\ res \ raw”文件夹中,并使用hashMap加载它。
我希望你能帮助我。
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);
最佳答案
您没有说遇到什么问题,但是卷处理不正确。SoundPool.play()
中指定的音量应该是0.0到1.0之间的浮点值,而AudioManager.getStreamVolume()
的返回值是介于0和AudioManager.getStreamMaxVolume()
之间的整数。
您只需将音量指定为1.0(或更小),系统就会相应地对其进行缩放。
关于java - Android:SoundPool/录制音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22074926/