在视频中使用视频标签时,如何将变量从页面传递到Brightcove HTML播放器?

时间:2018-11-13 04:22:48

标签: brightcove

这是页面:

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="utf-8">
  <title></title>
  <style media="screen">
    body {
background-color: #111;
color: #fff;
}
  </style>

</head>
<body> 

<script src="https://www.netapp.com/us/static/js/jquery-1.8.1.min.js"></script>
  <video-js id="myPlayerID"
    data-video-id="5448507890001"
      data-account="260701648001"
      data-player="FcmqUildl"
      data-embed="default"
      data-application-id
      class="video-js"
      controls
      width="640"
      height="360"></video-js>
  <script src="https://players.brightcove.net/260701648001/FcmqUildl_default/index.min.js"></script>
  <script type="text/javascript">
    $( window ).load(function() {
      videojs.getPlayer('myPlayerID').ready(function() {
        var cid = "12345";
         var myPlayer = this;
         iframeTag = document.querySelector("iframe").contentWindow;
         iframeTag.postMessage(cid, "*");
      });
    });
  </script>

</body>
</html>

我想将此页面中的变量传递给使用video标签添加的Brightcove Video。

我在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);
});

这将导致错误“无法读取null的属性'contentWindow'。我指的是这个示例https://support.brightcove.com/brightcove-player-sample-playpause-video-iframe-parent,该示例说明了如何将变量从页面传递到iframe。

在视频标签的帮助下添加视频时,如何传递变量?有什么想法?

0 个答案:

没有答案