HTML5 – Play sound/music with <audio> tag @ 1

Next: HTML5 – Play sound/music with <audio> tag @ 2

With HTML5, we can easily play audio file with the <audio> tag. Here is an example.

<html>
  <head></head>
  <body>
    <audio controls loop autoplay>
      <source src="music.ogg" type="audio/ogg" />
      <source src="music.mp3" type="audio/mp3" />
      Your browser does not support the audio element.
    </audio> 
  </body>
</html>


 

A control panel will be shown when the HTML is rendered.

 

Please note that you have to include both .ogg and .mp3 because .ogg works in Firefox, Opera and Chrome while .mp3 is for Internet Explorer and Safari.

Done =)

Reference:

Advertisement

3 thoughts on “HTML5 – Play sound/music with <audio> tag @ 1”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.