浅谈AS中文mp3乱码

    文章来源:万象互联 更新时间:2012-11-23 18:44:55
分享:
Flash如果MP3的ID3标签使用GB2312编码,那么在Flash脚本输出时是乱码的
代码1
var s:Sound=new Sound(this);
s.loadSound("dxh.mp3",false);
s.onID3=function(){
trace(this.id3.songname);
}
输出结果是:
?&IExcl;???
dxh.mp3的ID3v1的标签正确应该是songname="丁香花",看来FLASH在转码上出现了问题。我们来看看songname这个字符串中倒底是什么?
代码2:
var s:Sound=new Sound(this);
s.loadSound("dxh.mp3",false);
s.onID3=function(){
var songname:String=this.id3.songname;
for(var i=0;i<songname.length;i ){
trace(songname.charCodeAt(i));
}
}
输出结果是:
182
161
207
227
187
168
我们使用计算器转换成16进制就是"B6 A1 CF E3 BB A8";
正好是"丁香花"的GB2312编码,我们还是用FLASH来试试

System.useCodepage=true;
trace(unescape("丁香花"));
输出结果是:
丁香花
那么为什么代码1出现乱码现象,是因为FLASH将GB2312当作了UTF-8来解释,我们再来测试一下:
代码3:

var s:Sound=new Sound(this);
s.loadSound("dxh.mp3",false);
s.onID3=function(){
var songname:String=this.id3.songname;
trace(escape(songname));
}
结果是:
?????¨
问题的原因我们找到了,只要将GB2312转换成UTF-8编码就能显示正常了,可是如果转换呢,大家注意看代码2,我再测试一下想法
代码4:

System.useCodepage=true;
var gb:String=unescape("丁香花");
System.useCodepage=false;
trace(gb);
trace(escape(gb));
输出结果:
丁香花
    文章来源:http://www.hulian.top,转载请注明!
版权说明:本站原创文章,由万象互联SEO优化发表.
本文地址:https://www.hulian.top/zixun/post/5440.html
在线咨询
  • 在线时间
  • 8:00-21:00