使用cordova在iOS中创建和捕获视频

时间:2017-04-20 11:33:54

标签: jquery ios cordova video-capture

我想拍摄视频。之后,我想点击按钮后播放视频。我正在使用cordova购买iOS和Android应用程序。 我正在使用cordova-plugin-media-capturecordova-plugin-streaming-media插件。

对视频进行资源补充。但如果我点击“播放视频”按钮,我在控制台中收到错误:

  

ReferenceError:找不到变量:playVideo

什么错了?这是我的功能:

//cordova media caputre plugin
document.addEventListener("deviceready", init, false);
function init() {

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

}

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

// capture callback
var captureSuccess = function(mediaFiles) {
    var i, path, len;
    for (i = 0, len = mediaFiles.length; i < len; i += 1) {
        path = mediaFiles[i].fullPath;
        console.log(mediaFiles[i].fullPath);

          function playVideo(videoUrl) {
              // Play a video with callbacks
              var options = {
                mustWatch: true,
                successCallback: function() {
                  console.log("Video was closed without error.");
                },
                errorCallback: function(errMsg) {
                  console.log("Error! " + errMsg);
                }
              };
              window.plugins.streamingMedia.playVideo(path, options);

          }

    }
};

我的按钮(HTML)

<button id="takeVideo">Take Video</button>

<input type="url" size="60" value="" id="vidUrl"/><br/>
<button type="button" onclick="playVideo(document.getElementById('vidUrl').value);">Play Video</button>

1 个答案:

答案 0 :(得分:0)

修改

以下是我尝试调整代码的方法:

的JavaScript;

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

function init() {

    document.getElementById("takeVideo").addEventListener("touchend", function() {

        console.log("Take video");

        navigator.device.capture.captureVideo(captureSuccess, captureError, {
            limit: 1
        });

    }, false);

    document.getElementById("playButton").addEventListener("touchend", function() {

        playVideo(document.getElementById('vidUrl').innerHTML);

    });

}

function captureError(e) {

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


function captureSucess(mediaFile) {

    //No need for a loop as we have limited the user to take 1 video
    var path = mediaFile.fullPath;
    var vidUrlElement = document.getElementById('vidUrl');
    vidUrlElement.innerHTML = path;


}

function playVideo(videoUrl) {
    // Play a video with callbacks
    var options = {
        mustWatch: true,
        successCallback: function() {
            console.log("Video was closed without error.");
        },
        errorCallback: function(errMsg) {
            console.log("Error! " + errMsg);
        }
    };
    window.plugins.streamingMedia.playVideo(videoUrl, options);

}

HTML;

<button id="takeVideo">Take Video</button>
<br/>
<div id="vidUrl"></div>
<br/>
<button id="playButton">Play Video</button>

<强>原始

您是否尝试过在for循环之外移动playVideo()函数?