有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android:声音池/录制音频

我想录制不同的声音,并用手机上的“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);

共 (1) 个答案

  1. # 1 楼答案

    您没有说明遇到了什么问题,但卷处理不正确。 在SoundPool.play()中指定的卷应该是0.0到1.0之间的浮点值,而AudioManager.getStreamVolume()的返回值是0到AudioManager.getStreamMaxVolume()之间的整数

    您只需将体积指定为1.0(或更小),系统将相应地对其进行缩放