CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2002
    Location
    Iowa State University
    Posts
    2

    Lightbulb Reading the ID3 tag from an MP3

    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

  2. #2
    Join Date
    Oct 2002
    Location
    Växjö, Sweden
    Posts
    225
    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.

    Code:
    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
    Last edited by Athley; November 8th, 2002 at 07:20 AM.

  3. #3
    Join Date
    Jul 2002
    Location
    .NET 2.0/.NET 3.0/.NET 3.5 VS2005/VS2008
    Posts
    284
    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.
    WM.

    What about weapons of mass construction?

  4. #4
    Join Date
    Oct 2002
    Location
    Växjö, Sweden
    Posts
    225
    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 ).

    /Leyan

  5. #5
    Join Date
    Nov 2002
    Location
    Iowa State University
    Posts
    2
    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

  6. #6
    Join Date
    Nov 2001
    Posts
    69
    May be you can look in to http://www.id3lib.org/ for some formal information on the id3 tags.]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured