How to pass variable from a parent window to Brightcove player HTML?










0














This is the example code that I have on my page



<!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>


The plugin code is added in the Brightcove player as per this reference https://support.brightcove.com/brightcove-player-sample-playpause-video-iframe-parent



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);
);


This works fine when i click on the PlayVideo. I need to make this work on load. If i call the function PlayVideo on document ready it gives error saying Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://players.brightcove.net') does not match the recipient window's origin ('http://localhost').



Any idea?










share|improve this question

















  • 1




    You’ll presumably have to wait until the plugin initialization is done, or at least until the iframe content is done loading.
    – misorude
    Nov 12 at 11:22










  • Thanks. it worked. I have been struggling with this so long. I added that on window load and it worked. Thanks again
    – vids
    Nov 12 at 15:05















0














This is the example code that I have on my page



<!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>


The plugin code is added in the Brightcove player as per this reference https://support.brightcove.com/brightcove-player-sample-playpause-video-iframe-parent



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);
);


This works fine when i click on the PlayVideo. I need to make this work on load. If i call the function PlayVideo on document ready it gives error saying Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://players.brightcove.net') does not match the recipient window's origin ('http://localhost').



Any idea?










share|improve this question

















  • 1




    You’ll presumably have to wait until the plugin initialization is done, or at least until the iframe content is done loading.
    – misorude
    Nov 12 at 11:22










  • Thanks. it worked. I have been struggling with this so long. I added that on window load and it worked. Thanks again
    – vids
    Nov 12 at 15:05













0












0








0







This is the example code that I have on my page



<!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>


The plugin code is added in the Brightcove player as per this reference https://support.brightcove.com/brightcove-player-sample-playpause-video-iframe-parent



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);
);


This works fine when i click on the PlayVideo. I need to make this work on load. If i call the function PlayVideo on document ready it gives error saying Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://players.brightcove.net') does not match the recipient window's origin ('http://localhost').



Any idea?










share|improve this question













This is the example code that I have on my page



<!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>


The plugin code is added in the Brightcove player as per this reference https://support.brightcove.com/brightcove-player-sample-playpause-video-iframe-parent



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);
);


This works fine when i click on the PlayVideo. I need to make this work on load. If i call the function PlayVideo on document ready it gives error saying Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://players.brightcove.net') does not match the recipient window's origin ('http://localhost').



Any idea?







brightcove






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 11:17









vids

3710




3710







  • 1




    You’ll presumably have to wait until the plugin initialization is done, or at least until the iframe content is done loading.
    – misorude
    Nov 12 at 11:22










  • Thanks. it worked. I have been struggling with this so long. I added that on window load and it worked. Thanks again
    – vids
    Nov 12 at 15:05












  • 1




    You’ll presumably have to wait until the plugin initialization is done, or at least until the iframe content is done loading.
    – misorude
    Nov 12 at 11:22










  • Thanks. it worked. I have been struggling with this so long. I added that on window load and it worked. Thanks again
    – vids
    Nov 12 at 15:05







1




1




You’ll presumably have to wait until the plugin initialization is done, or at least until the iframe content is done loading.
– misorude
Nov 12 at 11:22




You’ll presumably have to wait until the plugin initialization is done, or at least until the iframe content is done loading.
– misorude
Nov 12 at 11:22












Thanks. it worked. I have been struggling with this so long. I added that on window load and it worked. Thanks again
– vids
Nov 12 at 15:05




Thanks. it worked. I have been struggling with this so long. I added that on window load and it worked. Thanks again
– vids
Nov 12 at 15:05

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261039%2fhow-to-pass-variable-from-a-parent-window-to-brightcove-player-html%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53261039%2fhow-to-pass-variable-from-a-parent-window-to-brightcove-player-html%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3