0

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;

  1. Why I'm getting the ID3v1 tag
  2. Why the custom tag isn't visible in Mp3Tag
  3. 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

Community
  • 1
  • 1
HeavyHead
  • 310
  • 3
  • 11

1 Answers1

0

Answers:

1: Taglib sharp saving ONLY ID3v2

2: As far as I know, Mp3tag only shows "standard" ID3 tags, but never private frames (https://forums.mp3tag.de/index.php?showtopic=4082)

3: How do you search for "Sample Value"? Maybe it is written encoded?

Community
  • 1
  • 1
PeterCo
  • 910
  • 2
  • 20
  • 36