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.

            
              <h1>Create Player</h1>
<section class="bcls-section">
<h2 id="infoinput">Player info input</h2>

<p>Account ID: <input class="checkForValue" id="account_id_input" type="text" size="40" name="account_id" /></p>

<p>Client ID: <input class="checkForValue" id="client_id_input" type="text" size="100" name="client_id_input" /></p>

<p>Client Secret: <input class="checkForValue" id="client_secrect_input" type="password" size="100" name="client_secrect_input" /></p>

<p>Player Name: <input class="checkForValue" id="player_name_input" type="text" size="100" name="player_name_input" /></p>

<p>Media URL OR Video Cloud video id: <input class="checkForValue" id="media_url_input" type="text" size="200" value="https://learning-services-media.brightcove.com/videos/mp4/oystercatcher.mp4" name="media_url_input" /></p>

<p>Media Type: <select id="media_type_input"><option value="video/mp4" selected="selected">video/mp4</option><option value="application/x-mpegURL">HLS (application/x-mpegURL)</option></select></p>

<p><button id="create_player" class="bcls-button">Create Player</span></p>
</section>

<section class="bcls-section">
<h2 id="jsonText">JSON response</h2>

<p>Below is the JSON data returned by the player creation:</p>

<pre><code id="create_response">Response will appear here...</code></pre>

<p>Below is the JSON data returned by the player publish:</p>

<pre><code id="publish_response">Response will appear here...</code></pre>
</section>

<section class="bcls-section">
<h2 id="embedded_player">Processed response</h2>
<p>
  <button class="bcls-button" id="preview_player">Preview the Player</button>
</p>

<p>Note publishing is asynchrounous; if the player doesn't immediately appear, wait a few seconds and try again. </p>

<div id="player_embedded"></div>
</section>

            
          
!
            
              /* * 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: 'Source Code Pro',monospace;
  padding: 1em;
  width: 90%;
  min-height: 5em;
  background-color: #cfcfcf;
  font-size: 1rem;
}
.bcls-button {
  padding: .5em;
  background-color: #333;
  border: 1px yellow solid;
  border-radius: .5em;
  color: yellow;
  cursor: pointer;
}
fieldset {
  color: #64AAB2;
  border: 1px #64AAB2 solid;
  border-radius: .5em;
}
code {
  color: #E4B842;
  font-family: 'Source Code Pro',monospace;
}
            
          
!
            
              var BCLS = ( function (window, document) {
  // account id calue is the default
  var account_id = '57838016001',
    account_password = '',
    account_username = '',
    player_name = '',
    player_id,
    account_id_input = document.getElementById('account_id_input'),
    client_id_input = document.getElementById('client_id_input'),
    client_secrect_input = document.getElementById('client_secrect_input'),
    player_name_input = document.getElementById('player_name_input'),
    media_url_input = document.getElementById('media_url_input'),
    media_type_input = document.getElementById('media_type_input'),
    create_response = document.getElementById('create_response'),
    publish_response = document.getElementById('publish_response'),
    player_embedded = document.getElementById('player_embedded'),
    create_player = document.getElementById('create_player'),
    preview_player = document.getElementById('preview_player'),
    player_code,
    now = new Date();

    // initial value for player name (make unique)
    player_name_input.value = 'Test Player ' + now.toISOString();

    // event handlers
    create_player.addEventListener('click', function() {
      createRequest('createPlayer');
    });

    preview_player.addEventListener('click', function() {
      // inject the player - clear the div first to allow repeated clicks
      player_embedded.innerHTML = '';
      player_embedded.insertAdjacentHTML('afterbegin', player_code);
    });

  /**
   * get selected value for single select element
   * @param {htmlElement} e the select element
   * @return {String} the selected value
   */
  function getSelectedValue(e) {
      var selected = e.options[e.selectedIndex],
          val = selected.value;
      return val;
  }

  /**
   * createRequest sets up requests, send them to makeRequest(), and handles responses
   * @param  {string} type the request type
   */
  function createRequest(type) {
    var options   = {},
      requestBody = {},
      proxyURL = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php',
      baseURL = 'https://players.api.brightcove.com/v1/accounts/',
      endpoint,
      responseDecoded;

    if (client_id_input.value.length > 0 && client_secrect_input.value.length > 0) {
      options.client_id     = client_id_input.value;
      options.client_secret = client_secrect_input.value;
    }

    options.account_id = (account_id_input.value.length > 0) ? account_id_input.value : account_id;
    options.proxyURL = proxyURL;

    switch (type) {
        case 'createPlayer':
          endpoint            = '/' + options.account_id + '/players';
          options.url         = baseURL + endpoint;
          options.requestType = 'POST';
          requestBody.name = player_name_input.value;
          requestBody.configuration = {};
          if (media_url_input.value.indexOf('//') > -1) {
            requestBody.configuration.media = {};
            requestBody.configuration.media.sources = [];
            requestBody.configuration.media.sources[0] = {};
            requestBody.configuration.media.sources[0].src = media_url_input.value;
            requestBody.configuration.media.sources[0].type = getSelectedValue(media_type_input);
          } else {
            // assume video id
            requestBody.configuration.video_cloud = {};
            requestBody.configuration.video_cloud.video = media_url_input.value;
          }
          options.requestBody = JSON.stringify(requestBody);
          makeRequest(options, function(response) {
              responseDecoded = JSON.parse(response);
              player_id = responseDecoded.id;
              create_response.textContent = JSON.stringify(responseDecoded, null, 2);
              if (player_id) {
                createRequest('publishPlayer');
              }
          });
          break;
        case 'publishPlayer':
          endpoint            = '/' + options.account_id + '/players/' + player_id + '/publish';
          options.url         = baseURL + endpoint;
          options.requestType = 'POST';
          makeRequest(options, function(response) {
            responseDecoded = JSON.parse(response);
            player_code = responseDecoded.embed_code;
            publish_response.textContent = JSON.stringify(responseDecoded, null, 2);
          });
          break;

        // additional cases
        default:
          console.log('Should not be getting to the default case - bad request type sent');
          break;
    }
  }

  /**
   * 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(),
       response,
       requestParams,
       dataString,
       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
               callback(response);
             } else {
               alert('There was a problem with the request. Request returned ' + httpRequest.status);
             }
           }
         } 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
     httpRequest.send(JSON.stringify(options));
   }

})(window, document);

            
          
!
999px
🕑 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 ..................

Console