在iOS中正确编码ID3标签 [英] Correct encoding for ID3 Tags in iOS
本文介绍了在iOS中正确编码ID3标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从项目中的一堆mp3文件中获取ID3标签。
I'm trying to get ID3 tags from a bunch of mp3 files in my project.
AudioFileGetProperty(audioFile, kAudioFilePropertyInfoDictionary, &size, &metadataDictionary);
如果标签不包含西里尔字符,输出在设备上看起来就OK。但是我有时会得到像这样的价值:
If the tag doesn't contain cyrillic symbols, the output looks OK on the device. However I sometimes get values like this one:
album = "\U00ce\U00f2\U00ea\U00f0\U00fb\U00f2\U00ee\U00e5 \U00d0\U00e0\U00e4\U00e8\U00ee 102.5FM";
"approximate duration in seconds" = "260.623";
,并导致扭曲的符号显示( http://d.pr/i/X9wG )。
and it leads to distorted symbols display (http://d.pr/i/X9wG).
有没有办法解码这些符号变成可读形式?我已经尝试过
Is there any way to decode these symbols into a readable form? I've already tried
NSString* value = [metadataDictionary objectForKey: key];
NSData* data = [value dataUsingEncoding: NSASCIIStringEncoding];
NSString* string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
但结果保持不变。
任何帮助将不胜感激!
[更新]
尝试在此SO答案中提供的解决方案,但还有其他方法?
I tend to try a solution provided in this SO answer, but are there any other ways?
推荐答案
将这些符号解码成可读形式:
That's way to decode these symbols into a readable form:
NSString *value = [metadataDictionary objectForKey:@"artist"];
const char *cString = [value cStringUsingEncoding:NSWindowsCP1252StringEncoding];
NSString *artist = [NSString stringWithCString:cString encoding:NSWindowsCP1251StringEncoding];
这篇关于在iOS中正确编码ID3标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文