1

I'm trying to copy all ID3v2 tags from one file to another. But my code does not work (the tags remain unchanged) and I do not know why.

ID3_Tag sFile, tFile;

sFile.Link("source.mp3", ID3TT_ID3V2);
tFile.Link("target.mp3");

tFile.Strip();

ID3_Tag::Iterator* sFrItr = sFile.CreateIterator();
ID3_Frame* sFrame = NULL;
while (NULL != (sFrame = sFrItr->GetNext()))
{
    tFile.AddFrame(sFrame);
}
delete sFrItr;

tFile.Update();

This code is mostly based on id3lib API example. I didn't have anything to do with id3 earlier, so I might just not be understanding how the frames and fields work.

burtek
  • 2,576
  • 7
  • 29
  • 37

1 Answers1

1

The problem is, that when Update() is triggered, the ID3_Frames added to tFile do not exist anymore. The correct way is to create pointers to copies of ID3_Frames and attach them to the ID3_Tag:

while (NULL != (sFrame = sFrItr->GetNext()))
{
    tFile.AttachFrame(new ID3_Frame(*sFrame));
}

AttachFrame() takes care of the memory and deletes the data itself afterwards.

burtek
  • 2,576
  • 7
  • 29
  • 37