I'm using html5 audio tag and can't seem to find what to specify for the codec for both mp3 and wav.
I know ogg is:
<audio>
<source type='audio/ogg; codec="vorbis"' />
</audio>
Anyone know what I would write for mp3 and wav?
There are three supported audio formats in HTML: MP3, WAV, and OGG.
HTML5 features include native audio and video support without the need for Flash. The HTML5 <audio> and <video> tags make it simple to add media to a website. You need to set src attribute to identify the media source and include a controls attribute so the user can play and pause the media.
There are basically four options to choose from: WAV, MP3, Ogg and AAC. Not all browsers support all of them, but we'll come to that.
WAV is the best lossless audio codec on the market currently and is most suitable for professional use since it offers the best audio quality.
The best reference for <source type="">
keywords is not the IANA media types registry, as you might think, but developer.mozilla.org's "Media formats for HTML audio and video" article, which documents what browsers (not just Firefox) actually implement, instead of what the RFCs say is supposed to happen. (For instance, there is no official MIME type for .WAV files.)
For the audio container formats you mention, these are my recommended source
tags:
<source type="audio/ogg">
<source type="audio/mpeg">
<source type="audio/wav">
(annoyingly, audio/wave
is simultaneously "preferred" and "does not work with Chrome", thanks ever so much Google).I recommend you do not specify exactly which codec you are using, because this embeds details that could change into the HTML. The browser will figure it out. (Really, this entire mess should have been handled using a generic URL directly on the audio
tag, and an Accept:
header on the HTTP request, but nobody listens to me.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With