【问题标题】:Creating and capturing video in iOS with cordova使用 cordova 在 iOS 中创建和捕获视频
【发布时间】:2017-09-17 00:31:08
【问题描述】:

我想拍摄视频。之后,我想在单击按钮后播放视频。我正在使用 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>

【问题讨论】:

  • 您是否尝试过更改您自己的函数 playVideo 的名称?好像你有一个命名冲突。也许这只是因为如果是这样,但是你在函数内部声明一个函数,然后从你的 html 调用它,这是不可能的......

标签: jquery ios cordova video-capture


【解决方案1】:

编辑

这是我调整您的代码以使其正常工作的尝试:

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>

原创

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

【讨论】:

    猜你喜欢
    • 2015-10-02
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-28
    相关资源
    最近更新 更多