javascript - 在 phoneGap 的背景中使用最小化的录制屏幕在 android 中捕获视频

标签 javascript cordova jquery-mobile video-capture

我尝试了以下代码。我想在后台录制视频并存储在 SD 卡中。我不想手动开始录制和停止。是否可以在 PhoneGap 中使用或不使用 API 录制视频。 我想在后台录制视频

<html>
<head>
<title>Capture Video</title>
<script type="text/javascript" charset="utf-8" src="js/cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="js/json2.js"></script>
<script type="text/javascript" charset="utf-8">
    // A button will call this function
    function captureVideo() {
        // Launch device video recording application, 
        // allowing user to capture up to 3 video clips
        alert("captureVideo");
        var options = {
            limit : 2,
            duration : 10
        };
        navigator.device.capture.captureVideo(captureSuccess, captureError,
                options);
    }
    // Called when capture operation is finished
    function captureSuccess(
    mediaFiles) {
        alert("captureSuccess   ");
        var i, len;
        alert(mediaFiles.length);
        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!');

    }
    // Upload files to server
    function uploadFile(mediaFile) {
        alert("uploadFile");
        var ft = new FileTransfer(), path = mediaFile.fullPath, name = mediaFile.name;
        alert("path:" + path);
        alert("name:" + 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="captureVideo();">Capture Video</button>
    <br>
</body>
</html>

最佳答案

document.addEventListener("deviceready", start_here, false);

function start_here(){captureVideo();}
每次启动应用程序并自动录制视频时都会调用该函数。
再次发送后开始录制...

    function uploadFile(mediaFile) {
           alert("uploadFile");
            var ft = new FileTransfer(), path = mediaFile.fullPath, name = mediaFile.name;
            alert("path:" + path);
            alert("name:" + 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
            });
start_here;   /*just call the instance. here is the change*/       
}

关于javascript - 在 phoneGap 的背景中使用最小化的录制屏幕在 android 中捕获视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22316986/

相关文章:

javascript - Onsen UI 2.0 如何改变 Material 颜色?

android - 在 visual studio 中使用 apache cordova 构建 android 应用程序时出错?

javascript - 为什么我的 jQuery Mobile 页脚会在用户单击背景时出现然后消失?

javascript - HTML 页面中添加背景音乐并循环播放

javascript - Sequelize 复杂和/或

javascript 代码不适用于 html 脚本

cordova - Phonegap 相机控制

android - 如何删除出现在 Android 设备表单中文本框内的默认文本?

jquery - MVC 4 移动模板重定向到操作在发布后失败

java - 如何使用 HTML5 数据属性获取 session 属性