Which mime type should I use for mp3
Asked Answered
E

6

135

I'm trying to decide which mime type to choose for returning mp3 data (served up by php)

according to this listing of mime types: http://www.webmaster-toolkit.com/mime-types.shtml

.mp3    audio/mpeg3
.mp3    audio/x-mpeg-3
.mp3    video/mpeg
.mp3    video/x-mpeg

What are the difference between these, and which should I use?

Elery answered 21/5, 2012 at 16:0 Comment(0)
H
201

Your best bet would be using the RFC defined mime-type audio/mpeg.

Highpowered answered 21/5, 2012 at 16:3 Comment(5)
Chrome 26 knows better and uses audio/mp3... Go figure.Privatdocent
Here is the Chromium bug, he just turned 3 today. I'm sure he's going to stick around for a few more years, so smile and wish him a happy birthday. :)Bouquet
@pollaris There is no such thing as multiple mime types, because a file is only of one type. Ideally, you would return audio/mpeg if you are returning an mp3 file or audio/wav if you are returning a wav file. You could use the generic application/octet-stream to indicate a binary file if you didn't want to code for returning the actual mime type, but then the browser might not treat the file the way you expect.Highpowered
@Bouquet - you were right. 6 years and can now ride a bicycle bugs.chromium.org/p/chromium/issues/detail?id=227004Ratchford
The Chrome bug has been fixed! Not sure when it'll make it into Chrome.Ecdysiast
X
40

I had a problem with mime types and where making tests for few file types. It looks like each browser sends it's variation of a mime type for a specific file. I was trying to upload mp3 and zip files with open source php class, that what I have found:

  • Firefox (mp3): audio/mpeg
  • Firefox (zip): application/zip
  • Chrome (mp3): audio/mp3
  • Chrome (zip): application/octet-stream
  • Opera (mp3): audio/mp3
  • Opera (zip): application/octet-stream
  • IE (mp3): audio/mpeg
  • IE (zip): application/x-zip-compressed

So if you need several file types to upload, you better make some tests so that every browser could upload a file and pass mime type check.

Xochitlxp answered 19/1, 2015 at 9:38 Comment(0)
S
14

Use .mp3 audio/mpeg, that's the one I always used. I guess others are just aliases.

Stibnite answered 21/5, 2012 at 16:2 Comment(0)
G
6

You should always use audio/mpeg, because firefox cannot play audio/mpeg3 files

Greathearted answered 2/7, 2014 at 8:28 Comment(1)
Firefox doesn't like audio/mp3 eitherGreyback
C
5

The standard way is to use audio/mpeg which is something like this in your PHP header function ...

header('Content-Type: audio/mpeg');

Calhoun answered 27/6, 2015 at 4:34 Comment(0)
I
0

mp3 files sometimes throw strange mime types as per this answer: https://mcmap.net/q/168744/-why-some-mp3s-on-mime_content_type-return-application-octet-stream

If you are doing some user validation do not allow 'application/octet-stream' or 'application/x-zip-compressed' as suggested above since they can contain be .exe or other potentially dangerous files.

In order to validate when mime type gives a false negative you can use fleep as per this answer https://mcmap.net/q/168745/-python-check-audio-file-type-mp3-or-flac to finish the validation.

Italianism answered 9/12, 2020 at 2:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.