Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5 audio codec

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?

like image 272
keith Avatar asked Jul 29 '10 02:07

keith


People also ask

What are the audio format supported by HTML5?

There are three supported audio formats in HTML: MP3, WAV, and OGG.

Can HTML5 play audio?

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.

What are the 3 Supported audio formats by our browsers *?

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.

What is the best audio codec?

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.


1 Answers

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:

  • Ogg: <source type="audio/ogg">
  • MP3: <source type="audio/mpeg">
  • WAV: <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.)

like image 180
zwol Avatar answered Sep 20 '22 03:09

zwol