14

I want to add text to a custom tag, to an MP3-file. I tried doing like this, but I can't get the tag to change.

This is my code for now:

TagLib.File f = TagLib.File.Create(@"C:\Users\spunit\Desktop\denna.mp3");
TagLib.Id3v2.Tag t = (TagLib.Id3v2.Tag)f.GetTag(TagTypes.Id3v2);
PrivateFrame p = PrivateFrame.Get(t, "albumtype", true);
p.PrivateData = System.Text.Encoding.Unicode.GetBytes("TAG CHANGED");
f.Tag.Album = "test";
f.Save();

I get the album tag to change, but not the albumtype tag. Am I missing something?

spunit
  • 523
  • 2
  • 6
  • 23

2 Answers2

5

Unfortunately Id3v2 has a set specification which does not allow custom tags, as defined here.

The code you've referenced from another question does work, you just need to include the reader method to return the private frame data.

See also this question on the Unix Stack Exchange where someone encountered the same problem - an alternative solution could be to use the UserDefinedText tag.

Chawin
  • 1,438
  • 1
  • 21
  • 33
  • So... It is not possible? But I can change and set custom tags for mp3 files in a program called foobar2000. Here is a screenshot of some of my custom tags: https://imgur.com/ksAoZ7D These are the tags that I want to be able to change in C#. – spunit Oct 24 '17 at 19:12
  • @spunit See [this thread](https://hydrogenaud.io/index.php/topic,61938.0.html) on the foobar2000 forum - all non-native supported field names are stored in the `UserDefinedText` field, they do not have their own custom tag. – Chawin Oct 25 '17 at 07:35
  • Oh I see, so that is how it works. Then add / change UserDefinedText is what I want to do. Do you know how to do this in C#? – spunit Oct 25 '17 at 17:44
  • `UserDefinedText` is the TXXX frame, so `t.SetTextFrame("TXXX", "Your info");` should work – Chawin Oct 26 '17 at 07:48
  • I tried this out, but my result is strange... It Allways changes my albumtype, regardless of what is in the code... For example this changes my albumtype: https://imgur.com/tWdv8bq What the hell...? – spunit Oct 28 '17 at 12:24
  • I'm not sure how else to help - I'm running VS2015 and testing on a generic .mp3 file and everything works as expected – Chawin Oct 31 '17 at 15:10
  • 1
    Really strange... Must be something wrong on my end... Anyway, your help has been much appreciated, thanks for all your time and effort. I'll give thumbs up and accept your answer =) – spunit Nov 01 '17 at 19:43
0

TagLib allows to set custom headers as defined here.

var tfile = TagLib.File.Create(@"C:\My song.flac");
var custom = (TagLib.Ogg.XiphComment) tfile.GetTag(TagLib.TagTypes.Xiph);

// Read
string [] myfields = custom.GetField("MY_TAG");
Console.WriteLine("First MY_TAG entry: {0}", myfields[0]);

// Write
custom.SetField("MY_TAG", new string[] { "value1", "value2" });
custom.RemoveField("OTHER_FIELD");
rgFile.Save();
TheBlueOne
  • 486
  • 5
  • 13