Play sound on button click android

后端 未结 11 1282
清酒与你
清酒与你 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条回答
  •  猫巷女王i
    2020-11-29 16:42

    there are some predefined sounds: SHUTTER_CLICK, FOCUS_COMPLETE, START_VIDEO_RECORDING, STOP_VIDEO_RECORDING.

    Nice!

    MediaActionSound

    A class for producing sounds that match those produced by various actions taken by the media and camera APIs. Docs

    use like:

    fun playBeepSound() {
        val sound = MediaActionSound()
        sound.play(MediaActionSound.START_VIDEO_RECORDING)
    }
    

提交回复
热议问题