Stop brightcove video

Im using this script to pause vimeo videos in an iframe but I also need to do the same for Brightcove videos in an iframe

var iframes = document.getElementsByTagName('iframe');
for(var i = 0; i < iframes.length; i++) {
if(iframes[i].src.indexOf('vimeo') != -1) {
var player = new Vimeo.Player(iframes[i]);
player.pause();

Here's sample code for working with brightcove videos in iframe :Brightcove Player Sample: Play/Pause Video from iframe Parent

Can you see if this works for you?

function pauseBrightcoveVideos() {
  // Match the protocol of the of the parent's page
  var theProtocol = location.protocol;
  var theURL = theProtocol + "//players.brightcove.net";
  
  // Get all the iframe elements on the page
  var iframes = document.getElementsByTagName("iframe");

  // Loop through each iframe and check if it contains a Brightcove video
  for (var i = 0; i < iframes.length; i++) {
    var iframeSrc = iframes[i].getAttribute("src");

    // Check if the iframe contains a Brightcove video
    if (iframeSrc && iframeSrc.indexOf("brightcove") !== -1) {
      // Get a reference to the iframe's window object needed for postMessage
      var iframeWin = iframes[i].contentWindow;

      // Post message passing 'pauseVideo' as the data
      iframeWin.postMessage("pauseVideo", theURL);
    }
  }
}

Thanks Daniel, no it didn't work - do I need to put anything in the htm head like i do for vimeo?

Can you share your example Hype document and Brightcove embed?

One thing I should have clarified:

  • This function should be run in response to tapping a button or element as a mouse click action
  • Placing this within a Hype HTML widget (if the embed code is an iframe) results in a double iframe -- so if you have an 'iframe' embed code, place that within the inner HTML of a rectangle
1 Like