android - how to make a button click play a sound file every time it been pressed?

前端 未结 5 1725
旧巷少年郎
旧巷少年郎 2020-12-01 12:42

I have open a new project -

Now what I would like to do is this - By pressing on the button I want an mp3 file being played - and also that each time the button is p

5条回答
  •  一个人的身影
    2020-12-01 13:41

    If you really have to invoke the click programmatically because the view has no own sound, i would solve it like that, its the simplest solution and a oneliner

    view.playSoundEffect(SoundEffectConstants.CLICK);
    

    very simple and works, if you want to make a layout play a sound you need to put

    android:soundEffectsEnabled="true"
    

    to the Layout

提交回复
热议问题