Click here to Skip to main content
11,920,211 members (47,814 online)
Click here to Skip to main content
Add your own
alternative version


27 bookmarked

MP3 ID3v1 Editor

, 18 Jan 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Edit many ID3v1 at the same time


This application is for read and write ID3v1 information of mp3 files. As i explain the codes i explain how ID3v1 works.

ID3 is some part of mp3 files that contains information about that file. like the title of song or artist name and etc...

ID3 have 2 major versions and this program is for working with version one. and read or write ID3v1 data. for more information about ID3 visit

Read ID3v1.1

Declare a buffer for read from file:

Public buffer(128) As Byte

ID3v1 is at the end of file and ID3v2 is at the begining of the file. so for open ID3v1 we need to read file from the end. Lenght of ID3v1 is fix and it's 128 bytes (it's because the buffer size is 128 bytes). Make a stream to file for read 128 bytes of file from end.

If mp3File.Length > 128 Then
    Dim mp3Reader As Stream = mp3File.OpenRead()
    mp3Reader.Seek(-128, SeekOrigin.End)
    Dim i As Integer
    For i = 0 To 127
        buffer(i) = mp3Reader.ReadByte
End If
note: if the file lenght was fewer than 128 bytes, it's clear that file don't have ID3v1 because ID3v1 size is fix and it's 128 bytes

As you can see with this code we save all 128 byte of file to buffer. Next step is check if buffer contain ID3 data. if first 3 bytes of buffer was "TAG" it means the file have ID3v1 and if not it means file don't have ID3v1. we check it with following 'if':

If Encoding.Default.GetString(buffer, 0, 3).Equals("TAG") Then

 'Read Data

End If

How to read data ? theres some kind of standard that you must know for reading this data. let me say how read data from our buffer. the bytes 0 to 2 as you saw must be equal to "TAG".

  • 3 to 32 Contain Title ( 30 Characters )
  • 33 to 62 is Artist ( 30 Characters )
  • 63 to 92 is Album name ( 30 Characters )
  • 93 to 96 is Year ( 4 Characters )
  • 97 to 125 is Comment ( 28 Characters )
  • 126 is Track Number ( 1 Character )
  • 127 is Genre ( 1 Character )

With this information we read ID3v1 data with following codes:

_Title = Encoding.Default.GetString(buffer, 3, 30)
_Artist = Encoding.Default.GetString(buffer, 33, 30)
_Album = Encoding.Default.GetString(buffer, 63, 30)
_Year = Encoding.Default.GetString(buffer, 93, 4)
_Comment = Encoding.Default.GetString(buffer, 97, 28)
_TitleNumber = Convert.ToInt32(buffer(126).ToString())
If Convert.ToInt32(buffer(127)) > 0 Then
    _Genre = Convert.ToInt16(buffer(127))
End If
note: The Genre number is standard and we don't have definition for numbers greater than 127. it's because the code control control Genre to understand if it's smaller than 127

If file includes ID3 we set _HasTag and _HadTag to true else we set them false. we need to know if file Had Tag it need for write ID3 as you will see.

We have some public properties for Title, Artist, Album, Year, Comment, TrackNumber and Genre.

In main application we must read information with this properties and set them if we need and then call WriteID3

Write ID3v1.1

For write ID3 Data first we must fill our buffer with variables data. to do this run this code:

buffer.Clear(buffer, 0, 128)
Encoding.Default.GetBytes("TAG".ToUpper.ToCharArray()).CopyTo(buffer, 0)
Encoding.Default.GetBytes(_Title.ToCharArray()).CopyTo(buffer, 3)
Encoding.Default.GetBytes(_Artist.ToCharArray()).CopyTo(buffer, 33)
Encoding.Default.GetBytes(_Album.ToCharArray()).CopyTo(buffer, 63)
Encoding.Default.GetBytes(_Year.ToCharArray()).CopyTo(buffer, 93)
Encoding.Default.GetBytes(_Comment.ToCharArray()).CopyTo(buffer, 97)
buffer(126) = _TitleNumber
buffer(127) = Convert.ToInt32(_Genre)

As you see we cleared the buffer and then fill the buffer with variables data. As we said before first three bytes must be "TAG". remember "TAG" is case sensitive you can't use "Tag" or "TaG" or any thing except "TAG".

We need to open file for write data

Dim mp3Writer As FileStream = mp3File.OpenWrite()

If the file has tag now and had it before it means we must start overwrite data to final 128 bytes. and if file hadn't tag but now it have. it means we must write data at the end of file. or file had tag before and don't have tag now it means we must delete 128 bytes from end.

If _HasTag And _HadTag Then
   mp3Writer.Seek(-128, SeekOrigin.End)
   mp3Writer.Write(buffer, 0, 128)
ElseIf (Not _HadTag) And _HasTag Then
   mp3Writer.Seek(0, SeekOrigin.End)
   mp3Writer.Write(buffer, 0, 128)
   _HadTag = True
ElseIf _HadTag And (Not _HasTag) Then
   _HadTag = False
   mp3Writer.SetLength(mp3Writer.Length - 128)
End If
note: Of course it's clear that if file didn't have tag and now don't have either we must not do some special thing

For those that more relax with C# visit


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Hamed J.I
Web Developer
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I began programming with C/C++ when i was 15. Then try to learn VC++ but at the middle of my reading .NET came.

I began to read C# and VB.NET and also began designing basic websites by FrontPage and developed some websites for our school and some other companis.

Later learn Microcontroller and design some digital circuits with PIC microcontrollers for a industrial controller company.

As I learned SQL and ASP.NET developed some website such as news portals that are active now.

Now i'm a software student and teach programming in computer institues. And have my own job by getting projects from companies.

You may also be interested in...

Comments and Discussions

GeneralChange Audio sample rate in Pin
m.yazdian12-Apr-11 22:31
memberm.yazdian12-Apr-11 22:31 
Generalhi Pin
Member 389772426-Mar-08 0:37
memberMember 389772426-Mar-08 0:37 
Generalhelp Pin
Member 389772417-Mar-08 1:06
memberMember 389772417-Mar-08 1:06 
GeneralRe: help Pin
Member 389772426-Mar-08 0:16
memberMember 389772426-Mar-08 0:16 
QuestionMP3 ID3v1 Editor and VB 2005 Express Edition Pin
treble199915-Nov-07 5:31
membertreble199915-Nov-07 5:31 
GeneralThank you Pin
imanali30-Dec-06 23:55
memberimanali30-Dec-06 23:55 
GeneralNeed Help: How to Fade an mp3 or wav Pin
pinoylandia23-May-06 16:04
memberpinoylandia23-May-06 16:04 
GeneralRe: Need Help: How to Fade an mp3 or wav Pin
Hamed_ji31-Jul-06 13:26
memberHamed_ji31-Jul-06 13:26 
GeneralRemove id3 Pin
QCPBraca15-Mar-06 16:03
memberQCPBraca15-Mar-06 16:03 
GeneralRe: Remove id3 Pin
Hamed_ji16-Mar-06 5:21
memberHamed_ji16-Mar-06 5:21 
GeneralRe: Remove id3 Pin
QCPBraca20-Mar-06 23:16
memberQCPBraca20-Mar-06 23:16 
GeneralRe: Remove id3 Pin
Hamed_ji21-Mar-06 8:58
memberHamed_ji21-Mar-06 8:58 
GeneralRe: Remove id3 Pin
QCPBraca21-Mar-06 22:00
memberQCPBraca21-Mar-06 22:00 
GeneralNot bad... Pin
HyperX21-Feb-06 12:15
memberHyperX21-Feb-06 12:15 
GeneralSource File missing Pin
Iftikhar Ali17-Jan-06 1:11
memberIftikhar Ali17-Jan-06 1:11 
GeneralRe: Source File missing Pin
Hamed_ji18-Jan-06 1:10
memberHamed_ji18-Jan-06 1:10 
GeneralNot very well written. Pin
lintball11-Jan-06 9:48
memberlintball11-Jan-06 9:48 
JokeRe: Not very well written. Pin
RunyonAveSoulja5-Sep-06 6:54
memberRunyonAveSoulja5-Sep-06 6:54 
QuestionCode? Pin
Bojan Rajkovic11-Jan-06 8:29
memberBojan Rajkovic11-Jan-06 8:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151120.1 | Last Updated 18 Jan 2006
Article Copyright 2006 by Hamed J.I
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid