1

In my project using flash cs6 ,as3 I success to encode bytearray from microphone using waveEncoder class and upload it on the server side It works in the server but when I download it and try to play it inside the flash ,it doesn’t play I need help to encode mp3 file that's work when I try to play it inside flash here is my code

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);

}

Thank’s

Enas S3efan
  • 81
  • 1
  • 11

3 Answers3

5
**My Solution:**

download shinemp3Encoder from this link https://github.com/kikko/Shine-MP3-Encoder-on-AS3-Alchemy then the following code work perfectly :)

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's all

Enas S3efan
  • 81
  • 1
  • 11
0

waveEncoder is for wav files, not mp3-s. Mp3-s require hardware acceleration, or else they are very heavy. however, there are libs, like in this video http://gotoandlearn.com/play.php?id=169, what can make it for you.

csomakk
  • 5,369
  • 1
  • 29
  • 34
0

It shouldn't be a problem if that file is actually a valid sound. Use this manual to load sounds from URLs.

Vesper
  • 18,599
  • 6
  • 39
  • 61
  • I use the following way to play it , the normal mp3 works fine but when I use it for the file which I create doesn’t work var mp3fi:File mp3fi = File.documentsDirectory var mp3out= mp3fi.resolvePath(nam+".mp3").nativePath var url:URLRequest=new URLRequest(mp3out) sourceSnd.load(url); sourceSnd.play – Enas S3efan May 30 '13 at 09:15
  • No, since you have uploaded that MP3 elsewhere, you have to load that sound from server. Or do you have difficulties playing the sound that you've just recorded? – Vesper May 30 '13 at 09:45
  • var req:URLRequest = new URLRequest("http:/path/test4.mp3"); var s:Sound = new Sound(req); s.play() also not work – Enas S3efan May 30 '13 at 10:41
  • `var req:URLRequest = new URLRequest("http:/myserver.php/path/test4.mp3"); var s:Sound = new Sound(req); s.play() ` Will this work? – Vesper May 30 '13 at 11:35
  • no,, but finally I got the solution using shine mp3 encoder, I will Post it here very soon – Enas S3efan May 30 '13 at 11:39