Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

HTML

              
                <!-- ideally this should be in <head> -->  
<script src="//cdn.viblast.com/vb/stable/viblast.js"></script>

<!-- body -->
<div>
  <button onclick="load('//cdn3.viblast.com/streams/hls/airshow/playlist.m3u8');" type="button">Load HLS Stream</button>
  <button onclick="load('//dash.edgesuite.net/dash264/TestCases/3b/fraunhofer/heaac_stereo_with_video/Sintel/sintel_480p_heaac_stereo_sidx.mpd');" type="button">Load MPEG-DASH Stream</button>
</div>

<video id="player" controls muted>
</video>

<div class="quality-controls">
Available Video Qualities:
<select id="video-qualities" onchange="changeQuality(this, 'video');">
  <option value="NA">NA</option>
</select>

Current Quality: <span id="current-video-quality">NA</span>
</div>

<div class="quality-controls">
Available Audio Qualities:
<select id="audio-qualities" onchange="changeQuality(this, 'audio');">
  <option value="NA">NA</option>
</select>

Current Quality: <span id="current-audio-quality">NA</span>
</div>

<div>
  Current CDN Bandwidth:
  <span id="cdn-bandwidth">NA</span>
  <span class="note">Beware that due to caching values much higher than the actual bandwidth may be reported</span>
</div>
              
            
!

CSS

              
                video { height: 200px; width: auto; }
.quality-controls { margin-bottom: 0.5em; }
.note { color: gray; padding-left: 1em; }
              
            
!

JS

              
                var player = document.getElementById('player');

function formatQuality(quality) {
  var res = '';
  if (quality.width && quality.height) {
    res += quality.width + 'x' + quality.height + ' ';
  }
  res += quality.bandwidth + 'bps';
  return res;
}

function changeQuality(control, channel) {
  var selectedQuality = control.value;
  if (selectedQuality === "auto") {
    player.viblast.abr = true;
  } else {
    player.viblast[channel].quality = player.viblast[channel].qualities[parseInt(selectedQuality)];
  }
}

function onUpdatedMetadata() {
  refreshAvailableQualities('video');
  refreshAvailableQualities('audio');
  
  refreshQuality('video');
  refreshQuality('audio');
}

function refreshAvailableQualities(channel) {
  var qualitiesControl = document.getElementById(channel + '-qualities');
  qualitiesControl.innerHTML = '';
  qualitiesControl.innerHTML += '<option value="auto">Auto</option>'
  for (var i = 0; i<player.viblast[channel].qualities.length; i++) {
    var quality = player.viblast[channel].qualities[i];
    qualitiesControl.innerHTML += '<option value="' + i + '">'  + formatQuality(quality) + '</option>';
  }
}

function refreshQuality(channel) {
  if (!player.viblast[channel] || !player.viblast[channel].quality) return;
  var currQualityControl = document.getElementById('current-' + channel + '-quality');
  currQualityControl.innerHTML = formatQuality(player.viblast[channel].quality);
};

function load(src) {
  // clean up any old instances
  viblast(player).stop();
  
  // start playing the new stream
  viblast(player).setup({
    stream: src,
    key: 'N8FjNTQ3NDdhZqZhNGI5NWU5ZTI='
  });
  player.play();
  
  // register the updatedmetadata each time because after src change event hanlers are cleared
  player.viblast.addEventListener('updatedmetadata', onUpdatedMetadata);
  // check if metadata has already been loaded
  // if yes then updatedmetadata will not be fired so just call the callback manually
  if (player.viblast.video) onUpdatedMetadata();
  
  player.viblast.addEventListener('videoqualitychange', refreshQuality.bind(null, 'video'));
  player.viblast.addEventListener('audioqualitychange', refreshQuality.bind(null, 'audio'));
}

window.setInterval(function() {
  var control = document.getElementById('cdn-bandwidth');
  if (player.viblast) {
    control.innerHTML = player.viblast.cdnBandwidth + 'kbps';
  } else {
    control.innerHTML = 'NA';
  }
}, 1000);
              
            
!
999px

Console