android音乐文件乱码显示问题解决

时间:2021-12-03 13:23:35

在android中利用音乐播放器播放音乐时,有时会发现歌曲名称,歌手名称,专辑名称等会有乱码,其实这是在音乐文件扫描的过程中解码不正确造成的,采用下面的代码应该可以修正大部分类似的问题:

in MediaScannerClient.cpp

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);
...
}
其中+号代表要添加的代码,-号代表要删除的代码。