Play sound on button click android

后端 未结 11 1281
清酒与你
清酒与你 2020-11-29 16:10

How do I get a button to play a sound from raw when click? I just created a button with id button1, but whatever code I write, all is wrong.

imp         


        
11条回答
  •  悲&欢浪女
    2020-11-29 16:49

    All these solutions "sound" nice and reasonable but there is one big downside. What happens if your customer downloads your application and repeatedly presses your button?

    Your MediaPlayer will sometimes fail to play your sound if you click the button to many times.

    I ran into this performance problem with the MediaPlayer class a few days ago.

    Is the MediaPlayer class save to use? Not always. If you have short sounds it is better to use the SoundPool class.

    A save and efficient solution is the SoundPool class which offers great features and increases the performance of you application.

    SoundPool is not as easy to use as the MediaPlayer class but has some great benefits when it comes to performance and reliability.

    Follow this link and learn how to use the SoundPool class in you application:

    https://developer.android.com/reference/android/media/SoundPool

    Youtube: Save Solution

提交回复
热议问题