- Skill level:
Add the following code to the body of your HTML document:
<audio src="audio.mp3" id="mp3" preload="auto"></audio>
This code embeds and loads the MP3 file, but does not play it. The value of the "src" tag contains the path to and filename of the MP3 file.
This function, when called, accesses the "audio" element by its id ("mp3"), and uses the method play() to play it.
Add a button to the Web page to call the "playMP3" function when the user clicks it. Add the following code to the body of the HTML document:
<input type="button" value="Click to play MP3" on Click="playMP3();" />
Change the "value" attribute to give the button a different title.
Use the following function instead of "playMP3" to let the user pause the file after starting it:
Change the "onClick" attribute of the "input" tag in Step 3 to match this function's name.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for