以下是完成的工作
获取WAV文件=>确定
private function renderWav(src, convertToMp3 = false) {
WaveFile.writeBytesToWavFile(myWavFile, myWavData, 44100, 2, 16)
}
转换为MP3 =>确定
private function makeIntoMp3(wav) {
mp3Encoder = new ShineMP3Encoder(wav);
mp3Encoder.start();
}
将MP3文件保存到Client =>确定
private function onWavClick(e:MouseEvent) {
new FileReference().save(mp3Encoder.mp3Data, "MyAudio.mp3");
}
上面,我可以在客户端获取一个MP3文件但是我的问题是保存到服务器端(PHP)
保存到服务器端=>失败
public function makeMP3File() {
var urlVariables:URLVariables = new URLVariables;
urlVariables.mp3Data = mp3Encoder.mp3Data;
var req:URLRequest = new URLRequest('upload.php');
req.data = urlVariables;
req.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.load(req);
}
我的PHP代码
function strean2audio($audioStream, $filename)
{
$file = fopen($filename . '.mp3', "wb");
fwrite($file, $audioStream);
fclose($file);
}
我是一名ActionScript新手,不知道哪部分错误, 感谢您的帮助!
答案 0 :(得分:0)
我找到解决问题的方法(供你参考)
// FLASH将MP3文件发送到服务器
public function makeMP3File() {
var sba:ByteArray = mp3Encoder.mp3Data; **//to ByteArray**
var req:URLRequest = new URLRequest('upload.php');
req.contentType = 'application/octet-stream';
req.method = URLRequestMethod.POST;
req.data = sba;
var loader:URLLoader = new URLLoader(req);
}
// PHP服务器端
function strean2audio($name, $spec, $userId=0) {
$audio_content = file_get_contents("php://input"); **//get RAW POST**
$file = fopen($audio_file_name . '.mp3', "wb");
fwrite($file, $audio_content);
fclose($file);
}
<强>结论强>
recorder.MP3 - &gt; ByteArray - &gt; URLRequest - &gt; URLLoader - &gt; PHP - &gt; ByteArray - &gt; MP3 强>