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


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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


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.

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.


                  <video-js id="bcls_alltimePlaysPlayer"

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

  <script src=""></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: 309px;
  width: 550px;
  float: left;

#bcls_alltimePlaysPlaylist {
  max-width: 170px;
  min-width: 150px;
  height: 309px;
  padding: 5px 5px 0 5px;
  background-color: #6a8d9d;
  /* lighter blue */

#bcls_alltimePlaysPlaylist .vjs-playlist-item {
  background-color: #6a8d9d;
  /* lighter blue */
  margin-bottom: 5px;
  height: 90px;



                videojs.getPlayer('bcls_alltimePlaysPlayer').ready(function() {  
  var player = this,
      videoElement = document.getElementById('bcls_alltimePlaysPlayer'),
      account_id = videoElement.getAttribute('data-account'),
      // Build options needed for Analytics API request
      options = {},
      baseURL = "";
      options.proxyURL = "";
      options.requestType = "GET";
      options.hasPlaylist = true;

  // listener for the first video load'loadedmetadata', function() {
    // +++ Create the element to hold the video views +++
    el = document.createElement('p');
    el.setAttribute('id', 'bcls_alltimeViews');
    el.setAttribute('style', 'font-weight:bold;');
    if (options.hasPlaylist) {
      var playlistEl = document.getElementById('bcls_alltimePlaysPlaylist');
      playlistEl.insertAdjacentElement('afterend', el);
    } else {
      videoElement.insertAdjacentElement('afterend', el);
    alltimeViewsEl = document.getElementById('bcls_alltimeViews');

    // +++ Get the current video id from mediainfo then start process to get views count +++
    video_id =;
    // launch the Analytics API request to get the alltime video views

    // +++ Set listener for future requests +++
    player.on('loadedmetadata', function() {
      // Clear element where count is shown
      alltimeViewsEl.textContent = '';
      // get the current video id from mediainfo
      video_id =;
      // launch the Analytics API request to get the alltime video views

       * formats an integer by adding commas for thousands separators
       * @param  {Integer} x Number to format
       * @return {String}   The formatted number
  function numberWithCommas(x) {
    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

  // +++ Prepare information for request to proxy/Analytics API +++
       * createRequest sets up requests, send them to makeRequest(), and handles responses
       * @param  {string} type the request type
  function createRequest() {
    var JSONresponse;

    // set the Analytics API request
    options.url = baseURL + account_id + '/videos/' + video_id;
    // send the request and handle the response
    makeRequest(options, function (response) {
      // Convert response string into JSON
      JSONresponse = JSON.parse(response);
      // should always get a response, but just in case...
      if (JSONresponse && JSONresponse.alltime_video_views) {
        // write the views to the UI
        alltimeViewsEl.textContent = numberWithCommas(JSONresponse.alltime_video_views) + ' views';
      } else {
        alltimeViewsEl.textContent = 'All-time views for this video are not available';

  // +++ Makes actual call for data +++
    * 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"POST", proxyURL);
    // set headers if there is a set header line, remove it
    // open and send request