Introduction
Ever wanted to know how to retrive detailed information of MP3 File ( ID3 tag) like Artist , Comments , Year , Album information this is right article for you .
Here is screenshot what will be out final product.

Technologies:
.net 2.0/3.5
Language:
C#
Prerequisite
1. .NET Framework 3.5/2.0
2. Visual Studio 2008/2005
3. Taglib# Library Download it From http://developer.novell.com/wiki/index.php/TagLib_Sharp
Implementation
Now assumes that you have all prerequestites .
1 .add reference to the taglib# library from project menu like below and browse to your taglib# where you downloaded it.

2. define namespace
{codecitation class="brush: csharp; gutter: true;" width="650px"} using TagLib;
{/codecitation} and also {codecitation class="brush: csharp; gutter: true;" width="650px"}
using System.IO;
{/codecitation}
because we are dealing with the File IO operations also
now we are making application that will scan Mp3 files in Perticular directory recursivly and retrive information about those found mp3 files and Add them to ListView
4. Setup GUI like Ubove Image Provided .
5. We are Just Coding one Function "Scan Directory() " that will Recursively Scan Directory and add Information About Mp3 in ListView .
the Function code is very Simple as it Self Explanery
{codecitation class="brush: csharp; gutter: true;" width="650px"} public void ScanDirectory(string DirectoryName) { string Genre; long Length; string Album; string FileName; string Year; string Comment; foreach (string strFile in Directory.GetFiles(DirectoryName)) { FileInfo finfo = new FileInfo(strFile); // Check if File is Mp3 get the Info about it if (string.Compare(finfo.Extension, ".mp3", true) == 0) { try { //Here We have to Specifly name space explicitly because both System.IO and TagLib having same File Class TagLib.File f = TagLib.File.Create(finfo.FullName); //Get Information About File FileName = f.Name.ToString(); Genre = f.Tag.FirstGenre; Album = f.Tag.Album.ToString(); Year = f.Tag.Year.ToString(); Length = finfo.Length; Comment = f.Tag.Comment; string[] SongInfo = new string[6]; SongInfo[0] = FileName; SongInfo[1] = Genre; SongInfo[2] = Album; SongInfo[3] = Convert.ToInt32(Length.ToString()) / (1024 * 1024) + " MB"; SongInfo[4] = Year; SongInfo[5] = Comment; // Add information From Array to ListView ListViewItem litem = new ListViewItem(SongInfo); listView1.Items.Add(litem); } catch { } }
}
//Scan Subfolders in Directory foreach (string subDirectory in Directory.GetDirectories(DirectoryName)) { ScanDirectory(subDirectory); }
}
{/codecitation}
6. Call the Function When Scan button is Clicked after Selecting path of the Folder .
7. You are done !!
Conclusion
Article Explaines how to retrive Mp3 ID3 tag information .
Thanks .
| About the Author |
 |
| Kirtan Patel | - Bachelor of Computer Application . - File Handling with C# - Registry Programming With C#. - Knowledge of Virus Programming . - Working With third party controls like Telerik and Component Factory . - P/invoke Win32 API. - SQL Server Database Applications - Client/Server Database Programming Expertise in : C# , Asp.net ,Vb.net , SQL Server , Designing Elegant look Web interface Familiar With : C/C++ , Core Java , Java Script , Dream weaver templates , fire Works ,PHP ,Photo shop and Graphics Databases: Microsoft SQL Server 2005 , Microsoft Access and Some MySQL Occupation: Student |
|
|