Reputation: 2228
I am wondering how its possible HTML audio element can play a song when the type attribute of the src element is set to the wrong format?
For example I set the type attribute for an mp4 audio file to be audio/wav and it still plays even though I didn't specify a fallback source? Also it seems if you omit the type it still can figure out the correct audio format.
So my question is whats the purpose of the type attribute for the source element?
<audio controls="controls">
Your browser does not support the <code>audio</code> element.
<source src="http://a898.phobos.apple.com/us/r1000/039/Music6/v4/13/22/67/1322678b-e40d-fb4d-8d9b-3268fe03b000/mzaf_8818596367816221008.plus.aac.p.m4a">
</audio>
Here is a jsfiddle showing the effect https://jsfiddle.net/abftb7sm/4/
Upvotes: 0
Views: 422
Reputation: 136986
After some tests, and according to the specs it seems that the type
attribute of the MediaElements only helps the browser to determine if it should and how to fetch the data at all.
The type attribute gives the type of the media resource, to help the user agent determine if it can play this media resource before fetching it.
On Firefox,
Setting it to any valid value, but not accorded to the actual file type will make UA fetch data as plain
. Then when asked to play, UA double checks the data type and is able to override the type
you gave.
Setting it to some invalid value however (such as "Audio/mpeg"
instead of "audio/mpeg"
) will make your UA not even fetch any data. No double check here.
Chrome seems to never trust us...
Upvotes: 1