gpt4 book ai didi

android - 点击声音无法播放android onClick

转载 作者:行者123 更新时间:2023-12-03 00:08:34 25 4
gpt4 key购买 nike

我有这个:

android:onClick="onClick"
android:soundEffectsEnabled="true"

在我的XML中。在我的课上,我有:
public void onClick(View v) {
v.playSoundEffect(SoundEffectConstants.CLICK);
increment(button, key, this);
}

但是,“点击”声音仍然无法正常工作

最佳答案

根据Android开发人员页面的方法PlaySoundEffect

The sound effect will only be played if sound effects are enabled by the user, and isSoundEffectsEnabled() is true.



因此,必须在“设置”->“声音”中激活声音效果。

尝试
MediaPlayer mp = MediaPlayer.create(getApplicationContext(),<yoursound> );
mp.start();

代替。
如果打开音频(用于媒体),此声音将始终播放

关于android - 点击声音无法播放android onClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38873493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com