Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <video-js id="myPlayerID" 
  data-video-id="4784521906001" 
  data-account="1752604059001" 
  data-player="ryeOJ8f5dZ" 
  data-embed="default"
  data-application-id 
  controls></video-js>
<script src="https://players.brightcove.net/1752604059001/ryeOJ8f5dZ_default/index.min.js"></script>
              
            
!

CSS

              
                /* * The body style is just for the
 * background color of the codepen.
 * Do not include in your code.
 */
body {
  background-color: #111;
  color: #fff;
}
/*
 * Styles essential to the sample
 * are below
 */
.video-js {
  height: 344px;
  width: 610px;
}
.hide-overlay .vjs-overlay {
  display: none;
}

              
            
!

JS

              
                var myPlayer, timeoutID, removeCTATime;
videojs.getPlayer('myPlayerID').ready(function() {
  var cuePointAra = [],
    allCuePointData;
  myPlayer = this;
  // Hide overlay initially
  myPlayer.addClass("hide-overlay");

  // +++ Listen for cue change then pass data to be displayed +++
  myPlayer.on("loadstart", function(evt) {
    cuePointAra = myPlayer.mediainfo.cue_points;
    var tt = myPlayer.textTracks()[0];
    // When a cue point starts, extract cue data and pass data to be displayed
    tt.oncuechange = function() {
      if (tt.activeCues[0] !== undefined) {
        allCuePointData = getSubArray(
          cuePointAra,
          "time",
          tt.activeCues[0].startTime
        );
        displayCTA(allCuePointData[0]);
      }
    };
    myPlayer.play();
  });

  // +++ Extract data pieces from cue point meta data and display overlay  +++
  function displayCTA(cpData) {
    // Split metadata into an array of three pieces based on location of semicolons
    var dataAra = cpData.metadata.split(";"),
      durationCTA = dataAra[0],
      textCTA = dataAra[1],
      urlCTA = dataAra[2],
      // Dynamically build the anchor tag
      hrefCTA =
        '<a href="' +
        urlCTA +
        '"><span style="background-color: black; color: red;">' +
        textCTA +
        "</span></a>",
      timeoutValue;
    // Set duration, set timeout, inject dynamic html and show overlay
    timeoutValue = Number(durationCTA) * 1000;
    timeoutID = window.setTimeout(checkTime, timeoutValue);
    document.getElementsByClassName("vjs-overlay")[0].innerHTML = hrefCTA;
    myPlayer.removeClass("hide-overlay");
  }

  // +++ Clear timeout and remove overlay +++
  // This function called when timeout is reached
  function checkTime() {
    window.clearTimeout(timeoutID);
    myPlayer.addClass("hide-overlay");
  }

  // +++ Helper function to extract cue point info +++
  function getSubArray(targetArray, objProperty, value) {
    var i,
      totalItems = targetArray.length,
      objFound = false,
      idxArr = [];
    for (i = 0; i < totalItems; i++) {
      if (targetArray[i][objProperty] === value) {
        objFound = true;
        idxArr.push(targetArray[i]);
      }
    }
    return idxArr;
  }
});

              
            
!
999px

Console