关键:读取开头2个字节,utf-8前3个字节是ef bb bf ,unicode前2个字节是fffe或者feff,ansi则没有这些标志!
搞了一天,终于可以识别各种格式的LRC歌词了。放出部分代码
var strCode:int= this.stream.readByte();
var str:String = new String();
trace(strCode);
switch(strCode)
{
case -1:
//第一个字符为-1则是unicode
this.charset="unicode";
this.stream.readByte();
str = this.stream.readMultiByte(this.stream.bytesAvailable,this.charset);
break;
case -17:
//第一个字符为-17则是utf-8
this.charset="utf-8";
this.stream.readByte();
this.stream.readByte();
str = this.stream.readMultiByte(this.stream.bytesAvailable,this.charset);
break;
default:
this.charset="ansi";
str = String.fromCharCode(strCode);
str += this.stream.readMultiByte(this.stream.bytesAvailable,this.charset);
}
trace(str);
搞了一天,终于可以识别各种格式的LRC歌词了。放出部分代码
var strCode:int= this.stream.readByte();
var str:String = new String();
trace(strCode);
switch(strCode)
{
case -1:
//第一个字符为-1则是unicode
this.charset="unicode";
this.stream.readByte();
str = this.stream.readMultiByte(this.stream.bytesAvailable,this.charset);
break;
case -17:
//第一个字符为-17则是utf-8
this.charset="utf-8";
this.stream.readByte();
this.stream.readByte();
str = this.stream.readMultiByte(this.stream.bytesAvailable,this.charset);
break;
default:
this.charset="ansi";
str = String.fromCharCode(strCode);
str += this.stream.readMultiByte(this.stream.bytesAvailable,this.charset);
}
trace(str);