wentnet.com Home
Misc Home
While writing XNJB, I found a few problems when using id3lib. Some of these are not documented so I hope this will save someone some time!
Reading unicode fields
id3lib has full support for reading unicode tags but I spent ages trying to get it to read unicode from the MP3 files I had. It turns out, if a file has ID3 version 1 tags, all fields are converted to ASCII so extra unicode information is lost. ID3 version 1 does not support unicode, ID3 version 2 does. So, for files with ID3 version 2, only read in the version 2 tags. For example:

// ID3V2 is the default - I can't get it to load unicode if not
size_t id3Size = myTag.Link(filename, ID3TT_ID3V2);
if (id3Size == 0)
  // try anything else
  myTag.Link(filename, ID3TT_ALL);
Writing unicode fields
Again, I found problems writing unicode fields to ID3 tags. This problem may be specific to Mac OS X but should be resolved to make code portable. There is a bug in io_helpers.cpp that causes unicode values to be written to files incorrectly. Unsigned chars are stored in a signed char array which are then cast to signed ints (implicitly). This means 'negative' chars gain 0xff in the three most significant bytes. This is fixed by changing the line

unicode_t ch = (data[i] << 8) | data[i+1];

of function writeUnicodeText() to

unicode_t ch = ((unsigned char)data[i] << 8) | (unsigned char)data[i+1];

This is mentioned in patch request id 1016290 on the id3lib Sourceforge page and will hopefully be included in the cvs/release code soon.
Copyright © 1999-2010 Richard Low. All trademarks on this page are owned by their respective owners. Hosting by Memset.