cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <audio id="music" preload="true">
  <source src="https://s3-us-west-2.amazonaws.com/mortycodepen/Codepen/mechanical+marvel.mp3">
	</audio>

<div class="main">
  <div id="draggable" class="ui-widget-content">

    <div id="musicCont" class="flex-container settle">
      <div id="handle">
        <ul>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
        </ul>
      </div>
      <div id="artistNameAlbum">
        <p>Mogwai | Kappa</p>
      </div>
      <div id="albumCont" class="flex-item album flex-container">
        <img id="currentAlbum" class="flex-item" src="http://cache.swdlive.com/image/test/resize_1375300602.jpg">
      </div>
      <div id="audioplayer">


        <svg id="playButton" class="button" onclick="play()" x="0px" y="0px" width="4.5px" height="6.9px" viewBox="0 0 4.5 6.9" style="enable-background:new 0 0 4.5 6.9;">
  <polyline class="button" points="0.6,0.3 3.9,3.4 0.6,6.6 "/>
  </svg>


        <svg id="pauseButton" class="button" onclick="pause()" x="0px" y="0px" width="4.5px" height="6.9px" viewBox="0 0 4.5 6.9" style="enable-background:new 0 0 4.5 6.9;">
    <g>
      <line class="st0" x1="0.4" y1="0.1" x2="0.4" y2="6.8"/>
      <line class="st0" x1="4.1" y1="0.1" x2="4.1" y2="6.8"/>
    </g>
  </svg>
        <div id="timeline">
          <div id="playhead"></div>
        </div>
      </div>
    </div>
    <div id="sliderCont" class="flex-item">
      <div id="slider">
        <span></span>
      </div>
    </div>
  </div>
</div>

<div class="bgText">
  <h1>Music Player is operational. 
  <br>You can drag the player with the dots on click.<br>
  Have fun!</h1>
</div>
            
          
!
            
              html {
  background-color: #272733;
}

.main {
  margin-left: 60%;
  margin-top: 2%;
}

.album {
  margin-bottom: 25px;
}

#musicCont {
  background-color: #044154;
  position: absolute;
  z-index: 1;
  width: 400px;
  box-shadow: 0px 5px 5px 5px rgba(0, 0, 0, 0.2);
  border-bottom: 4px solid #3594BA;
}

.lift {
  animation: lift 350ms forwards;
}

@keyframes lift {
  0% {
    box-shadow: 0px 5px 5px 5px rgba(0, 0, 0, 0.2);
    transform: scale(1);
    transform: rotate(0deg);
  }
  100% {
    box-shadow: 0px 25px 5px 9px rgba(0, 0, 0, 0.1);
    transform: scale(1.03);
    transform: rotate(.5deg);
  }
}

.settle {
  animation: settle 200ms forwards;
}

@keyframes settle {
  0% {
    box-shadow: 0px 25px 5px 9px rgba(0, 0, 0, 0.1);
    transform: scale(1.03);
    transform: rotate(.5deg);
  }
  100% {
    box-shadow: 0px 5px 5px 5px rgba(0, 0, 0, 0.2);
    transform: scale(1);
    transform: rotate(0deg);
  }
}

.flex-container {
  list-style: none;
  display: flex;
  -webkit-flex-flow: row wrap;
  justify-content: space-around;
}

.flex-item {
  padding-bottom: 20px;
  width: 300px;
  height: 300px;
  margin-top: 30px;
  text-align: center;
}

#audioplayer {
  width: 300px;
  height: 60px;
}

.button {
  height: 35px;
  width: 35px;
  border: none;
  background-size: 50% 50%;
  background-repeat: no-repeat;
  background-position: center;
  float: left;
  outline: none;
}

#timeline {
  width: 240px;
  height: 2px;
  margin-right: 10px;
  margin-top: 20px;
  float: right;
  border-radius: 15px;
  background: #DBE3E3;
}

#playhead {
  width: 4px;
  height: 10px;
  margin-top: -4px;
  background: #fff;
  cursor: pointer;
}

#playButton,
#pauseButton {
  width: 10px;
  margin-top: 4px;
  margin-left: 10px;
  fill: none;
  stroke: #ffffff;
  stroke-width: 0.5;
  stroke-miterlimit: 10;
  cursor: pointer;
}

.button:hover {
  animation: bounce 500ms alternate;
}

@keyframes bounce {
  0% {
    transform: scale(1);
  }
  100% {
    transform: scale(1.2);
  }
}

#artistNameAlbum {
  display: inline-block;
  position: absolute;
  left: 140px;
  padding: 10px;
  color: white;
  font-family: Helvetica;
  font-weight: 300;
  font-size: 14px;
  margin-top: 0px;
  margin-bottom: 0px;
}

.ui-widget-content {
  width: 400px;
  height: 400px;
  border: none;
  background-color: rgba(0, 0, 0, 0);
}

#handle {
  position: absolute;
  display: inline-block;
  cursor: all-scroll;
  left: 190px;
  top: 415px;
  margin: 0px;
  padding: 0px;
}

li {
  list-style: none;
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 6px;
  background-color: #1D6B87;
}

ul {
  margin: 0px;
  padding: 0px;
}

h1{
  position: relative;
  top: -438px;
  left: 15%;
  font-family: Helvetica;
  color: rgba(29, 107, 135, .2)
}

.bgText{
  width: 54%;
  z-index: -2;
  font-size: 22px;
}
            
          
!
            
              var music = document.getElementById('music');
var duration;
var playButton = document.getElementById('playButton');
var pauseButton = document.getElementById('pauseButton');
var playhead = document.getElementById('playhead');
var timeline = document.getElementById('timeline');
var timelineWidth = timeline.offsetWidth - playhead.offsetWidth;

music.addEventListener("timeupdate", timeUpdate, false);

timeline.addEventListener("click", function(event) {
  moveplayhead(event);
  music.currentTime = duration * clickPercent(event);
}, false);

function clickPercent(e) {
  console.log(e);
  return (e.pageX - timeline.offsetLeft) / timelineWidth;
}

playhead.addEventListener('mousedown', mouseDown, false);
window.addEventListener('mouseup', mouseUp, false);

var onplayhead = false;

function mouseDown() {
  onplayhead = true;
  window.addEventListener('mousemove', moveplayhead, true);
  music.removeEventListener('timeupdate', timeUpdate, false);
}

function mouseUp(e) {
  if (onplayhead == true) {
    moveplayhead(e);
    window.removeEventListener('mousemove', moveplayhead, true);
    music.currentTime = duration * clickPercent(e);
    music.addEventListener('timeupdate', timeUpdate, false);
  }
  onplayhead = false;
}

function moveplayhead(e) {
  var newMargLeft = e.pageX - timeline.offsetLeft;
  if (newMargLeft >= 0 && newMargLeft <= timelineWidth) {
    playhead.style.marginLeft = newMargLeft + "px";
  }
  if (newMargLeft < 0) {
    playhead.style.marginLeft = "0px";
  }
  if (newMargLeft > timelineWidth) {
    playhead.style.marginLeft = timelineWidth + "px";
  }
}

function timeUpdate() {
  var playPercent = timelineWidth * (music.currentTime / duration);
  playhead.style.marginLeft = playPercent + "px";
}

function play() {
  if (music.paused) {
    music.play();
  }
}

function pause() {
  if (music.play) {
    music.pause();
  }
}

music.addEventListener("canplaythrough", function() {
  duration = music.duration;
}, false);

$("#draggable").draggable({
  handle: "#handle"
});

$(function() {
  $("#draggable").draggable();
});

$("#handle").mousedown(function() {
  $("#musicCont").removeClass("settle");
  $("#musicCont").addClass("lift");
});

$("#handle").mouseup(function() {
  $("#musicCont").removeClass("lift");
  $("#musicCont").addClass("settle");
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console