AS3 載入MP3 ID3 亂碼解決辦法

來源:互聯網
上載者:User

AS3 載入MP3 ID3 亂碼解決辦法2009-04-20 19:09大部份MP3 的ID3用的字元編碼都是 GBK/GB2312 的。在AS2 中,擷取ID3時使用 usedCodePage 便可解決問題,但在AS3中 即使使用了 usedCodePage,Sound 在載入mp3讀取ID3資訊使,仍使用的是 UTF8 的編碼,這使得大量MP3 讀出的ID3是亂碼,無法正常顯是,這是很不爽的事。通過以下代碼,可以使得被誤以為是UTF8編碼的ID3資訊從亂碼變成可讀.

/*
    *id3資訊編碼轉換
    */
   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");
   }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.