How can I determine if a particular file is actually an MP3 file?

How can I determine if a particular file (which may or may not contain the extension ".mp3") is actually an MP3 file? I want to do this in C #.

+7
source share
5 answers
+5
source

According to http://www.garykessler.net/library/file_sigs.html mp3 file will always start with ID3 (hex 49 44 33). However, the presence of these bytes only means that the file is marked with ID3 information . If this signature is not found, it may be an unlabeled mp3 file. To determine this, check the structure of the mp3 file and you will see that the mp3 frame begins with the signature ff fb (hex).

So:

  • If the file starts with hex 49 44 33

or

  • if the file starts with hex ff fb

It’s safe to assume that it is MP3.

+14
source

Files often start with a magic number to identify the data format. Depending on the format, the file starts with a specific sequence of bytes that is unique to this format. There is no standard to follow so that it is not 100% reliable.

According to fvu, magic number mp3 0x49 0x44 0x33

+5
source
 string[] filePath = Directory.GetFiles(fbdialog.SelectedPath.ToString(),".mp3", SearchOption.AllDirectories); foreach (string str in filePath) { MessageBox.Show("It mp3 file"); } 
+1
source

C # code:

 bool isMP3(byte[] buf) { if (buf[0] == 0xFF && (buf[1] & 0xF6) > 0xF0 && (buf[2] & 0xF0) != 0xF0) { return true; } return false; } 
-2
source

All Articles