I'm trying to read and write a custom tag into a MP3 file. I followed this code here; adding custom tag using tagLib sharp library
I'm using Visual Studio 2015 and have done the following; Installed taglib-sharp with NuGet, running the following command in the Package Manager Console in Visual Studio.
PM> Install-Package taglib
Then added the C# code;
private void Write_Click(object sender, EventArgs e)
{
TagLib.Id3v2.Tag.DefaultVersion = 3;
TagLib.Id3v2.Tag.ForceDefaultVersion = true;
File f = File.Create(@"c:\Boy.mp3");
TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)f.GetTag(TagTypes.Id3v2);
PrivateFrame p = PrivateFrame.Get(t, "CustomKey", true);
p.PrivateData = System.Text.Encoding.Unicode.GetBytes("Sample Value");
f.Save();
f.Dispose();
}
private void Read_Click(object sender, EventArgs e)
{
File fa = File.Create(@"c:\Boy.mp3");
TagLib.Id3v2.Tag ta = (TagLib.Id3v2.Tag)fa.GetTag(TagTypes.Id3v2);
PrivateFrame pa = PrivateFrame.Get(ta, "CustomKey", false);
string data = Encoding.Unicode.GetString(pa.PrivateData.Data);
MessageBox.Show(data);
}
Now if I click Read_Click it fails, which is expected as I've not written the custom tag.
If I click Write_Click, the file modified date changes, however I get a ID3v1 Tag as well as the original ID3v2, however if I then open the file in Mp3Tag I don't see the custom Tag. But if I click the Read_Click it shows the value.
So I'm confused;
- Why I'm getting the ID3v1 tag
- Why the custom tag isn't visible in Mp3Tag
- If I open the file in a Hex Editor, I can't see "Sample Value"
What am I doing wrong??
Thanks in advance for your help