Reading Tags From Mp3 Files
In this post i will show you how to read the Tags like Album,Artist,Song Title,Year etc from mp3 , avi , ogg, Asf, Divx, png etc..
You will need Taglib - Sharp Library for this purpose .
Download the Library : http://download.banshee.fm/taglib-sharp/
you will find taglib-sharp.dll That's what we need.
1. Create a project . Name it something like TagReader
2. Add reference to the taglib-sharp.dll
3. Make a Form look something like below figure.


Most of the Coding is Understandable so i will put the Whole form's coding.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using TagLib;
namespace TagReadermp3
{
public partial class frmTagReader : Form
{
public frmTagReader()
{
InitializeComponent();
}
private void btnSelect_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Mp3 Files | *.mp3";
if (ofd.ShowDialog() == DialogResult.OK)
{
lblFile.Text = ofd.FileName;
}
}
private void btnRead_Click(object sender, EventArgs e)
{
TagLib.File mp3 = TagLib.File.Create(lblFile.Text);
lblAlbum.Text = mp3.Tag.Album;
lblAritst.Text = GetAllStringsFromArrary(mp3.Tag.AlbumArtists,","); // Tag.AlbumAritst is a string array
lblBitsPerMinute.Text = mp3.Tag.BeatsPerMinute.ToString();
lblComposers.Text = GetAllStringsFromArrary(mp3.Tag.Composers,",");
lblCopyright.Text = mp3.Tag.Copyright;
lblGenre.Text = GetAllStringsFromArrary(mp3.Tag.Genres,",");
lblTitle.Text = mp3.Tag.Title;
lblTrack.Text = mp3.Tag.Track.ToString();
lblYear.Text = mp3.Tag.Year.ToString();
lblLength.Text = mp3.Properties.Duration.ToString();
}
public string GetAllStringsFromArrary(string[] strArray,string strDelimeter)
{
string strFinal = string.Empty;
for (int i = 0; i < strArray.Length ; i++)
{
strFinal += strArray[i];
if (i != strArray.Length - 1)
{
strFinal += strDelimeter;
}
}
return strFinal;
}
}
}
**New Length field added
Here is the Link to Complete Project : Tag Reader (Updated)
TagReader (old)

浙公网安备 33010602011771号