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.

              <video id="myPlayerID"

  <div class="vjs-playlist"></div>

  <script src="//players.brightcove.net/1752604059001/H18cgu1wG_default/index.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
.video-js {
  height: 280px;
  width: 512px;
  float: left;
.vjs-playlist {
  width: 224px;
  height: 280px;
              videojs("myPlayerID").ready(function() {
  // +++ Initialize variables and option object for CMS API call +++
  // Data structures for manipulated video data
  var myPlayer = this,
    mostWatchedVideos = [],
    videoData = [],
    videoObjects = [],
    // +++ Build options needed for CMS API request +++
    options = {},
    requestBody = {},
    accountId = "1752604059001",
    baseURL = "https://cms.api.brightcove.com/v1/accounts/",
    endPoint = "?sort=-plays_total&limit=10";
  options.url = baseURL + accountId + "/videos" + endPoint;
  options.proxyURL =
  options.requestType = "GET";

  // +++ Helper Function: Retrieve video objects from video IDs +++
   * get video objects
   * @param {array} videoIds array of video ids
   * @return {array} videoData array of video objects
  function getVideoData(videoIds, callback) {
    var i = 0,
      iMax = videoIds.length,
      videoObjectsForReturn = [];
     * makes catalog calls for all video ids in the array

    function getVideo() {
      if (i < iMax) {
        myPlayer.catalog.getVideo(videoIds[i].id, pushData);
      } else {

    // +++ Helper Function: Callback function that places video objects into array +++
     * callback for the catalog calls
     * pushes the returned data object into an array
     * @param {string} error error returned if the call fails
     * @parap {object} video the video object
    function pushData(error, video) {

  // +++ Helper Function: Extract video IDs from data CMS API response +++
   * extract video data from CMS API response
   * @param {array} cmsData the data from the CMS API
   * @return {array} videoData array of video info
  function extractVideoData(cmsData) {
    var i,
      iMax = cmsData.length,
      videoDataForReturn = [];
    for (i = 0; i < iMax; i++) {
      if (cmsData[i].id !== null) {
        videoItem = {};
        videoItem.id = cmsData[i].id;
    return videoDataForReturn;

  // +++ Make the CMS API request to get matching video IDs +++
  makeRequest(options, function(mostWatchedVideos) {
    var JSONmostWatchedVideos;
    // Convert response string into JSON
    JSONmostWatchedVideos = JSON.parse(mostWatchedVideos);
    // Extract the needed video IDs into an array
    videoData = extractVideoData(JSONmostWatchedVideos);
    // Get video objects based on array of video IDs
    getVideoData(videoData, function(videoObjects) {
      // Add the most watched videos list to the player as a playlist

  // +++ Make actual request to API +++
   * send API request to the proxy
   * @param  {Object} options for the request
   * @param  {String} options.url the full API request URL
   * @param  {String="GET","POST","PATCH","PUT","DELETE"} requestData [options.requestType="GET"] HTTP type for the request
   * @param  {String} options.proxyURL proxyURL to send the request to
   * @param  {String} options.client_id client id for the account (default is in the proxy)
   * @param  {String} options.client_secret client secret for the account (default is in the proxy)
   * @param  {JSON} [options.requestBody] Data to be sent in the request body in the form of a JSON string
   * @param  {Function} [callback] callback function that will process the response
  function makeRequest(options, callback) {
    var httpRequest = new XMLHttpRequest(),
      proxyURL = options.proxyURL,
      // response handler
      getResponse = function() {
        try {
          if (httpRequest.readyState === 4) {
            if (httpRequest.status >= 200 && httpRequest.status < 300) {
              response = httpRequest.responseText;
              // some API requests return '{null}' for empty responses - breaks JSON.parse
              if (response === "{null}") {
                response = null;
              // return the response
            } else {
                "There was a problem with the request. Request returned " +
        } catch (e) {
          alert("Caught Exception: " + e);
     * set up request data
     * the proxy used here takes the following request body:
     * JSON.strinify(options)
    // set response handler
    httpRequest.onreadystatechange = getResponse;
    // open the request
    httpRequest.open("POST", proxyURL);
    // set headers if there is a set header line, remove it
    // open and send request

🕑 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 ..................