Click to See Complete Forum and Search --> : Reading the ID3 tag from an MP3


bc3tech
November 7th, 2002, 09:02 PM
my research shows me that the ID3 tag is stored in the last 128 bytes of an MP3 file. i want to read out this last 128 bytes of the MP3 file into a variable so i can mess with it then write it back in. i can't figure out how to get VB.NET's binaryRead and Write objects to work even after visiting MSDN... please help. thanks

brandon

Athley
November 8th, 2002, 04:12 AM
Never done this before so dont rate this as THE solution, there might be better ways to do this. But this worked for me. I had a form with a button1 and a textbox1 control and the following code in the event handler for the button.

Dim s As Stream = File.OpenRead("c:\Test.mp3")
Dim br As New BinaryReader(s)
Dim c As Integer
Dim sb As New System.Text.StringBuilder()

s.Seek(s.Length - 128, SeekOrigin.Begin)

For c = 1 To 128
sb.Append(Strings.Chr(br.ReadByte))
Next

TextBox1.Text = sb.ToString

The writing is as easy, just use a BinaryWriter object with the Write method instead.

/Leyan

WillemM
November 8th, 2002, 08:37 AM
http://www.csharphelp.com/archives/archive226.html Take a look here. This site has a class that is used for reading and editing id3 tags from mp3 files.

It's a bit pitty that it is in C#. But I hope you have any use of this.

Athley
November 8th, 2002, 09:04 AM
Ahh, nice example. Shouldn't be to hard to translate into VB. It does almost exactly as I did in my example aside from that it uses a FileStream object instead of a Stream. That may increase performance a bit.

And their use of System.Text.ASCIIEncoding instead of my a bit clumbsy Strings.Chr(br.ReadByte) is more consize (as I said, it wasn't THE solution :D ).

/Leyan

bc3tech
November 8th, 2002, 11:05 AM
Thanks guys, i'm going to be trying to re-write that C# version (because i really like it) into VB.NET code. i'll post a URL for the src when i'm done.

brandon

teejbee
March 21st, 2003, 09:11 AM
May be you can look in to http://www.id3lib.org/ for some formal information on the id3 tags.]