vendredi 20 février 2015

Charset error while reading ID3 tags

I'm trying to retrieve ID3 tags from mp3 files by using Java ID3Tag Library. But I get some errors while retrieving strings with special characters (çáêü...). So I've converted these strings to byte arrays:



ID3v2_4 tag=(ID3v2_4) mp3file.getID3v2Tag();
byte [] artBytes=tag.getLeadArtist().getBytes();
for (int i=0;i<artBytes.length;i++){
System.out.println(artBytes[i]);
}


And then I've found that every "unknown" char (as well as the first bytes in the string) has been read as the three-byte sequence -17 -65 -67 ("�" in the string). Also, after each letter there is a byte 0. So, if I want to read "Blue Öyster Cult" ,I get something like "��B l u e � y s t e r C u l t".


What can I do to normalize these strings?


[EDIT]




  • A few mp3 files with special characters are displayed correctly.




  • Reading from charsets like US_ASCII or ISO_8859_1 will cause the char � to be displayed as byte 63.




Aucun commentaire:

Enregistrer un commentaire