Reading Tags From Mp3 Files

1:54 AM
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)

1 comments:

{ Jimmy Johns } at: March 26, 2015 at 1:33 AM said...

Mp3 Tagger Zortam Mp3 Media Studio is all-in-one Mp3 application suite. It has several modules such us Zortam Mp3 Auto Tagger, Mp3 Organizer, ID3 Tag Editor, Mp3 Player, Mp3 Normalizer, CD Ripper, Mp3 to Wav converter. With Zortam Mp3 Media Studio you can batch auto tag your Mp3 files using Zortam database. Batch auto tag process download Cover Art, Lyrics and other metadata and automatically tags your Mp3 files.

Post a Comment