android - Android SoundPool不起作用-只是发出咔嗒声

标签 android audio soundpool

我有六个按钮,希望根据点击播放不同的.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/

相关文章:

android - 忽略点击 ImageView 的透明部分

android - 休息数据获取缓存的android

android - 随机声音onClick Android Medaplayer

redirect - Oculus Rift SDK 2更改旋转增益

android - soundPool.load上下文问题

android - 在Android中永久播放而不会暂停

java - Cupcake(API3) 在 SoundPool 中暂停/停止声音循环的友好方式?有任何想法吗?

java - Android 多播只能使用 255.255.255.255 地址

android - 为什么我的 FragmentTransacton() 或 FragmentManager.beginTransaction() 会遇到空指针异常

ios - 单个 AVPlayerItem 中的两个声音淡入淡出