ID3V2 Detect and Manipulate MP3 file format using C# with Idsharp Library

by Viper 21. March 2009 18:18

Long time ago I wrote an article Detect file type or mime type based on content. If you look at the XML file that contained magic signature of different file types, one of the type was MP3 files. And magic signature for MP3 files is that first 3 bytes of file content are ID3. The format of MP3 files is very well defined and explained at ID3.org. Although it is very well defined but it is not something very straight forward and not a job for faint heart to understand it.

For one of new development adventure I am tasked with digging little bit deep into file structure of MP3 files and find out some meta data. Things like Artist Name, Title, Track Number, Year Of Release etc. So I looked around the site and found reference to IDSharp library developed for .Net and is COM visible as well. So you can use it in any application that can invoke COM interfaces. The library is available on sourceforge. But there is no source code for the actual core library. It is only available as .Net assembly. I really needed source code for it because I was curious about implementation and I had to make some modifications as well for the kind of work I was doing.

So I fired up good old tool Reflector and dis-assembled the assembly to generate the source code for it. I had to fix few compile errors after disassembly. But finally I made it to work as expected. So I thought I will share the source code of IdSharp library with people who are interested in it.

Download Source Code For IdSharp Library

From the following code snippet you can see how you can load a MP3 file to get all information about the file. And then you can actually change ID3 tag information as well and save the file with new information. In the sample code, I changed the name of the artist as well as album name. You can see from the screen shot that it did work.

static void Main(string[] args)
{
var id3v2 = ID3v2Helper.CreateID3v2("Hello.mp3");
Console.WriteLine("Artist: {0}", id3v2.Artist);
Console.WriteLine("Title: {0}", id3v2.Title);
Console.WriteLine("Album: {0}", id3v2.Album);
Console.WriteLine("Genre: {0}", id3v2.Genre);
Console.WriteLine("Year: {0}", id3v2.Year);
Console.WriteLine("TrackNumber: {0}", id3v2.TrackNumber);
Console.WriteLine("Media Type: {0}", id3v2.MediaType);
Console.WriteLine("CD Identifier: {0}", id3v2.MusicCDIdentifier.TOC);
id3v2.Artist = "Byteblocks.com";
id3v2.Title = "ID3v2 Song";
id3v2.Save("Bytes.mp3");
}

Give your advice to big bosses and make money

Views: 7100

Tags: , , ,

.Net | C# | Mime Type | File Format

Comments

6/11/2009 4:25:09 AM #

zcy

谢谢,thanks

zcy People's Republic of China

8/26/2009 5:58:42 AM #

asim

it does not have project file...

asim United States

8/26/2009 6:07:31 AM #

asim

i mean it does not have a project sln file....

asim United States

10/7/2009 7:08:24 AM #

best toaster

Thanks for info

best toaster United Kingdom

10/14/2009 9:49:30 PM #

Search engine optimization

Hi,
   Excellent post.This was actually what I was looking for, and I am glad that I finally came here! This for sharing and keep up the good work...

Search engine optimization United States

10/14/2009 9:50:35 PM #

Search engine optimization

Hi,
   Excellent post.This was actually what I was looking for, and I am glad that I finally came here! This for sharing and keep up the good work...

Search engine optimization United States

10/14/2009 10:26:05 PM #

XRF

HI,
   Excellent post.I want to thank you for this informative read, I really appreciate sharing this great post. Keep up your work…

XRF United States

10/16/2009 2:37:17 AM #

cash advance

Yea nice Work !Laughing

cash advance United States

10/19/2009 11:42:41 AM #

cash loans

Do you have any more info on this?

cash loans United States

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli

By Categories