Skip to main content
Email Password   helpLost your password?

Introduction

There are many other articles at The Code Project describing the audio header and tag information, but none in VB.NET. So it's time to update my very old article (Reading and writing MP3 ID3v1 tags ) with nicer code and extend it to read the MPEG header information.

I don't want to go into detail about the structure of MPEG audio headers, because Konrad Windszus already has a very good article (MPEG Audio Frame Header) about that. If you're interested in the structure of the audio header or the ID3 tag format i recommend to visit the following sites:

Using the code

I wrote two classes to handle the header and tag information, called MP3Info and ID3v1Tag. The following code will show the structure to use the classes:

Dim objMP3Info As New _
 Monotic.Multimedia.MP3.MP3Info
With ListView1
    ''' Set the filename property

    objMP3Info.Filename = "c:\test.mp3"

    ''' Add the header information to a listview

    .Add("Filesize").SubItems.Add(objMP3Info.Filesize & " Byte")
    .Add("SamplingRateFrequency").SubItems.Add _
     (objMP3Info.SamplingRateFrequency & " Hz")
    .Add("Padding").SubItems.Add(objMP3Info.Padding & " Bytes")
    .Add("Private").SubItems.Add(objMP3Info.PrivateBit)
    .Add("Copyright").SubItems.Add(objMP3Info.Copyright)
    .Add("OriginalBit").SubItems.Add(objMP3Info.OriginalBit)
    .Add("Bitrate").SubItems.Add(objMP3Info.Bitrate & " bps")
    .Add("FrameSamples").SubItems.Add(objMP3Info.FrameSamples)
    .Add("FrameSize").SubItems.Add(objMP3Info.FrameSize & " Byte")
    .Add("Length").SubItems.Add(objMP3Info.Length & " s (" 
     & Int(objMP3Info.Length / 60) & ":" & _
      objMP3Info.Length Mod 60 & " m)")
    .Add("HeaderPosition").SubItems.Add(objMP3Info.HeaderPosition)
    .Add("VBRScale").SubItems.Add(objMP3Info.VBRScale)

    Select Case objMP3Info.MPEGVersion
        Case MP3.MPEGVersionEnum.MPEG1
            .Add("MPEGType").SubItems.Add("MPEG 1")
        Case MP3.MPEGVersionEnum.MPEG2
            .Add("MPEGType").SubItems.Add("MPEG 2")
        Case MP3.MPEGVersionEnum.MPEG25
            .Add("MPEGType").SubItems.Add("MPEG 2.5")
    End Select

    Select Case objMP3Info.Layer
        Case MP3.LayerEnum.LayerI
            .Add("Layer").SubItems.Add("Layer I")
        Case MP3.LayerEnum.LayerII
            .Add("Layer").SubItems.Add("Layer II")
        Case MP3.LayerEnum.LayerIII
            .Add("Layer").SubItems.Add("Layer III")
    End Select

    Select Case objMP3Info.Protection
        Case MP3.ProtectionEnum.None
            .Add("Protection").SubItems.Add("None")
        Case MP3.ProtectionEnum.CRC
            .Add("Protection").SubItems.Add("By CRC")
    End Select

    Select Case objMP3Info.ChannelMode
        Case MP3.ChannelModeEnum.DualChannel
            .Add("ChannelMode").SubItems.Add("Dual Channel")
        Case MP3.ChannelModeEnum.JointStereo
            .Add("ChannelMode").SubItems.Add("Joint Stereo")
        Case MP3.ChannelModeEnum.SingleChannel
            .Add("ChannelMode").SubItems.Add("Single Channel")
        Case MP3.ChannelModeEnum.Stereo
            .Add("ChannelMode").SubItems.Add("Stereo")
    End Select

    Select Case objMP3Info.Emphasis
        Case MP3.EmphasisEnum.CCIT
            .Add("Emphasis").SubItems.Add("CCIT")
        Case MP3.EmphasisEnum.MS5015
            .Add("Emphasis").SubItems.Add("50/15 ms")
        Case MP3.EmphasisEnum.None
            .Add("Emphasis").SubItems.Add("None")
    End Select

    Select Case objMP3Info.Encoding
        Case MP3.EncodingEnum.CBR
            .Add("Encoding").SubItems.Add("CBR")
        Case MP3.EncodingEnum.VBR
            .Add("Encoding").SubItems.Add("VBR")
    End Select

    ''' Add the ID3v1 tag information to a listview

    If (objMP3Info.ID3v1Tag.TagAvailable) Then
        .Add("ID3 Title").SubItems.Add _
         (objMP3Info.ID3v1Tag.Title)
        [...]
    End If

    ''' Update the tag

    objMP3Info.ID3v1Tag.Title = "Another title"
    objMP3Info.ID3v1Tag.Update()

