alex - 2012-01-06

Hi,
I'm trying to add an "Album Artist" tag to MP3 files in my library that don't have it.  The code I'm using is this:

struct id3_frame* frame = id3_frame_new(fieldId.c_str()); // fieldId has value "TPE2"
// If frame is zero, too bad
id3_ucs4_t aString;
id3_ucs4_t* strings = { aString };
int arrLen = stringToArray(value, aString); // stringToArray converts 1-byte chars to 4-byte ints
if (arrLen != value.length()) {
cerr << "addField: unexpected length " << arrLen << " from stringToArray.  Expected " << value.length() << endl;
}
frame->fields = (union id3_field*)malloc(2*sizeof(union id3_field));
frame->nfields = 2;
for (int j = 0; j < 4; ++j) { frame->id = fieldId.c_str(); }
frame->id = 0;

frame->fields.type = ID3_FIELD_TYPE_TEXTENCODING;
frame->fields.number.type = ID3_FIELD_TYPE_TEXTENCODING;
frame->fields.number.value = 0;

frame->fields.type = ID3_FIELD_TYPE_STRINGLIST;
frame->fields.stringlist.type = ID3_FIELD_TYPE_STRINGLIST;

if (0 != id3_field_setstrings(&frame->fields, 1, strings)) {
throw id3FieldSetstringsFailed;
}

frame->refcount = 1;

// TODO: this call has no effect on the output file
if (0 != id3_tag_attachframe(fileDescriptor->tags.tag, frame)) {
attachFailed.msg = string("Id3FileManager::addField: Failed to attach new frame for field ") + fieldName;
throw attachFailed;
}

// TODO: this call has no effect after writing the file and then reading it again on the next run.
/***/
if (0 != id3_tag_attachframe(fileDescriptor->primary, frame)) {
attachFailed.msg = string("Id3FileManager::addField: Failed to attach new frame to primary ") + fieldName;
throw attachFailed;
}

After this, there's a call to id3_file_update and then id3_file_close.
This doesn't seem to add any tags to the file.  What am I doing wrong?

Thanks
ALex