简体   繁体   English

Android:SoundPool /录制音频

[英]Android: SoundPool / record Audio

I want to record different sound and play it with the "SoundPool" on my Phone. 我想录制不同的声音并在手机上使用“ SoundPool”播放。 At the moment I save the sounds in the "\\res\\raw" folder und load it with a hashMap. 目前,我将声音保存在“ \\ res \\ raw”文件夹中,并使用hashMap加载它。

I hope you can help me. 我希望你能帮助我。

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);

You didn't say what problem you're running in to, but your volume handling is incorrect. 您没有说遇到什么问题,但是卷处理不正确。 The volume specified in SoundPool.play() is supposed to be a floating point value from 0.0 to 1.0, while the return value of AudioManager.getStreamVolume() is an integer between 0 and AudioManager.getStreamMaxVolume() . SoundPool.play()指定的音量应该是0.0到1.0之间的浮点值,而AudioManager.getStreamVolume()的返回值是0到AudioManager.getStreamMaxVolume()之间的整数。

You should just specify a volume of 1.0 (or less), and the system will scale it accordingly. 您只需将音量指定为1.0(或更小),系统就会相应地对其进行缩放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM