I need to delete all of the id3 tags from an mp3 file. I have tried this:
byte[] a = System.IO.File.ReadAllBytes("X.mp3");
int x = 0;
int b=3;
for (int i = 6; i <= 9; i++)
{
x += (a[i] << (b * 7));
b--;
}
byte[] r = new byte[a.Length-x];
for (int i = x; i < a.Length; i++)
{
r[i-x] = a[i];
}
System.IO.File.WriteAllBytes("X.mp3", r);
But it does not delete all of the id3 tags. I think there is a problem in calculating the size of tag but I do not know what is wrong ?
Your code only addresses ID3v2 tags, at the beginning of the file. If your MP3 file has both types of ID3 - ID3v1 and ID3v2 - you'll need to remove both.
ID3v1 tags are placed at the end of the file and are fixed-length. They'd actually be easier to strip - they are always the last 128 bytes of the file, and start with the text "TAG".
You might be better served by using a pre-existing library to work with the MP3 files; one such is the open-source library, taglib-sharp. It can manipulate both types of ID3 tags, as well as perform a variety of other tasks.