Pen Settings

HTML

CSS

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

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

              
                <h1>Basic playlist</h1>
<p>Just select any of the options in the dropdown and see how the player changes the source</p>
<p>Works for both video and audio!</p>

<p>If you like this Pen, please show your support to this project by giving it a star by clicking in the icon below.</p>
<a class="github-button" href="https://github.com/openplayerjs/openplayerjs" data-size="large" data-show-count="true" aria-label="Star openplayerjs/openplayerjs on GitHub">Star</a>

<div class="players video-player">
  <video class="op-player__media" id="video" controls playsinline>
    <source src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/TearsOfSteel.mp4" type="video/mp4"></video>
  <div>
  <select name="sources">
    <option value="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/TearsOfSteel.mp4" selected>MP4</option>
    <option value="https://upload.wikimedia.org/wikipedia/commons/2/22/Volcano_Lava_Sample.webm">WebM</option>
    <option value="https://player.webvideocore.net/CL1olYogIrDWvwqiIKK7eLBkzvO18gwo9ERMzsyXzwt_t-ya8ygf2kQBZww38JJT/8i4vvznv8408.m3u8">HLS</option>
    <option value="https://dash.akamaized.net/envivio/EnvivioDash3/manifest.mpd">M(PEG)-DASH</option>
    </select>
  </div>
</div>
<br>
<p><strong>Note:</strong> For the live HLS audio, it requires a custom method to parse the content and display the data associated</p>
<div class="players audio-player">
  <div id="stream-info" class="hidden"></div>
  <audio class="op-player__media" id="audio" controls>
    <source src="https://ccrma.stanford.edu/~jos/mp3/Latin.mp3" type="audio/mp3">
  </audio>
  <div>
  <select name="sources">
    <option value="https://ccrma.stanford.edu/~jos/mp3/Latin.mp3" selected>MP3</option>
    <option value="https://db2.indexcom.com/bucket/ram/00/05/05.m3u8">HLS</option>
  </select>
  </div>
</div>
              
            
!

CSS

              
                select {
  margin-top: 20px;
}
select:last-child {
  margin-bottom: 20px;
}
#stream-info {
  min-height: 300px;
}
#stream-info.hidden {
  min-height: 0;
}
#stream-info > img {
  float: left;
  width: 300px;
}
#stream-info > p {
  margin-left: 315px;
}
.op-controls__test > img {
  max-height: 18px;
}
              
            
!

JS

              
                function loadMedia(e) {
  const id = e.target.closest('.players').querySelector('.op-player').id;
  const player = OpenPlayerJS.instances[id];
  player.src = this.value.replace('&amp;', '&');
  player.load();
  
  setTimeout(() => {
    player.play()
  }, 250);
}

function extractMeta(data, audio) {
  let startLoc;
  let endLoc;

  // name
  startLoc = data.indexOf("TRSN") + 11;
  endLoc = data.indexOf("TRSO");
  const name = data.substring(startLoc, endLoc);

  // desc
  startLoc = data.indexOf("TRSO") + 11;
  endLoc = data.indexOf("TIT2");
  const desc = data.substring(startLoc, endLoc);

  // artist
  startLoc = data.indexOf("TPE1") + 11;
  endLoc = data.indexOf("TPE2");
  const artist = data.substring(startLoc, endLoc);

  // title
  startLoc = data.indexOf("TIT2") + 11;
  endLoc = data.indexOf("TPE1");
  const title = data.substring(startLoc, endLoc);

  // image
  const image = data.match('(http:\/\/|https:\/\/).*\.(jpg|png|svg)')[0];
  const infoArea = document.getElementById('stream-info');

  infoArea.innerHTML = `
    <img src="${image}" alt="${title}, by ${artist}" width="300" />
    <p>Name: ${name}</p>
    <p>Desc: ${desc}</p>
    <p>Artist: ${artist}</p>
    <p>Title: ${title}</p>
  `;
  infoArea.classList.remove('hidden');
  audio.poster = image;
}

document.querySelectorAll('select[name=sources]').forEach(source => {
  source.addEventListener('change', loadMedia);
});

document.querySelectorAll('.op-player__media').forEach((player, i) => {
  const p = new OpenPlayerJS(player.id, {
    hls: {
      startLevel: -1
    }
  });
  p.init();
  
  if (i === 1) {
    p.getElement().addEventListener('hlsFragParsingMetadata', event => {
        const parsedTag = [];
        event.detail.samples[0].data.forEach(element => {
            parsedTag.push(String.fromCharCode(element));
        });
        extractMeta(parsedTag.toString().replace(/,/g, ''), p.getElement());
    });
  }
});

              
            
!
999px

Console