Pen Settings



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


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


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.


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.


                <!-- div elements added for responsive sizing -->
	<div style="display: block; position: relative; max-width: 640px;">
  <div style="padding-top: 56.25%;">
		<!-- Player embed code with id attribute added -->
    <video-js id="myPlayerID"
      style="width: 100%; height: 100%; position: absolute; top: 0px; bottom: 0px; right: 0px; left: 0px;"></video-js>
      <script src=""></script>
<!-- Container for the playlist -->
<div class="vjs-playlist"></div>

<!-- Button to advance the videos in the playlist -->
<input id="nextButton" type="button" value="Next Videos">

<!-- Optional: display the API request with the limit and offset parameters -->
<h3>Playback API request:</h3>
<pre class="line-numbers">
<code id="apiRequest" class="language-html" style="white-space: pre-line;">This text will be replaced</code></pre>


                /* * 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
/* Style the playlist */
.vjs-playlist.vjs-playlist {
  margin-left: 0;
  margin-top: .5em;
  max-width: 640px;
  height: 140px;
  white-space: nowrap;
  overflow-y: hidden;
  border-style: solid;
  border-width: 2px;
  border-color: black;
.vjs-playlist-item {
  display: inline-block;
  height: 140px;
.vjs-playlist-item img{
  width: 212px;
  height: 140px;
@media (min-width: 800px) {
  .vjs-playlist.vjs-playlist {
    overflow-x: hidden;


                var myPlayer,
    apiBaseURL = '',
    policyKey = "BCpkADawqM3_9ax216PJYuUTLApMLkLJ3apjFlTRKHHS4q0DE33J0XsiDWmc6SfKwrwRAhejCZpTbwljz4-OlUwyqKi64L25Dwy4yhY1eSZ9ZduI-dO0mjSNVcR9C8nz0jtkimOOtzQgswCr",
    accountId = "1752604059001",
    playlistId = "5282200243001",
    videoData = [],
    offsetValue = 0,
    limitValue = 3,
    firstTime = true,
    eNextButton = document.getElementById("nextButton"),
    // Optional: get a reference to the API request display element
    eApiRequest = document.getElementById("apiRequest"),

videojs.getPlayer('myPlayerID').ready(function() {
  // Get a reference to the player
  myPlayer = this;
  // +++ Load first set of videos +++
  // Use the catalog library to get the playlist object
  myPlayer.catalog.getPlaylist(playlistId, function(error, playlist){
    // Save the playlist length
    playlistLength = playlist.length;
    // Display the videos in the current playlist
    // Add a listener to the Next Videos button
   // +++ Listen for Next Videos button +++ 
      // Advance the video offset value by 3 to get the next videos in the playlist
      offsetValue += 3;
      // If the offset value is greater than the playlist length, then go back to the beginning of the playlist
      if (offsetValue >= playlistLength) {
        offsetValue = 0;
      // Display the videos in the current playlist

// +++ Load video data +++
function displayPlaylist() {
  // Set up data for Playback API request
  requestData = setRequestData();
  mediaType = 'playlist';
  // Make the Playback API request to get playlist data
  getMediaData(mediaType, requestData, function (mediaData) {
    // Loop through video data and change duration from milliseconds to seconds
    for (var i=0; i<limitValue; i++) {
      mediaData.videos[i] = myPlayer.catalog.transformVideoResponse(mediaData.videos[i], myPlayer);
    // Load the first video of the current playlist to the player
    // Add the newest videos list to the playlist

// +++ Create request URL +++
		 * Set up the data for the API request
function setRequestData() {
  var requestURL = '';
  // Create the request URL with offset and limit parameters
  requestURL = apiBaseURL +  accountId + '/playlists/' + playlistId + '?offset=' + offsetValue + '&limit=' + limitValue;
  // Optional: display the request URL
			 eApiRequest.innerHTML = requestURL;
  return requestURL;

// +++ Get video data +++
			* Request data from the Playback API
getMediaData = function(mediaType, requestURL, callback) {
  var httpRequest = new XMLHttpRequest(),
      // Response handler
      getResponse = function() {
        try {
          if (httpRequest.readyState === 4) {
            if (httpRequest.status >= 200 && httpRequest.status < 300) {
              responseData = httpRequest.responseText;
              parsedData = JSON.parse(responseData);
              switch (mediaType) {
                case 'video':
                  // Do nothing
                case 'playlist':
                  // Return the parsed data from the Playback API response
            } else {
              alert('There was a problem with the request. Request returned ' + httpRequest.status);
        } catch (e) {
          alert('Caught Exception: ' + e);
  // Set the response handler
  httpRequest.onreadystatechange = getResponse;
  // Open the request'GET', requestURL);
  // Set headers
  httpRequest.setRequestHeader('Accept', 'application/json;pk=' + policyKey);
  // Open and send request