Flash读取MP3的标题ID3,出现乱码的解决方法
时间:2011-3-14 作者:天空下的雨 分类: 学习教程 浏览:7794
今天刚好遇到这样的问题,用了知名的Dewplayer网页音乐播放器后,读取MP3的ID3时中文会出现乱码,经过网上找相关资料,整理测试最简单的方法:
用AS2彻底解决ID3的乱码问题,一般大陆MP3的编码为GB2312,所以需要通过Flash转码来实现,代码如下:
function ANSI2UTF(ANSI_string) {
var temp = !(!System.useCodepage);
System.useCodepage = true;
var code = "";
for (var i = 0; i<ANSI_string.length; i++) {
code += "%"+ANSI_string.charCodeAt(i).toString(16);
}
var result = unescape(code);
System.useCodepage = temp;
return result;
}
使用示例 代码:
my_sound = new Sound();
my_sound.onID3 = function() {
var songName = ANSI2UTF(this.id3.songname);
trace("result: "+songName);
};
my_sound.loadSound("music.mp3", false);
天空下的雨:只能转换ID3,对于更加广泛的txt等外部文本,或者繁体中文上,转换方法仍然存在问题。
Continue