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

              
                <h2>Fully customized audio player</h2>
<p>This demo involves more CSS than usual to achieve the desired results, but shows the flexibility of OpenPlayerJS to place elements properly and modify the regular DOM.</p> 
<div class="audio-player">
  <img class="cover">
  <audio class="op-player__media" id="audio" controls playsinline src="https://db2.indexcom.com/bucket/ram/00/05/64k/05.m3u8"></audio>
</div>
<br>
<div class="audio-player live">
  <img class="cover" src="https://ctl.s6img.com/society6/img/7eMZqEa9RHkjy7he9uiOWoCCMeU/w_700/posters/18x24/front/~artwork,fw_2718,fh_3618,fx_-450,iw_3618,ih_3618/s6-original-art-uploads/society6/uploads/misc/20010436db00425db80e923d85c57278/~~/urban-vinyl-of-underground-music-posters.jpg?wait=0&attempt=0" alt="Radio">
  <audio class="op-player__media" id="audio-live" controls>
    <source src="https://hlsyoufm.akamaized.net/hls/live/2016538/youfm/master.m3u8">
</audio>
</div>
<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>
              
            
!

CSS

              
                            .audio-player {
  background: #4c4e5a; 
  background: linear-gradient(top, #4c4e5a 0%, #2c2d33 100%);
  max-width: 650px;
  position: relative;
}
.audio-player > img {
  position: absolute;
  width: 70px;
  background: #000;
  height: 70px;
  border: none;
}
.op-player {
  height: 70px;
  background: transparent;
  margin-left: 70px;
}
.op-controls {
  flex-direction: column;
  background: transparent;
  padding: 0;
}
.op-controls__volume {
  width: calc(60% - 40px);
  height: 12px;
}
.op-controls__progress {
  margin-left: 0;
}
.op-controls__tooltip {
  z-index: 10;
}
.op-controls input[type=range]::-webkit-slider-thumb {
  background: #aaa;
}
.op-controls .op-controls__progress--played, .op-controls .op-controls__volume--display {
  color: #64b44c;
}

.op-controls .op-controls__volume--display {
  box-shadow: inset 0px 1px 0px rgba(0,0,0, .3), 0px 1px 0px rgba(255,255,255, .25);  
}

.audio-player.live .op-player {
  margin-left: 0;
}
.audio-player.live .op-controls-layer__top, .audio-player.live .op-controls-layer__center {
  margin-left: 70px;
}

.audio-player.live > img {
  height: 65px;
}
              
            
!

JS

              
                // Custom method to parse information from HLS streaming
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 imageTag = audio.closest('.audio-player').querySelector('.cover');
  imageTag.src = image;
  imageTag.setAttribute('alt', `${title}, by ${artist}`);
}

const player = new OpenPlayerJS('audio', {
   hls: {
    startLevel: -1
  },
  controls: {
    layers: {
      'top-left': ['play', 'time'],
      'left': ['volume'],
      'bottom-middle': ['progress'],
    }
  }
});
player.init();

player.getElement().addEventListener('hlsFragParsingMetadata', event => {
  const parsedTag = [];
  event.detail.samples[0].data.forEach(element => {
      parsedTag.push(String.fromCharCode(element));
  });
  extractMeta(parsedTag.toString().replace(/,/g, ''), player.getElement());
});

const player2 = new OpenPlayerJS('audio-live', {
   hls: {
    startLevel: -1
  },
  controls: {
    layers: {
      'top-left': ['play', 'time'],
      'left': ['volume'],
      'bottom-middle': ['progress'],
    }
  }
});
player2.init();
              
            
!
999px

Console