Flash AS解决中文mp3乱码
Flash AS解决中文mp3乱码
发布时间:2016-12-21 来源:查字典编辑
摘要:Flash如果MP3的ID3标签使用GB2312编码,那么在Flash脚本输出时是乱码的代码1vars:Sound=newSound(thi...

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));

输出结果:

丁香花

涓侀鑺

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Flash教程学习
热门Flash教程学习
网页设计子分类