mpatric / mp3agic

A java library for reading mp3 files and reading / manipulating the ID3 tags (ID3v1 and ID3v2.2 through ID3v2.4).
MIT License
1.2k stars 310 forks source link

Reading Chinese encoded tags seems to sometimes have problems. #197

Open joe-vettek opened 2 years ago

joe-vettek commented 2 years ago

my code is like this:

                mp3file.save(basePath + tt);
                id3v22Tag.setEncoder("2");
                mp3file.setId3v2Tag(id3v22Tag);
                id3v22Tag = mp3file.getId3v2Tag();
                if (id3v22Tag.getAlbum() != null && !id3v22Tag.getAlbum().isEmpty()) 
                    this.album = id3v22Tag.getAlbum();

I've tried tweaking the encoder to salvage the bad encoding, but it doesn't seem to work. The library outputs UTF-8 encoding by default, while Chinese encoding is sometimes GBK. But the result always shows like this: OutPut: ×÷´Ê£ºFinale ×÷Çú/±àÇú/Ñݳª£ººÓͼ Actually: 2008作词:Finale 作曲/编曲/演唱: The setEncoder function doesn't seem to do anything.

joe-vettek commented 2 years ago

Ok, I found a simple way to solve it. Just check the encoder of the output, and then convert it into the encoder you want.

Log.d(TAG, "alertMp3Info: "+ SimpleTool.getEncoding(id3v22Tag.getAlbum())+id3v22Tag.getAlbum());
Log.d(TAG, "alertMp3Info: "+ new String(id3v22Tag.getAlbum().getBytes("ISO-8859-1"),"gbk"));

SimpleTool.getEncoding is a method to determine which encoding it is. It depends on what language you are.

refer: https://community.mp3tag.de/t/convert-charset-encoding/14360