简体   繁体   English

捕获音频Phonegap错误代码3

[英]Capture Audio Phonegap error code 3

I'm creating an app with audio recording, i tried to implement this example code: http://docs.phonegap.com/en/3.3.0/cordova_media_capture_capture.md.html#capture.captureAudio 我正在创建一个带录音的应用程序,我试图实现这个示例代码: http//docs.phonegap.com/en/3.3.0/cordova_media_capture_capture.md.html#capture.captureAudio

But when click on the button an error appears: Code error 3. According to documentation this errors appears when you exit the recording aplicacion before you record anything, but when i click on the button the recording app is not launched it goes directly to error function. 但是当单击按钮时会出现错误:代码错误3.根据文档,当您在录制任何内容之前退出录制aplicacion时会出现此错误,但是当我单击按钮时,录制应用程序未启动它会直接转到错误功能。

Capture video works fine. 捕获视频工作正常。

Using Phonegap 3.0.0 or 2.9.0 with Phonegap Build. 使用Phonegap 3.0.0或2.9.0与Phonegap Build。

Code: 码:

<!DOCTYPE html>
<html>
<head>
<title>Capture Audio</title>

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="json2.js"></script>
<script type="text/javascript" charset="utf-8">

// Called when capture operation is finished
//
function captureSuccess(mediaFiles) {
    var i, len;
    for (i = 0, len = mediaFiles.length; i < len; i += 1) {
        uploadFile(mediaFiles[i]);
    }
}

// Called if something bad happens.
//
function captureError(error) {
    var msg = 'An error occurred during capture: ' + error.code;
    navigator.notification.alert(msg, null, 'Uh oh!');
}

// A button will call this function
//
function captureAudio() {
    // Launch device audio recording application,
    // allowing user to capture up to 2 audio clips
    navigator.device.capture.captureAudio(captureSuccess, captureError, {limit: 2});
}

// Upload files to server
function uploadFile(mediaFile) {
    var ft = new FileTransfer(),
        path = mediaFile.fullPath,
        name = mediaFile.name;

    ft.upload(path,
        "http://my.domain.com/upload.php",
        function(result) {
            console.log('Upload success: ' + result.responseCode);
            console.log(result.bytesSent + ' bytes sent');
        },
        function(error) {
            console.log('Error uploading file ' + path + ': ' + error.code);
        },
        { fileName: name });
}

</script>
</head>
<body>
    <button onclick="captureAudio();">Capture Audio</button> <br>
</body>

This is not an exactly answer to your problem, but a working alternative. 这不是您问题的确切答案,而是一种可行的替代方案。

Instead of using org.apache.cordova.media-capture I tried org.apache.cordova.media . 我没有使用org.apache.cordova.media-capture,而是尝试了org.apache.cordova.media

Here is a small example: 这是一个小例子:

function recordAudio() {
    var src = "myrecording.amr";
    var mediaRec = new Media(src,
        // success callback
        function() {
            console.log("recordAudio():Audio Success");
        },

        // error callback
        function(err) {
            console.log("recordAudio():Audio Error: "+ err.code);
        });

    // Record audio
    mediaRec.startRecord();

    // Stop recording after 10 seconds
    setTimeout(function() {
        mediaRec.stopRecord();
    }, 10000);
}

Unfortunaly each device uses their own audio codec and in case of Android it is the AMR Codec. 不幸的是,每个设备都使用自己的音频编解码器,而在Android的情况下,它是AMR编解码器。 I was able to listen to the record using MPC (Windows) . 我能够使用MPC(Windows)收听记录。 But if you want to upload the file and share it with other users, you'll have to convert it . 但是,如果您要上传文件并与其他用户共享,则必须进行转换

If you do not find the myrecording.amr file: It is located on devices' root. 如果找不到myrecording.amr文件:它位于设备的根目录下。 I did not figure out how to store files temporary in the application cache folder itself, which is existing. 我没有弄清楚如何在应用程序缓存文件夹本身临时存储文件,这是现有的。

A 10 second recording has < 20kb size. 10秒的录音大小<20kb。

AMR 8000Hz mono 12kbps [Audio]

Which is very bad quality. 这是非常糟糕的质量。 Unfortunaly there seems to be no possibility to increase the quality. 不幸的是,似乎没有可能提高质量。

The problem may be that there's no application that is handling the RECORD_SOUND intent. 问题可能是没有应用程序正在处理RECORD_SOUND意图。

I used this one: 我用过这个:

https://play.google.com/store/apps/details?id=com.brightattic.soundrecorder&hl=en https://play.google.com/store/apps/details?id=com.brightattic.soundrecorder&hl=en

(I have no endorsement for it other than it worked in my test) (除了在我的测试中工作之外,我没有认可它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM