As3 loading MP3 ID3 garbled solution most MP3 ID3 uses GBK/gb2312 character encoding. In As2, usedcodepage can be used to solve the problem, but in as3, even if usedcodepage is used, sound still uses utf8 encoding to read ID3 information when loading MP3 files, this makes the ID3 read by a large number of MP3 players garbled and cannot be displayed normally. This is a very unpleasant thing. The following code can be used to convert the ID3 information that is incorrectly encoded by UTF-8 from garbled code to readable code.
/*
* ID3 Information encoding and conversion
*/
Private function encodeutf8 (STR: string): String {
VaR oribytearr: bytearray = new bytearray ();
Oribytearr. writeutfbytes (STR );
VaR tempbytearr: bytearray = new bytearray ();
// Trace (STR );
For (VAR I = 0; I <oribytearr. length; I ++ ){
If (oribytearr [I] = 194 ){
Tempbytearr. writebyte (oribytearr [I + 1]);
I ++;
} Else if (oribytearr [I] = 195 ){
Tempbytearr. writebyte (oribytearr [I + 1] + 64 );
I ++;
} Else {
Tempbytearr. writebyte (oribytearr [I]);
}
}
Tempbytearr. Position = 0;
Return tempbytearr. readmultibyte (tempbytearr. bytesavailable, "Chinese ");
}