Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Soundpool不播放任何声音_Java_Android_Audio_Soundpool - Fatal编程技术网

Java Soundpool不播放任何声音

Java Soundpool不播放任何声音,java,android,audio,soundpool,Java,Android,Audio,Soundpool,编辑文本不会在单击时播放任何声音。上次我创建这种设置时,它起作用了。现在没有了。问题是什么 声音等级: public class MySound { private AudioAttributes audioAttributes; private SoundPool soundPool; protected int soundClick; public MySound(final Context context) { audioAttribut

编辑文本不会在单击时播放任何声音。上次我创建这种设置时,它起作用了。现在没有了。问题是什么

声音等级:

public class MySound {

    private AudioAttributes audioAttributes;
    private SoundPool soundPool;
    protected int soundClick;

    public MySound(final Context context) {
        audioAttributes = new AudioAttributes.Builder()
                .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                .setUsage(AudioAttributes.USAGE_MEDIA)
                .build();
        soundPool = new SoundPool.Builder()
                .setMaxStreams(10)
                .setAudioAttributes(audioAttributes)
                .build();
        soundClick = soundPool.load(context, R.raw.click, 1); 
    }

    public void setEtSound(EditText editText) {
        editText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                soundPool.play(soundClick, 0.5f, 0.5f, 0, 0, 1);
            }
        });
    }

}
片段:

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_1, container, false);

    mySound= new MySound(getActivity());
    mySound.setEtSound(etLoginUsername);
    mySound.setEtSound(etLoginPassword);

    return view;

}