1

在我使用 flash cs6、as3 的项目中,我成功地使用 waveEncoder 类从麦克风编码字节数组并将其上传到服务器端需要帮助来编码 mp3 文件,当我尝试在 flash 中播放它时,这是我的代码

import org.bytearray.micrecorder.encoder.WaveEncoder;
var enco:WaveEncoder=new WaveEncoder();
function upload_s(user_name:String,user_id:String)
{
var SERVICE_PATH:String = "http://myserver.php";
    var o:ByteArray=enco.encode(soundO3,1)

var soundFileName=user_name+user_id+".mp3"
var loaderjp:URLLoader = new URLLoader();

var url:String = SERVICE_PATH + "?name=" + soundFileName;

var req:URLRequest = new URLRequest(url);

// make sure the server knows it is getting an image
req.requestHeaders =  new Array(new URLRequestHeader("Content-Type", "audio/mp3"));

loaderjp.dataFormat = URLLoaderDataFormat.BINARY;

req.contentType ="audio/mp3";

req.method = URLRequestMethod.POST;

req.data = o;

// send the file            
loaderjp.load(req);

}

谢谢

4

3 回答 3

5
**My Solution:**

从此链接下载shinemp3Encoder https://github.com/kikko/Shine-MP3-Encoder-on-AS3-Alchemy 然后以下代码完美运行:)

import org.bytearray.micrecorder.encoder.WaveEncoder;
import fr.kikko.lab.ShineMP3Encoder;
var enco:WaveEncoder=new WaveEncoder();

    var loaderjp:URLLoader = new URLLoader();

    var req:URLRequest
    function upload_s(user_name:String,user_id:String)
    {
    var SERVICE_PATH:String = "http://server/saveme.php";
        var o:ByteArray=enco.encode(soundO3,1) // soundO3 is Byte Array created from mic
        var mp3Encoder

    var imageFileName=user_name+user_id+".mp3"

    var url:String = SERVICE_PATH + "?name=" + imageFileName;

    req = new URLRequest(url);

    // make sure the server knows it is getting an image
    req.requestHeaders =  new Array(new URLRequestHeader("Content-Type", "audio/mp3"));

    loaderjp.dataFormat = URLLoaderDataFormat.BINARY;

    req.contentType ="audio/mp3";

    req.method = URLRequestMethod.POST;
    encodeToMP3(o)

     function encodeToMP3(wavData:ByteArray):void {

            mp3Encoder = new ShineMP3Encoder(wavData);
            trace("jjjjjjjjjjjkk "+mp3Encoder)
            mp3Encoder.addEventListener(Event.COMPLETE, mp3EncodeComplete);
            mp3Encoder.addEventListener(ProgressEvent.PROGRESS, mp3EncodeProgress);
            mp3Encoder.addEventListener(ErrorEvent.ERROR, mp3EncodeError);
            mp3Encoder.start();
    }

     function mp3EncodeProgress2(event : ProgressEvent) : void {

            trace( event.bytesLoaded, event.bytesTotal);
    }
     function mp3EncodeError(event : ErrorEvent) : void {

            trace("Error : ", event.text);
    }
    var arr:ByteArray=new ByteArray()

     function mp3EncodeComplete(event : Event) : void {

            trace("Done !", mp3Encoder.mp3Data.length);

    //      trace(mp3Encoder.mp3Data)

     req.data = mp3Encoder.mp3Data
    loaderjp.load(req);
    }

    // send the file            

    }

一切都好

于 2013-06-02T06:06:35.487 回答
0

waveEncoder 用于 wav 文件,而不是 mp3-s。Mp3-s 需要硬件加速,否则它们会很重。但是,有一些库,就像这个视频http://gotoandlearn.com/play.php?id=169一样,有什么可以为你做的。

于 2013-05-30T08:52:24.027 回答
0

如果该文件实际上是有效的声音,那应该不是问题。使用本手册从 URL 加载声音。

于 2013-05-30T08:54:49.910 回答