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