首页 > 解决方案 > 为什么我无法使用 SoundPool 播放声音?

问题描述

我正在使用以下代码:

button.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View v){
                    AudioAttributes at = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).setUsage(AudioAttributes.USAGE_NOTIFICATION).build();
                    SoundPool sp = new SoundPool.Builder().setMaxStreams(2).setAudioAttributes(at).build();
                    int sonido = sp.load(reserva.this,R.raw.sound_gracias,1);
                    sp.play(sonido,1,1,1,0,1);
                }
            });

问题:

当我单击按钮时,我听不到任何声音(我有 100% 的多媒体声音)。

这是我正在使用的声音:

https://freesound.org/people/HoseNoseSounds/sounds/510735/

我能做些什么来解决这个问题?

非常感谢您的阅读!

标签: androidsoundpool

解决方案


推荐阅读