Reputation: 37018
See how it links to a .ogg and a .mp3? Why is that? All the examples and applications I've seen do the same thing. Is it necessary to have two sources?
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
Upvotes: 3
Views: 414
Reputation: 9
To make it simpler lol.
Firefox doesnt support mp3 (idk if they still dont) So to make your player function in firefox you need the ogg as a backup.
Firefox will skip the mp3 and try to find the ogg.
Upvotes: 0
Reputation:
Not all browsers support the MP3 or OGG format, so both are usually included to insure cross-browser compatibility.
The Wav format can also be included, and unlike MP3 and Ogg, it supports every browser (minus Internet Explorer).
MP3 works with Internet Explorer 9+, Chrome 6+, and Safari 5+. Ogg works with every browser, minus Internet Explorer and Safari.
So the combination of MP3 and Wav, or MP3 and Ogg, would play the HTML5 Audio on virtually every major browser. Of course, it's a bad idea to include Wav and Ogg as a combo, due to the fact that Internet Explorer requires MP3 as a format.
So the multiple tags are included as a fallback.
Hopefully in the future, all the major browsers will support all the formats. Currently only Chrome does.
(Hope my answer doesn't sound like a tongue-twister.)
Upvotes: 1
Reputation: 224857
No, it's not necessary. The different sources are just possibilities to be tried in order; not all browsers are guaranteed to support all formats, and so you provide fallbacks.
(If you only want to provide one, the src
and type
can go directly on the <audio>
tag, too.)
Upvotes: 4