我有六个按钮,希望根据点击播放不同的.mp3-文件。我已经实现了onClick方法,如下所示:
SoundPool sp = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
if(view = screamButton) {
soundId = sp.load(getContext(), R.raw.scream, 1);
}
// Some else if - statements
sp.play(soundId, 5, 5, 0, 0, 1);
我还尝试创建一个AudioManager来设置音量,但是没有任何改变。
有什么事吗
汉克
最佳答案
我和你有同样的问题。
我的解决方案是:
在OnCreate中输入以下内容:
//The 20 is the maximum let the audio reproduce at the same time
sp = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
//volume control from the cellphone:
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
//load the audio
soundId= sp.load(this,R.raw.scream,1);
最后,当您想要声音再现时,请输入以下内容:
sp.play(soundId, 1, 1, 0, 0, 1);
对我来说还可以。
希望对您有帮助。
问候,皮耶罗。
关于android - Android SoundPool不起作用-只是发出咔嗒声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23246578/