css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <link href="https://players.brightcove.net/videojs-overlay/2/videojs-overlay.css" rel="stylesheet">

<video-js id="myPlayerID"

<p>Show "Are you still there?" message after <input id="timeCheckOption" value="5" size="5" style="width:20px;text-align:center;" /> seconds.</p>
<p>If the message is not clicked, pause the video after <input id="timeOutOption" value="5" size="5" style="width:20px;text-align:center;" /> seconds.</p>

  <legend>Message Box</legend>
  <p>Time elapsed since last check: <span id="timeSinceLastCheck"></span> seconds</p>
  <p>Current position: <span id="currentPosition"></span> seconds</p>

<script src="https://players.brightcove.net/1752604059001/default_default/index.min.js"></script>
<script src="https://players.brightcove.net/videojs-overlay/2/videojs-overlay.min.js"></script>
              /* * 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

/* hide the overlay */
.hide-overlay .vjs-overlay {
  display: none;

/* format the overlay */
.video-js div.vjs-overlay.vjs-overlay-bottom-left.vjs-overlay-background {
  width: 70%;
  color: #fff;
  background-color: rgba(255, 0, 0, 0.6);
  font-size: 1em;
  text-align: center;
  cursor: pointer;

/* set player size */
.video-js {
  width: 640px;
  height: 360px;

              videojs.getPlayer('myPlayerID').ready(function() {
  // +++ Initialize variables +++
  var myPlayer = this,
    msgShown = false,
    options = {
      // elapsed time for checking if viewer is still there (in seconds)
      timeCheckPoint: 5,
      // time to allow before stopping video (in seconds)
      timeOut: 5
    // reference in overlay message
    // references to option elements (for sample only - developers would set these in the options object above)
    eTimeCheckOption = document.getElementById("timeCheckOption"),
    eTimeOutOption = document.getElementById("timeOutOption"),
    eTimeSinceLastCheck = document.getElementById("timeSinceLastCheck"),
    eCurrentPosition = document.getElementById("currentPosition"),
    // counters for time and videos elapsed (short-form) and time checks (long-form)
    totalElapsedTime = 0,
    timeSinceLastCheck = 0,
    timeToNextPoint = options.timeCheckPoint,
    lastCheckTime = 0;

  // +++ Configure the overlay +++
    name: "overlay",
    content: "<strong>Default overlay content</strong>",
    overlays: [
          "<div id='overlayButton'>Just checking...are you still there? Click this message to continue watching, or the video will stop in <span id='timerSpan'></span> seconds</div>",
        start: "loadedmetadata",
        align: "bottom-left"

  // +++ Initially hide the overlay message +++

  // +++ Display overlay message and start countdown to pause +++
  var showMessage = function() {
    console.log("in function: showMessage");
    var seconds_left = options.timeOut;
    eTimerSpan.innerHTML = seconds_left;
    // show the overlay message
    // start the countdown
    intervalID = setInterval(function() {
      seconds_left -= 1;
      eTimerSpan.innerHTML = seconds_left;
      console.log("seconds left: ", seconds_left);
      if (seconds_left <= 0) {
        // reset the counters
        // stop the video
        // hide the overlay message
        lastCheckTime = Math.floor(myPlayer.currentTime());
    }, 1000);

  // +++ Hide the overlay +++
  var hideMessage = function() {
    console.log("in function hideMessage");

  // +++ Reset counters after click or pause +++
  var resetCounters = function() {
    console.log("in function resetCounters");
    totalElapsedTime = 0;
    timeSinceLastCheck = Math.floor(myPlayer.currentTime()) - lastCheckTime;
    timeToNextPoint = myPlayer.currentTime() + options.timeCheckPoint;
    msgShown = false;

  // +++ When the player is loaded, add a click event listener to the overlay +++
  myPlayer.one("loadedmetadata", function(evt) {
    eTimerSpan = document.getElementById("timerSpan");
    overlayButton.addEventListener("click", function() {
      lastCheckTime = Math.floor(myPlayer.currentTime());

  // +++ When playback position changes, show the overlay msg if greater than time check point +++
  myPlayer.on("timeupdate", function(evt) {
    console.log("myPlayer.currentTime()", myPlayer.currentTime());
    timeSinceLastCheck = Math.floor(myPlayer.currentTime()) - lastCheckTime;
    console.log("timeSinceLastCheck", timeSinceLastCheck);
    if (myPlayer.currentTime() + totalElapsedTime > timeToNextPoint) {
      if (!msgShown) {
        console.log("startTime ", myPlayer.currentTime());
        msgShown = true;

    // Sample only: show time elapsed and position
    eTimeSinceLastCheck.innerHTML = timeSinceLastCheck;
    eCurrentPosition.innerHTML = Math.round(myPlayer.currentTime());

  // Sample only -- update options - developer would just do this in the code
  updateOptions = function() {
    options.timeCheckPoint = parseInt(eTimeCheckOption.value);
    options.timeOut = parseInt(eTimeOutOption.value);

  // Sample only: add event listeners for options changes
  eTimeCheckOption.addEventListener("change", updateOptions);
  eTimeOutOption.addEventListener("change", updateOptions);

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................