Uploading a recorded audio file using phonegap (Android)
Hello There, I am new to phonegap.I am trying to record a audio clip and uploading it to server.I am working with phonegap +jquery mobile + Android.Can anyone tell me a good way which can work for me with a small example.Basically I have a form which have a button as Record, from which user can record an audio clip and can publish it.So basically I need to upload that recorded file on server on submitting the form.I tried phonegap API's Media and File for recording and uploading file but couldn't succeed.
I am using following function for recording :
function recordAudio() {
var src = "myrecording.mp3";
var mediaRec = new Media(src, onSu开发者_JS百科ccess, onError);
// Record audio
mediaRec.startRecord();
// Stop recording after 10 sec
var recTime = 0;
var recInterval = setInterval(function() {
recTime = recTime + 1;
setAudioPosition(recTime + " sec");
if (recTime >= 10) {
clearInterval(recInterval);
mediaRec.stopRecord();
}
}, 1000);
}
Now I need to upload this recorded file to server.I am testing on emulator.
Kind Regrads Jaya
the default location of recorded audio for android is "mnt/sdcard/myrecording.wav"
to upload, use the FileTransfer
object to upload the audio
var ft = new FileTransfer();
ft.upload("mnt/sdcard/myrecording.wav", "http://www.website.com/upload.php", win, fail);
Why don't you try the captureAudio function directly?
function captureAudio() {
// Launch device audio recorder
navigator.device.capture.captureAudio(captureSuccess, captureError);
}
Check here: PhoneGap Doc
Under captureSuccess callback, you could use the FileTransfer object to upload your file.
精彩评论