I need help in exporting a bytearray to a wav or mp3 (or anything that runs!) from my flash code to my php page.
I am using microphone recorder to record voice, i use a a url request to send my ByteArray to my PHP page.
i send the bye array from flash like this:
var url = "http://localhost/wordswesay/uploads/testrec.php"; var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream"); var request:URLRequest = new URLRequest(url);
request.requestHeaders.push (header);
request.method = URLRequestMethod.POST;
request.data = soundBytes; //FLV byteArray
var loader:URLLoader = new URLLoader();
trace(request.data);
loader.load(request)
and in my php file, i do the following:
<?php
echo "test";
$im = $GLOBALS["HTTP_RAW_POST_DATA"];
$fp = fopen("test.wav", 'w');
fwrite($fp, $im);
fclose($fp);
?>
a开发者_JAVA技巧t the server side (the sime file as the php script) i get the test.wav with about 200kb of size but i can not play it! media players says it can't play this file as the codec might not be supported.
Any help would be appreciated
There is more to a audio file than the audio bytes, there needs to be a format specific header, and the bytes need to be stored in a way specific to the format type, which is often (mp3s for example) different then the raw bytes Flash will be giving you (which are decoded already)
Take a look on Google for a audio encoder, either in AS3 or PHP that will convert your bytes to a mp3 file, I'm sure there is something, but I don't know one off hand. Hopefully that explains why its not working, and pushes you into the right direction. Goodluck!
精彩评论