我的cordova应用程序不想运行,我不知道为什么

时间:2015-08-06 12:21:17

标签: javascript android cordova

我正在科尔多瓦开发一个应用程序。此应用程序应该能够在您按下捕获按钮时捕获视频,然后将其上载到特定服务器上。

但是我遇到了捕获API的问题。当我在模拟器或物理设备上运行它时,没有任何反应,并且在纹波上,会返回错误。

我的HTML代码在这里

      <div class="button">
                <div class="button1">
                    <button id="captureVideo" class="btn btn-lg btn-primary">launch a capture</button>
                </div>
            </div>

我的js

document.addEventListener("DOMContentLoaded", function () {
        document.getElementById("captureVideo").addEventListener("click", function () {
            document.addEventListener("deviceready", onDeviceReady, false);
    });
})


function onDeviceReady() {
    console.log(navigator.device.capture);
    navigator.device.capture.captureVideo(captureSuccess, captureError, { limit: 1 });
    console.log("Record launched !");
}



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

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

// 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 });
}*/

非常感谢您的回答:)

根据要求,我将代码直接放在这里而不是pastebin。

1 个答案:

答案 0 :(得分:0)

终于找到了!这是因为我的插件没有加载到应用程序中。