这是我页面上的示例代码
<!DOCTYPE html>
<html lang="en" dir="ltr">
<script src="https://www.netapp.com/us/static/js/jquery-1.8.1.min.js"></script>
<body>
<p>
<button class="bcls-button" onclick="playVideo()">Play Video</button>
<button class="bcls-button" onclick="pauseVideo()">Pause Video</button>
</p>
<div class="n-container">
<div class="n-row">
<div class="n-col-md-12">
<h2>Advanced (non-iFrame):</strong></h2>
<iframe src="//players.brightcove.net/260701648001/FcmqUildl_default/index.html?videoId=5448507890001" allowfullscreen="" webkitallowfullscreen="" mozallowfullscreen="" style="width: 640px; height: 360px;"></iframe>
</div></div></div>
<script>
var cid = "12345";
var theProtocol = location.protocol,
theURL = theProtocol + "//players.brightcove.net",
// Get a reference to the iframe element
iframeTag = document.querySelector("iframe"),
// Retrieve window object needed for postMessage
win = iframeTag.contentWindow;
console.log('theURL:', theURL);
console.log('win:', win);
function playVideo() {
// Post message passing 'playVideo' as the data
win.postMessage(cid, theURL);
}
function pauseVideo() {
// Post message passing 'pauseVideo' as the data
win.postMessage("pauseVideo", theURL);
}
</script>
</body>
</html>
根据此引用https://support.brightcove.com/brightcove-player-sample-playpause-video-iframe-parent
,插件代码已添加到Brightcove播放器中。videojs.registerPlugin('listenForParent', function() {
var myPlayer = this;
// This method called when postMessage sends data into the iframe
function controlVideo(evt){
console.log("evt.data" + evt.data)
};
// Listen for the message, then call controlVideo() method when received
window.addEventListener("message",controlVideo);
});
当我单击PlayVideo时,此功能正常。我需要在负载下进行这项工作。如果我准备好在文档上调用函数PlayVideo,则会显示错误消息,提示无法在“ DOMWindow”上执行“ postMessage”:提供的目标原点('http://players.brightcove.net')与收件人窗口的原点('{{3} }')。
有什么主意吗?