HTML5 introduced a new <audio>
element that can be used to play audio files directly in the browser. Prior to this, browsers had to use plugins, such as Flash Player, Real Player, or Quick Time to play audio files. The <audio>
element provides a lightweight alternative, and this recipe shows you how to use it in your app to play audio files.
Copy the full code of this recipe from the code/11/audio
folder. The audio snips are available in the code/resources/audio
folder. You can launch this code using the URL: http://localhost:8080/11/audio/main.html
.
The steps to be followed are:
Create
main.html
with the<audio>
element in its page content:<div data-role='content'> <audio controls autoplay preload='auto'> <source src='../../resources/audio/song.mp3' type='audio/mpeg' /> <source src='../../resources/audio/song.oga' type='audio/ogg' /> <source src...