【问题标题】:Video capture in android in background in phoneGap with minimized recording screen在phoneGap的后台Android中的视频捕获,最小化的录制屏幕
【发布时间】:2014-03-11 05:12:52
【问题描述】:

我尝试了以下代码。我想在后台录制视频并存储在 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("pause", captureVideo, false); 在后台执行任务,但视频不会自动捕获,您需要手动启动。
  • 我认为操作系统甚至不会让您这样做,除非出于安全考虑您具有 root 访问权限/权限。您需要的是在用户不知情的情况下录制、捕获和上传视频的能力。
  • 你是否演示了如何使用这个文档在后台录制视频。addEventListener("pause", captureVideo, false);

标签: javascript cordova jquery-mobile video-capture


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    现在您可以使用最小化的应用程序录制视频,甚至可以在 cordova\phonegap\ionic plugin 关闭屏幕时录制视频

    这是一个 fork,但主 repo 不能“在后台”录制视频(尽管有名字)。

    当它启动时,它会根据 SD 和内部磁盘上的可用空间大小自动选择存储视频的位置。

    cordova plugin add cordova-backgroundvideo
    
    var fileName = new Date().getTime() + '';
    cordova.plugins.backgroundvideo.start(fileName, 'back', true, null, null);
    
    cordova.plugins.backgroundvideo.stop(function (filePath) {
        alert(filePath);
      }, function (error) {
        alert('Error ' + JSON.stringify(error));
      }
    );
    

    【讨论】:

      猜你喜欢
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多