对于Android音乐播放器的音乐人 ,专辑,音乐名字显示乱码的修改做了下总结:
方法一:在frameworks\base\media\java\android\media\MediaScanner.java中修改:函数handleStringTag
在这个函数中加上字符编码的转换;
<span style="font-family:KaiTi_GB2312;font-size:18px;">/*add by tanfusheng @20150110 start */ private boolean isEncoding(String value,String code) throws UnsupportedEncodingException{ return value.equals(new String(value.getBytes(code),code)); } /*add by tanfusheng @20150110 end */ public void handleStringTag(String name, String value) { /*add by tanfusheng @20150110 start */ try{ if(isEncoding(value,"ISO-8859-1")){ value = new String(value.getBytes("ISO-8859-1"),"GBK"); } }catch(UnsupportedEncodingException e){ e.printStackTrace(); } /*add by tanfusheng @20150110 end */</span>
方法二:在frameworks\av\media\libmedia\MediaScannerClient.cpp中修改:
<span style="font-family:KaiTi_GB2312;font-size:18px;">void MediaScannerClient::endFile() { if (mLocaleEncoding != kEncodingNone) { int size = mNames->size(); + int count = 0; uint32_t encoding = kEncodingAll; uint32_t tmpEncoding = kEncodingAll; uint32_t srcEncoding = kEncodingNone; for (int i = 0; i < mNames->size(); i++) { tmpEncoding = possibleEncodings(mValues->getEntry(i)); // If no multibyte encoding is detected or GBK is the only possible multibyte encoding, just ignore - if( (kEncodingNone != tmpEncoding) && (kEncodingCP1252 != tmpEncoding) - && ((kEncodingGBK | kEncodingCP1252) != tmpEncoding) ) { - encoding &= tmpEncoding; + if( (kEncodingNone == tmpEncoding) || ((kEncodingGBK | kEncodingCP1252) == tmpEncoding) ) { + continue; } + + if( kEncodingCP1252 == tmpEncoding ) { + ++count; + continue; + } + + encoding &= tmpEncoding; LOGV("value: %s, tmpEncoding: %x\n", mValues->getEntry(i), tmpEncoding); } + + if(count >= 2) { + encoding = kEncodingAll; + } LOGV("possibleEncodings: %x\n", encoding); ... }</span>其中+号代表要添加的代码,-号代表要删除的代码。
希望遇到此乱码的问题可以用得上,如果这样改了还会乱码,那就是单首音乐的问题了,就得用千千静听去修改那首音乐的编码方式了,至于方法可以百度到的。
原文地址:http://blog.csdn.net/tfslovexizi/article/details/42583955