开发者

Uploading a recorded audio file using phonegap (Android)

开发者 https://www.devze.com 2023-03-20 21:13 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消