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-js id="bcls_alltimePlaysPlayer"

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

  <script src="https://players.brightcove.net/1752604059001/S1UUAwWzM_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: 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 = "https://analytics.api.brightcove.com/v1/alltime/accounts/";
  options.proxyURL = "https://solutions.brightcove.com/bcls/bcls-proxy/brightcove-learning-proxy-v2.php";
  options.requestType = "GET"
  options.hasPlaylist = true;

  // listener for the first video load
  player.one('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 = player.mediainfo.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 = player.mediainfo.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
    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 ..................