edittexts在点击时不播放任何声音。我最后一次创建这种设置是有效的。现在它没有。有什么问题?
声音等级:
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;
}