Pen Settings

HTML

CSS

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

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

Auto Save

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="inputDiv">
<p>
  <button id="boton">&#9655;</button>
</p>

<p>Izquierda:<br><input id="inputIzq" type="range" min="-1" max="1" step="0.01" value="0"  /></p>
<p>Derecha:<br><input id="inputDcha" type="range" min="-1" max="1" step="0.01" value="0" /></p>

</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body{background:#333; height:100vh;}
p{color:#777; text-align:center;line-height:250%; }

.inputDiv {
  width: 250px;
  margin: 1em auto;
  position: relative;
}

input[type='range'] {
  display: block;
  width: 250px;
  margin:.5em;
}

input[type='range']:focus {
  outline: none;
}

input[type='range'],
input[type='range']::-webkit-slider-runnable-track,
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
}

input[type=range]::-webkit-slider-thumb {
  background-color: #777;
  width: 20px;
  height: 20px;
  border: 3px solid #333;
  border-radius: 50%;
  margin-top: -9px;
}

input[type=range]::-moz-range-thumb {
  background-color: #777;
  width: 15px;
  height: 15px;
  border: 3px solid #333;
  border-radius: 50%;
}

input[type=range]::-ms-thumb {
  background-color: #777;
  width: 20px;
  height: 20px;
  border: 3px solid #333;
  border-radius: 50%;
}

input[type=range]::-webkit-slider-runnable-track {
  background-color: #777;
  height: 3px;
}

input[type=range]:focus::-webkit-slider-runnable-track {
  outline: none;
}

input[type=range]::-moz-range-track {
  background-color: #777;
  height: 3px;
}

input[type=range]::-ms-track {
  background-color: #777;
  height: 3px;
}

input[type=range]::-ms-fill-lower {
  background-color: HotPink
}

input[type=range]::-ms-fill-upper {
  background-color: black;
} 

button{background:#777; padding:.5em 1em; color:white; border-radius:.2em}

              
            
!

JS

              
                var audioContext = new (window.AudioContext || window.webkitAudioContext)();

// variables globales
var audioBuffer,
  fuenteDeReproduccion;
var splitter = audioContext.createChannelSplitter(2);
var gainIzq = audioContext.createGain();
var gainDcha = audioContext.createGain();
var pannerIzq = audioContext.createStereoPanner();
var pannerDcha = audioContext.createStereoPanner();


function solicitarAudio(url) {
  var request = new XMLHttpRequest();
  request.open("GET", url, true);
  request.responseType = "arraybuffer";
  request.onload = function() {
    audioContext.decodeAudioData(request.response, function(buffer) {
      audioBuffer = buffer;
    });
  };
  request.send();
}

function reproducirAudio() {
 // fuenteDeReproduccion --> splitter --> gainIzq  --> pannerIzq  --> destination
 //                                    ↳ gainDcha --> pannerDcha --> destination

  fuenteDeReproduccion = audioContext.createBufferSource();
  fuenteDeReproduccion.loop = true;
  fuenteDeReproduccion.buffer = audioBuffer;
  
  fuenteDeReproduccion.connect(splitter);
  
  splitter.connect(gainIzq, 0);
  splitter.connect(gainDcha, 1);
  
  gainIzq.connect(pannerIzq);
  //gainIzq.gain.value = inputIzq.value;
  
  gainDcha.connect(pannerDcha); 
  //gainDcha.gain.value = inputDcha.value;

  
  pannerIzq.connect(audioContext.destination);
  pannerIzq.pan.value = -1;
  
  pannerDcha.connect(audioContext.destination);
  pannerDcha.pan.value = 1;
  fuenteDeReproduccion.connect(audioContext.destination);
  fuenteDeReproduccion.start(audioContext.currentTime);
}

function detenerAudio() {
  fuenteDeReproduccion.stop();
}

function audio(){
  if (stop) {// si el audio está parado
    start = true;
    stop = false;
    boton.innerHTML = "||";//detener
    reproducirAudio();
  }else{// de lo contrario
    stop = true;
    start = false;
    boton.innerHTML = "&#9655;";//reproducir
    detenerAudio()
  }
}

solicitarAudio(
  "https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/Kevin_MacLeod_-_Camille_Saint-Sans_Danse_Macabre_-_Finale.mp3"
);



// Utiliza el evento click para iniciar o detener la reproducción
boton.addEventListener("click", audio, false);

inputIzq.addEventListener("input", function() {
  gainIzq.gain.value = this.value;
});

inputDcha.addEventListener("input", function() {
  gainDcha.gain.value = this.value;
});

              
            
!
999px

Console