【发布时间】:2017-09-17 00:31:08
【问题描述】:
我想拍摄视频。之后,我想在单击按钮后播放视频。我正在使用 cordova 开发 iOS 和 Android 应用程序。
我正在使用 cordova-plugin-media-capture 和 cordova-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