14
votes

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?

2
Anyone? I still haven't gotten this to work. - spunit
Still no ideas? =( - spunit
So to clarify, you need to change (not add) "albumtype" tag and it doesn't work with provided code, while changing "album" tag works? - Evk
Both change or add I guess (I want to set it to some text). Either way it does nothing. Change or add the "album" tag always works. - spunit

2 Answers

5
votes

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.

0
votes

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();