【发布时间】:2015-08-06 12:21:16
【问题描述】:
我正在 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。
【问题讨论】:
-
发生了什么错误?也请在此处发布您的内容,如果您懒得在此处添加代码,我怀疑人们会帮助您。
-
请在您的问题中添加重现此问题所需的最短代码量。您不应该让人们从一堆地方复制粘贴代码,以贡献他们的空闲时间来帮助您。
-
为什么你的点击事件会调用
deviceready事件处理器? -
'因为我在 cordova 的捕获插件文档中读到,如果没有 deviceReady 事件,您将无法调用您的捕获。但也许我做得那么糟糕。关于错误,我没有发生任何错误,只是,没有发生。我只是向我的按钮发送垃圾邮件,但应用程序只是......什么都不做。
标签: javascript android cordova