按钮点击播放音效(CLICK / NAVIGATION_RIGHT) - Android

问题描述 投票:2回答:1

我正在尝试使用playSoundEffect ()方法在单击按钮时播放声音效果,但到目前为止,由于某些原因它被证明非常困难。

我已经定义了以下内容。

<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()方法中调用。但是当我点击按钮时,我似乎听不到声音。我在这里错过了什么?文档没有什么可继续的。

我是否需要在onClick()方法中定义/调用?

任何帮助表示赞赏。

android button audio effects
1个回答
5
投票

试试这个:

button_flip.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            button_flip.playSoundEffect(0);
        }
    });

值0代表CLICK声音。你可以看到更多的值here

© www.soinside.com 2019 - 2024. All rights reserved.