在我的项目中使用flash cs6,as3我成功使用waveEncoder类从麦克风编码bytearray并将其上传到服务器端 它可以在服务器上运行,但是当我下载它并尝试在闪存中播放时,它无法播放 当我尝试在flash中播放时,我需要帮助编码mp3文件 这是我的代码
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);
}
感谢的
答案 0 :(得分:5)
**My Solution:**
从此链接https://github.com/kikko/Shine-MP3-Encoder-on-AS3-Alchemy下载shinemp3Encoder 然后以下代码完美地工作:)
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
}
thaaank全部
答案 1 :(得分:0)
waveEncoder用于wav文件,而不是mp3-s。 Mp3-s需要硬件加速,否则它们非常重。但是,有一些图书馆,就像在这个视频中http://gotoandlearn.com/play.php?id=169一样,有什么可以帮到你。
答案 2 :(得分:0)
如果该文件实际上是有效的声音,那应该不是问题。使用this manual加载来自网址的声音。