Retrive Mp3 ID3 tag Information

No.of Views2425
Bookmarked0 times
Downloads 
Votes0
By  kirtan007   On  16 Feb 2010 00:02:48
Tag : CSharp , Miscellaneous
Retrive Mp3 ID3 tag Information
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

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.



Image loading...

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.

Image Loading..

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


 
Sign Up to vote for this article
 
About Author
 
kirtan007
Occupation-
Company-
Member Type-Senior
Location-Not Provided
Joined date-02 Jul 2009
Home Page-http://kirtan.uni.cc
Blog Page-
He completed his Bachelor of Computer Application from Gujarat University 2009 .He is doing Master of Computer Application from Gujarat Technological University right now .. His area of Interests are Web Hacking , C# .net Windows form ,asp.net , WPF ,Silverlight ,SQL Server and Some PHP.
 
 
Other popularSectionarticles
Comments
By:ChrisDate Of Posted:2/7/2011 7:39:07 PM
This is really good but....
This looks really cool but from my newbie point of view I cant get past this error, // Add information From Array to ListView ListViewItem item = new ListViewItem(SongInfo); listView1.Items.Add(item); Error 3 The best overloaded method match for 'System.Web.UI.WebControls.ListViewItem.ListViewItem(System.Web.UI.WebControls.ListViewItemType)' has some invalid arguments I am a newbie. Can I see what I should put in the aspx page to display the code?
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top