使用phonegap预览后,如何将视频上传到服务器

时间:2016-09-24 14:22:35

标签: javascript android jquery cordova

请联系我们,了解如何上传使用phonegap android app捕获的视频。我可以上传捕获的视频,但我希望应用的用户在上传之前观看捕获的视频。这就是我遇到问题的地方。

我正在使用的代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="css/jquery.mobile-1.2.0.min.css" />
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/jquery.mobile-1.2.0.min.js"></script>
    <script src="js/modernizr-latest.js"></script>
    <script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", init, false);
function init() {


document.querySelector("#takeVideo").addEventListener("touchend",   function() {
    alert("Take video");
    navigator.device.capture.captureVideo(captureSuccess,  captureError, {limit: 1, duration: 10});
}, false);

}

function captureError(e) {
console.log("capture error: "+JSON.stringify(e));
}

function captureSuccess(s) {
console.log("Success");
console.dir(s[0]);
var v = "<video controls='controls'>";
v += "<source src='" + s[0].fullPath + "' type='video/mp4'>";
v += "</video>";
document.querySelector("#videoArea").innerHTML = v;
}

function uploadFile(s) {

// Get URI of picture to upload
var img = document.getElementById('videoArea');
var mediaFile = img;
alert(mediaFile);
if (!mediaFile || (img.style.display == "none")) {

    alert("Take picture or select picture from library first.");
        return;
    }

    var ft = new FileTransfer(),
    path = mediaFile.substr(mediaFile.lastIndexOf('/')+1),
    name = mediaFile.name;
    var options = new FileUploadOptions();
    options.mimeType = "document";
    options.fileName = name;
    options.chunkedMode = true;
        options.params = params;

    ft.upload(path,
        "http://www.example.com/folder/upload.php",
        function(result) {
            alert('Upload success: ' + result.responseCode);
            alert(result.bytesSent + ' bytes sent');
        },
        function(error) {
            alert('Error uploading file ' + path + ': ' + error.code);
        },
        options);
}
</script>
</head>
<body>
    <button id="takeVideo">Take Video</button><br>
    <b>Status:</b> <span id="camera_status"></span><br>
    <div id="videoArea"></div>

    <button type="submit" onclick="uploadFile();">Submit</button>

</body>
</html>

请指望您帮助解决这一挑战。我不知道如何引用“视频”标记名,也不知道从div的videoArea id中提取图像路径。

0 个答案:

没有答案