Read Header Information from MP3 Files

Problem

You need to read information about the song, artist, and album from an MP3 file.

Solution

Read the ID3v2 tag from the end of the MP3 file.

Discussion

Most MP3 files store information in a 128-byte ID3v2 tag at the end of the file. This tag starts with the word TAG and contains information about the artist, album, and song title in ASCII encoding. You can convert this data from bytes into a string using the Encoding object returned by the System.Text.Encoding.ASCII property.

The MP3TagData class shown here provides access to MP3 data, and it provides a ReadFromFile method that retrieves the information from a valid MP3 file.

Public Class MP3TagData Private _Artist As String Private _SongTitle As String Private ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.