播放音效(点击/ NAVIGATION_RIGHT)的按钮点击 - 机器人
问题描述:
我试图使用 playSoundEffect()
方法来播放声音效果,单击按钮时,但到目前为止,其证明出于某种原因非常困难。
I'm trying to use the playSoundEffect ()
method to play a sound effect when a button is clicked, but so far its' proved very difficult for some reason.
我已经定义了以下内容。
I have defined the following.
<ImageButton android:id="@+id/Button_flip" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="FLIP!"
android:src="@drawable/flip" android:soundEffectsEnabled="true">
</ImageButton>
然后,
button_flip.playSoundEffect(android.view.SoundEffectConstants.CLICK);
时,称为中的onCreate()方法。但我似乎无法得到它的声音,当我按一下按钮。我在想什么吗?该文档有没有什么去。
is called in onCreate() method. But I cannot seem to get it to sound when I click the button. What am I missing here? The documentation has nothing much to go on.
我是否需要定义/在onclick()方法调用?
Do I need to define/call in the onClick() method?
任何帮助是AP preciated。
Any help is appreciated.
感谢你。
答
试试这个:
button_flip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
button_flip.playSoundEffect(0);
}
});
值为0表示咔嚓声。你可以看到更多的价值这里