End With

Please have a look at the sample and the class code to see all the features.

Points of Interest

Unlike other articles, this class will handle CBR and VBR encoded files, so the playtime is calculated correctly.

The class is well-commented with XML comments made by AxTools CodeSmart 2005 and NDoc . I included the generated HTML help file in the download.

I'm working on reading and writing the much more complex ID3v2.x tags at the moment (80% done, just compressed frames are a little bit tricky). If you are interested in this, i will update this article in the future.

History

27.02.2004 Release of version 1

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
QuestionHow to read the actual genre string when it is "other" Pin
a1penguin
18:05 18 Jun '09  
GeneralVBR File Pin
nitesh gaba
22:30 19 Mar '09  
QuestionWhat i write to the tag doesn't show up when viewing the property details in the file system. Pin
MattRoy10
15:11 18 Mar '09  
Generalhip hop songs and dance Pin
Jigga Hov
6:58 12 Dec '08  
GeneralGNU OpenSource Tag Library for .NET Pin
someonestupid1969
5:55 10 Dec '08  
GeneralSet mp3-Tag with objMP3Info Pin
squirrel91
0:45 28 Jul '07  
QuestionIs it? Pin
Rola /anglian/
1:03 12 Jun '07  
GeneralRemote MP3 Pin
ohadioe2
6:33 30 Apr '07  
GeneralOverFlow searching Genres Pin
ricsamma
18:25 15 Nov '06  
AnswerRe: OverFlow searching Genres Pin
Thommy Mewes
21:39 15 Nov '06  
GeneralAdding Info to a listbox Pin
John Dovey
3:36 7 Sep '06  
GeneralHow to use this dll in Exel Macro? Pin
strangerland
19:16 26 May '06  
AnswerRe: How to use this dll in Exel Macro? [modified] Pin
bill-tor
18:50 4 Jan '07  
GeneralBitrate problem Pin
Alberto Venditti
10:12 15 Feb '06  
GeneralRe: Bitrate problem Pin
AndyLang
16:17 15 Jul '07  
GeneralRe: Bitrate problem Pin
LegoMindstorms
11:44 5 Apr '08  
QuestionUpdate Missing Pin
Iftikhar Ali
0:54 17 Jan '06  
AnswerRe: Update Missing Pin
Thommy Mewes
9:44 17 Jan '06  
GeneralRe: Update Missing Pin
Iftikhar Ali
21:33 17 Jan '06  
GeneralPassword??? Pin
Godz1lla
13:44 1 Jan '06  
GeneralRe: Password??? Pin
Thommy Mewes
9:45 17 Jan '06  
GeneralException by reading header info from CD Pin
Ronny Foerster
21:03 29 May '05  
GeneralRe: Exception by reading header info from CD Pin
Thommy Mewes
13:21 16 Jun '05  
GeneralRe: Exception by reading header info from CD Pin
Jef Lagueux
13:59 21 Mar '06  
QuestionRe: Exception by reading header info from CD Pin
KaosKidd
5:11 7 Dec '06  


Last Updated 1 Mar 2005 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009