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

              
                <h2>Video Thumbnail Grid Sample</h2>
<div id="video_container">
  <div id="video_grid"></div>
</div>
<div id="player_container"></div>

<!-- Player loader script -->
<script src="https://apis.support.brightcove.com/assets/js/playback/brightcove-player-loader.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: #f5f5f5;
  font-family: sans-serif;
  margin: 2em;
}
/*
 * Styles essential to the sample
 * are below
 */
.bcls-code {
  color: #111;
  font-family: monospace;
  padding: 1em;
  width: 90%;
  min-height: 5em;
  background-color: #cfcfcf;
  font-size: 1rem;
}
.bcls-button {
  padding: 0.5em;
  background-color: #333;
  border: 1px yellow solid;
  border-radius: 0.5em;
  color: yellow;
  cursor: pointer;
}
fieldset {
  color: #64aab2;
  border: 1px #64aab2 solid;
  border-radius: 0.5em;
}
code {
  color: #e4b842;
  font-family: monospace;
}
.bcls-table {
  border-collapse: collapse;
  border: 1px #64aab2 solid;
}

.bcls-table .bcls-table__head th {
  border: 1px #64aab2 solid;
  padding: 0.5em;
}
.bcls-table .bcls-table__body td {
  border: 1px #64aab2 solid;
  padding: 0.5em;
}

/** Styles for this sample **/
#video_container, #player_container {
  display: inline-block;
  max-width: 50%;
}

#video_container {
  vertical-align: top;
}

#player_container {
  min-width: 480px;
  vertical-align: middle;
}

#video_grid {
  display: grid;
  grid-template-columns: 33% 33% auto; 
}

.grid-item {
  margin-right: 5px;
  margin-bottom: 5px;
  cursor: pointer;
}

.thumbnail {
  width: 160px;
  height: 90px;
}

.truncate {
  font-size: small;
  min-width: 160px;
  width: 160px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space:nowrap;
}

.video-js {
  width: 480px;
  height: 270px;
  margin-top: 50px;
}


              
            
!

JS

              
                var BCLS = (function (window, document) {
  /**
   * To build your own version, replace the following with values from your account:
   * account_id
   * policy_key
   * video_ids
   * player_id
   */
  var account_id = '1752604059001',
      policy_key =
      'BCpkADawqM3CNfUEBYGvWS8QqHHg-g5kzNt63RmoOyVlrIL4zT67_KKSzlaI5TGMXIZZ4Yrtz28v7EcHTsTWAiOolxok8ZNqFrkNGru9OOumeQ8wX5csvYqx7zl468WgbhqDnpePPhQVpQfr',
      video_ids = [
        '6156696074001',
        '5811864560001',
        '5715315990001',
        '5550679964001',
        '5686632029001',
        '5819230967001',
        '5992439742001',
        '5811857173001',
        '6026822730001'
      ],
      player_id = 'WRgbJgqAe',
      player_container = document.getElementById('player_container'),
      video_grid = document.getElementById('video_grid');
      
  /**
   * Create player to play the video
   *
   * @param {string} video_id - the video to load into the player
   */
  function buildPlayer (video_id) {
    brightcovePlayerLoader({
      refNode: player_container,
      accountId: account_id,
      playerId: player_id,
      videoId: video_id,
      embedId: 'default',
    })
      .then(function (success) {
        console.log('player loaded');
      })
      .catch(function (error) {
        var p = document.createElement('p');
        p.textContent =
          'Sorry - the player could not be loaded. Please try again later.';
        player_container.appendChild(p);
      });
  }

  /**
   * Build the video grid
   *
   * @param {Array} video_data - the video data retrieved from the Playback API
   */
  function buildGrid (video_data) {
    var i = 0,
        iMax = video_data.length,
        div,
        img,
        p,
        video,
        frag = document.createDocumentFragment();

    for (i; i < iMax; i++) {
      video = video_data[i];
      div = document.createElement('div');
      img = document.createElement('img');
      p = document.createElement('p');
      div.setAttribute('id', video.id);
      div.setAttribute('class', 'grid-item');
      img.setAttribute('src', video.thumbnail);
      img.setAttribute('class', 'thumbnail');
      p.setAttribute('class', 'truncate');
      p.textContent = video.name;
      frag.appendChild(div);
      div.appendChild(img);
      div.appendChild(p);
    }
    video_grid.appendChild(frag);
    setListeners();
  }

  /**
   * Set event listeners for the grid items
   */
  function setListeners() {
    var i = 0,
        grid_items = document.getElementsByClassName('grid-item'),
        iMax = grid_items.length;
    for (i; i < iMax; i++) {
      grid_items[i].addEventListener('click', function(e) {
        player_container.innerHTML = '';
        buildPlayer(this.id);
      });
    }
  }

  /**
   * Set up the API request
   */
  function createRequest () {
    var request_data = {},
        i = 0,
        iMax = video_ids.length;

    request_data.request =
      'https://edge.api.brightcove.com/playback/v1/accounts/' + account_id + '/videos?q=';
    // add video ids to the search string
    for (i; i < iMax; i++) {
      request_data.request = request_data.request + 'id:' + video_ids[i];
      if (i < iMax - 1) {
        request_data.request = request_data.request + '%20';
      }
    }
    // add the policy key
    request_data.policy_key = policy_key;
    sendRequest(request_data, function (video_data) {
      if (video_data && video_data.length > 0) {
        video_data = JSON.parse(video_data);
        buildGrid(video_data.videos);
      } else {
        var h4 = document.createElement('h4');
        h4.textContent =
          'Videos are currently unavailable. Please try again later.';
        video_grid.appendChild(h4);
      }
    });
  }

  /**
   * Send API request and return response to caller
   *
   * @param {object} request_data - the API request and policy key
   * @param {*} callback - function to handle the response
   */
  function sendRequest (request_data, callback) {
    var httpRequest = new XMLHttpRequest(),
        // response handler
        getResponse = function () {
          try {
            if (httpRequest.readyState === 4) {
              if (httpRequest.status >= 200 && httpRequest.status < 300) {
                callback(httpRequest.responseText);
              }
            }
          } catch (e) {
            alert('Caught Exception: ' + e);
          }
        };

    // set response handler
    httpRequest.onreadystatechange = getResponse;
    // open the request
    httpRequest.open('GET', request_data.request);
    // set headers
    httpRequest.setRequestHeader('BCOV-Policy', request_data.policy_key);
    // open and send request
    httpRequest.send();
  }

  // kick things off by fetching the video data
  createRequest();
})(window, document);

              
            
!
999px

Console