Using TagLib To Create MediaExplorer GridView For MP3 Files

Download Sample Projects

In my earlier post Manipulating Media MP3 Files, I touched upon use of IdSharp library to manipulate MP3 files. But multimedia files are not just limited to MP3 files. There are few other popular formats as well e.g. WMA, MP4, WAV etc. And in this age and time, we all have an extensive library of digital music and video files sitting on our machines. Growth of these files on our machines is exponential. Before we realize, there are so many of them that it becomes hard to keep track of them. And soon you will find your self in a situation where you will duplicate copies of sames songs or videos.

I decided to catalog all the multimedia files on my file servers in database so I could perform some simple search operations based on some criteria like:

  • Artist(s)
  • Year of Release
  • Album
  • Type

And lot other criteria as well. You can catalog your collection without going through painful data entry process of looking at each file and then trying to figure out what it is and then punching some keys to enter the data in database. There is a much simpler process. There is another great library TagLib that have a C# version as well. This library handles more file formats other than just MP3. I just created a simple class that returns collection of objects containing meta data of these multimedia files. Usage of TagLib is as simple as one line of code. See the following code snippet.


private void Initialize()
{
 if (string.IsNullOrEmpty(FilePath))
 {
  throw new ArgumentException("No file path specified");
 }
 FileName = System.IO.Path.GetFileName(FilePath);
 TagFile = TagLib.File.Create(FilePath);
}

And a very simple method that takes folder that contains multimedia files and then iterates over these files to prepare a collection of meta data objects.


public List<MediaFile> GetFiles()
{
 List<MediaFile> mediaFiles = new List<MediaFile>();
 string [] files = Directory.GetFiles(Folder);
 foreach(string file in files)
 {
  try
  {
   MediaFile mediaFile = new MediaFile(file);
   mediaFiles.Add(mediaFile);
  }
  catch (Exception ex)
  {
   // Exceptions thrown here may be harmless. It could be that
   // files are not media type files
  }
 }
 return mediaFiles;
}

Based on these simple class libraries I created a simple application that creates a windows explorer like view of folder containing multimedia files. I used GridView control to bind it to list of MediaFile objects. You can try the attached sample project. Assembly for TagLib library is contained in BIN folder of ASP.Net web application.

Views: 1330

Related

How to use Silverlight control in ASP.Net GridView or DataGridHow to use Silverlight control in ASP.Net GridView or DataGridInsert new row in GridViewHow to insert new row in ASP.Net GridView control?How to add search providers in Internet ExplorerHow to add new search provider in Internet Explorer and use different type of search providers in In...Bind ASP.Net GridView Using LinqHow to use Linq with ASP.Net GridView?How to insert DropdownList control in GridViewHow to insert DropdownList control in a GridView Control in ASP.Net application

Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli

By Categories