开发者

Reading/writing Unicode to ID3v2 using jid3lib

I'm trying to write an application u开发者_StackOverflow中文版sing jid3lib and have pretty much everything working in terms of reading/writing id3v1 but for v2 unicode I can't figure out the best course of action for converting the unicode to a usable string and then reencoding it to write back to the frame.

I found CharsetDecoder and CharsetEncoder but they don't seem to change anything.

MP3File mp3file = new MP3File(f);
AbstractID3v2 tag = mp3file.getID3v2Tag();
String title = tag.getSongTitle();
System.out.println("Title : " + convertCharset(title));

where convertCharset is:

private static String convertCharset(String text) {
    Charset charset = Charset.forName("ISO-8859-1");
    CharsetDecoder decoder = charset.newDecoder();
    CharsetEncoder encoder = charset.newEncoder();
    try {
        ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(text));
        CharBuffer cbuf = decoder.decode(bbuf);
        return cbuf.toString();
    } catch (CharacterCodingException e) {
        e.printStackTrace();
    }
    return null;
}

The output comes out like this: http://i.stack.imgur.com/RLbKe.png

Many thanks in advance for any help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