How to play audio?

前端 未结 20 3255
抹茶落季
抹茶落季 2020-11-21 13:37

I am making a game with HTML5 and JavaScript.

How could I play game audio via JavaScript?

20条回答
  •  故里飘歌
    2020-11-21 13:44

    It's easy, just get your audio element and call the play() method:

    document.getElementById('yourAudioTag').play();
    

    Check out this example: http://www.storiesinflight.com/html5/audio.html

    This site uncovers some of the other cool things you can do such as load(), pause(), and a few other properties of the audio element.

提交回复
热议问题