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

              
                
  <div class="audio-player">
    <div id="play-bouton"></div>
    <div class="audio-wrapper" id="player-container" href="javascript:;">
      <audio id="player" ontimeupdate="initProgressBar()">
			  <source src="http://www.lukeduncan.me/oslo.mp3" type="audio/mp3">
			</audio>
    </div>
    <div class="player-controls scrubber">
           <span id="seekObjContainer">
			  <progress id="seekObj" value="0" max="1"></progress>
			</span>
      <br>
      <small style="float: left; position: relative; left: 40px;" class="start-time"></small>
      <small style="float: right; position: relative; right: 45px;" class="end-time"></small>

    </div>
    
  </div>
              
            
!

CSS

              
                html {
  height: 100%;
  display: table;
  margin: auto;
}

body {
background:black
}


.audio-player {
  background: white;
  width: 60vw;
  text-align: center;
  display: flex;
  flex-flow: row;
  
  .player-controls {
    align-items: center;
    justify-content: center;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    flex: 3;
    progress {
      width: 90%;
    }
    progress[value] {
      -webkit-appearance: none;
      appearance: none;
      background-color: white;
      color: black;
      height: 12px;
    }
    progress[value]::-webkit-progress-bar {
      background-color: white;
      border:3px solid lighten(#000000, 0%);
      color: black;
    }
    progress::-webkit-progress-value {
      background-color:black;
    }
    p {
      font-size: 30px;
      font-family: "Elastik-B";
    }
    small.start-time{
      font-size: 30px;
      font-family: "Elastik-B", sans-serif;
      
    }
    small.end-time{
      font-size: 30px;
      font-family: "Elastik-B", sans-serif;
    }
  }
  
  
  #play-bouton {
    background-image: url('http://www.lukeduncan.me/images/play-button.png');
    background-size: cover;
    width: 40px;
    height: 40px;
    margin: 2rem 0 2rem 2rem;
    &.pause {
      background-image: url('http://www.lukeduncan.me/images/pause-button.png');
    }
  }
}
              
            
!

JS

              
                function calculateTotalValue(length) {
  var minutes = Math.floor(length / 60),
    seconds_int = length - minutes * 60,
    seconds_str = seconds_int.toString(),
    seconds = seconds_str.substr(0, 2),
    time = minutes + ':' + seconds

  return time;
}

function calculateCurrentValue(currentTime) {
  var current_hour = parseInt(currentTime / 3600) % 24,
    current_minute = parseInt(currentTime / 60) % 60,
    current_seconds_long = currentTime % 60,
    current_seconds = current_seconds_long.toFixed(),
    current_time = (current_minute < 10 ? "0" + current_minute : current_minute) + ":" + (current_seconds < 10 ? "0" + current_seconds : current_seconds);

  return current_time;
}

function initProgressBar() {
  var player = document.getElementById('player');
  var length = player.duration
  var current_time = player.currentTime;

  // calculate total length of value
  var totalLength = calculateTotalValue(length)
  jQuery(".end-time").html(totalLength);

  // calculate current value time
  var currentTime = calculateCurrentValue(current_time);
  jQuery(".start-time").html(currentTime);

  var progressbar = document.getElementById('seekObj');
  progressbar.value = (player.currentTime / player.duration);
  progressbar.addEventListener("click", seek);

  if (player.currentTime == player.duration) {
    $('#play-bouton').removeClass('pause');
  }

  function seek(evt) {
    var percent = evt.offsetX / this.offsetWidth;
    player.currentTime = percent * player.duration;
    progressbar.value = percent / 100;
  }
};

function initPlayers(num) {
  // pass num in if there are multiple audio players e.g 'player' + i

  for (var i = 0; i < num; i++) {
    (function() {

      // Variables
      // ----------------------------------------------------------
      // audio embed object
      var playerContainer = document.getElementById('player-container'),
        player = document.getElementById('player'),
        isPlaying = false,
        playBtn = document.getElementById('play-bouton');

      // Controls Listeners
      // ----------------------------------------------------------
      if (playBtn != null) {
        playBtn.addEventListener('click', function() {
          togglePlay()
        });
      }

      // Controls & Sounds Methods
      // ----------------------------------------------------------
      function togglePlay() {
        if (player.paused === false) {
          player.pause();
          isPlaying = false;
          $('#play-bouton').removeClass('pause');

        } else {
          player.play();
          $('#play-bouton').addClass('pause');
          isPlaying = true;
        }
      }
    }());
  }
}

initPlayers(jQuery('#player-container').length);
              
            
!
999px

Console