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.

            
              <html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AMP Content Title</title>
    <meta name="description" content="Azure Media Player Content Title plugin">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!--Note: DO NOT USE the "latest" folder in production. Replace "latest" with a version number like "1.0.0"-->
    <!--EX:<script src="//amp.azure.net/libs/amp/1.0.0/azuremediaplayer.min.js"></script>-->
    <!--Azure Media Player versions can be queried from //amp.azure.net/libs/amp/latest/docs/changelog.html-->
    <link href="https://amp.azure.net/libs/amp/latest/skins/amp-default/azuremediaplayer.min.css" rel="stylesheet">
    <script src="https://amp.azure.net/libs/amp/latest/azuremediaplayer.min.js"></script>
</head>

<body>
    <h1>Content Title Plugin Sample</h1>

    <video id="azuremediaplayer" class="azuremediaplayer amp-default-skin amp-big-play-centered" controls autoplay width="640"
           height="400" poster="" data-setup='{ "nativeControlsForTouch": false, "logo": { "enabled": false }, "plugins": { "contentTitle": { "name": "Azure Media Services Overview", "horizontalPosition": "left", "verticalPosition": "center" } } }'
           tabindex="0">
        <source src="https://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest"
                type="application/vnd.ms-sstr+xml" />
        <p class="amp-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video</p>
    </video>
    <div id="overlay">
      <p id="overlayText">Overlay Text</p>
    </div>
  <button id ="overlayBtn">Toggle Stats Overlay</button>
    <footer>
        <br />
        <p>&copy;Dave Voyles 2016</p>
    </footer>
</body>

</html>
            
          
!
            
              #overlay {
  position: absolute; 
  top: 110px; 
  left: 20px;
  background-color: rgba(0,0,0,  0.6);
  width: 640px;
  padding: 10px 0;
  z-index: 2147483647;
}

#overlayText {
  color: #FFF; 
  text-align: left;
  padding: 0 16px;
  margin: 0px;
  font-size: 16px;
  text-shadow: 2px 2px #000000;
  font-family: Segoe UI;
  font-size: 14px;
  font-style: normal;
  font-variant: normal;
  font-weight: 400;
  line-height: 19.99px;
}

            
          
!
            
              // TODO: Add a stats display button to the AMS player, adjacent to audio / video feed buttons
(function (mediaPlayer) {
    "use strict";

    mediaPlayer.plugin('contentTitle', function (options) {
        var player         = this;    
        var overlay        = document.getElementById('overlay');
        var overlayBtn     = document.getElementById('overlayBtn');
        var overlayText    = document.getElementById('overlayText');
        var bOverlayHidden = "false";
        var log            = console.log.bind(console); // Shorthand for console.log
        var p              = player.mediaPlayer;
        var res            = p.videoWidth          + " x " + p.videoHeight; 
        var widthHeight    = player.options_.width + " x " + player.options_.height;
      
      
      /**
       * Make the overlay width 1/2 of the width of the video player
       */
      function setOverlayWidth () {
        var sWidth          = "" + player.options_.width / 2 + "px";
        overlay.style.width = sWidth;
      };      
      setOverlayWidth();

      
      /**
       * Takes player source URL and determines if it is using http || https.
       * @return {string} - "http" or "https" 
       */
      function getHttpStatus () {
        var endpoint = p.src;
        
        // Head returns 'http' or 'https'
        // ^  Start of Line
        // .  Match zero or more
        // *  Match previous char
        // \  Literal next char
        var re                 = /^.*:\/\//;
        var head               = re.exec( endpoint );      
        
       if (head[0] === "https://") {
          return "https"; 
        } else { 
          return "http";
        }
        
      }
      

      /**
       * Data object used to store misc values of AMS player.
       */
      var data = {
          "curPlaybackBitrate": "", 
          "mimeType"          : p.type,
          "src"               : p.src,
          "curTime"           : "",
          "stream type"       : "", // TODO
          "connSpeed"         : "", // TODO
          "res"               : "",
          "dimensions"        : "",
          "avgBandwidthKbps"  : "",
          "curDlBitrate"      : "" ,
          "streamType"        : ""
        }
      
      
      /**
       * Instantiates a formatted block of text based on info returnes from data object.
       * @param {object} stats - Accepts data object, which is automatically updated every (x) seconds. 
       * @return {string} - Formatted string which will be set as the innerText of the overlay
       */
      function createTextBlock (stats) {        
        var sData = 
          "Mime Type: "      + stats.mimeType          + '\n' +
          "Dimensions: "     + stats.dimensions        + '\n' +
          "Res: "            + stats.res               + '\n' +  
          "Dl Bitrate: "     + stats.curDlBitrate      + '\n' +  
          "Avg Bandwidth: "  + stats.avgBandwidthKbps  + '\n' +
          "Stream Type: "    + stats.streamType        + '\n' ;
        
        return sData;
      }
      
      
      /**
       * Sets the text value of the overlay with updated stats from data object.
       */
      function updateOverlayText () {
        // overlay.innerText = createTextBlock(data);
        overlayText.innerText = createTextBlock(data);
      }
      
      
      /**
      * Conver size to bytes
      * @param {number} bytes - downlaod value
      * @param {string} decimals - Where should the placeholder be?
      * @return {number} parseFloat - size changes, depending on initial size of bytes passed in
      */
      function formatBytes(bytes,decimals) {
          if(bytes == 0) return '0 Byte';
          var k     = 1000;
          var dm    = decimals + 1 || 3;
          var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
          var i     = Math.floor(Math.log(bytes) / Math.log(k));

          return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
      }
      

      /**
       * Updates data object every (x) seconds, which the stats overlay text object then reads 
       */
      function setValuesForStatsOverlay () {       
        setInterval(function () { data.curTime            = p.currentTime},                         1000);
        setInterval(function () { data.curDlBitrate       = formatBytes(p.currentDownloadBitrate)}, 1000);   
        setInterval(function () { data.avgBandwidthKbps   = formatBytes(p.videoBufferData._bandwidthTracker.averageBandwidthInKbps)}, 1000);
        setInterval(function () { data.dimensions         =  player.options_.width + " x " + player.options_.height                },  1000); 
        setInterval(function () { data.curDlBitrate       = formatBytes(p.currentDownloadBitrate)}, 1000);
        setInterval(function () { data.curPlaybackBitrate = formatBytes(p.currentPlaybackBitrate)}, 1000);
        setInterval(function () { data.res                =  p.videoWidth + " x " + p.videoHeight}, 1000);            
        setTimeout(function  () { data.streamType         = getHttpStatus()                      }, 1000);        
        setInterval(function () { updateOverlayText()                                            }, 1000); 
        // retrieve values for DEBUGGING
         console.log(player);
        // console.log(player.mediaPlayer);          
      }
      
      
      /**
       * Toggles visibiltiy of overlay. Ideally this would be embedded as a btn in the AMS player.
       */
      function toggleOverlayVisibility()  {		
        var bVisibility           = (bOverlayHidden  === "false") ? "hidden" : "visible";	        
        overlay.style.visibility  = bVisibility;
        bOverlayHidden            = (bOverlayHidden  === "false") ? "true"   : "false";		
      };


        /**
         * Main function -- Entry point of this application
         */
        player.ready(function () {
          log("player ready");
          player.on('play', setValuesForStatsOverlay);    
          overlay.onclick    = toggleOverlayVisibility;
          overlayBtn.onclick = toggleOverlayVisibility;     
        });
    });
}(window.amp));
            
          
!
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