cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div id="outerWrap">
  <div id="wrapper">
    
    <label>Enter a soundcloud URL:</label>
    <input type="text" id="trackUrl" value="https://soundcloud.com/jinzo-the-trap-lord/shadow-realm-beat-cypher-volume-1"></input>
    <button id="playSoundcloud" onclick="playSoundcloud()">PLAY</button>
    <button id="stopSoundcloud" onclick="stopSoundcloud()">STOP</button>
<br><br>
    <div class="labelSpacer">
      <label>Artist:</label>
      <div id="artist"></div>
    </div>
    <br>
    <div class="labelSpacer">
      <label>Song:</label>
      <div id="song"></div>
    </div>
    <br>
    <div class="labelSpacer">
      <label>Description:</label>
      <div id="description"></div>
    </div>
    <canvas id="canvas2">
          </canvs>
      </div>
<div class="about">
      <div>
        kubrixXx is a <a href="https://www.soundcloud.com/kubrixxx" target="_blank">music producer</a> and web developer.
      </div>

    </div>
    </div>
    <canvas id="myCanvas">
    </canvas>

    
            
          
!
            
              /* --- General Styles --- */

@import url(https://fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic);
body {
  font-family: Roboto;
  font-weight: 300;
  -moz-user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  background: #fff;
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAy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5ExsmP9AxbDTc9JwgneAT5vTiUSm1E7BSflSt3bfa1tv8Di3R8n3Af7MNWzs49hmauE2wP+ttrq+AsWpFG2awvsuOqbipWHgtuvuaAE+A1Z/7gC9hesnr+7wqCwG8c5yAg3AL1fm8T9AZtp/bbJGwl1pNrE7RuOX7PeMRUERVaPpEs+yqeoSmuOlokqw49pgomjLeh7icHNlG19yjs6XXOMedYm5xH2YxpV2tc0Ro2jJfxC50ApuxGob7lMsxfTbeUv07TyYxpeLucEH1gNd4IKH2LAg5TdVhlCafZvpskfncCfx8pOhJzd76bJWeYFnFciwcYfubRc12Ip/ppIhA1/mSZ/RxjFDrJC5xifFjJpY2Xl5zXdguFqYyTR1zSp1Y9p+tktDYYSNflcxI0iyO4TPBdlRcpeqjK/piF5bklq77VSEaA+z8qmJTFzIWiitbnzR794USKBUaT0NTEsVjZqLaFVqJoPN9ODG70IPbfBHKK+/q/AWR0tJzYHRULOa4MP+W/HfGadZUbfw177G7j/OGbIs8TahLyynl4X4RinF793Oz+BU0saXtUHrVBFT/DnA3ctNPoGbs4hRIjTok8i+algT1lTHi4SxFvONKNrgQFAq2/gFnWMXgwffgYMJpiKYkmW3tTg3ZQ9Jq+f8XN+A5eeUKHWvJWJ2sgJ1Sop+wwhqFVijqWaJhwtD8MNlSBeWNNWTa5Z5kPZw5+LbVT99wqTdx29lMUH4OIG/D86ruKEauBjvH5xy6um/Sfj7ei6UUVk4AIl3MyD4MSSTOFgSwsH/QJWaQ5as7ZcmgBZkzjjU1UrQ74ci1gWBCSGHtuV1H2mhSnO3Wp/3fEV5a+4wz//6qy8JxjZsmxxy5+4w9CDNJY09T072iKG0EnOS0arEYgXqYnXcYHwjTtUNAcMelOd4xpkoqiTYICWFq0JSiPfPDQdnt+4/wuqcXY47QILbgAAAABJRU5ErkJggg==);
}

#outerWrap {
  margin: 0em auto;
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  bottom: 0;
  border:1px solid;
  display:block;
}

#wrapper {
  margin: 0 auto;
  margin-top:2em;
  padding: .5em;
  font-size: 1em;
  text-align: center;
  background: rgba(255, 255, 255, 1);
  border-radius: .2em;
  box-shadow: 0 .2em .4em 0 rgba(0, 0, 0, .5);
  width:30em;
}

*:focus {
  outline: none;
}

button {
  cursor: pointer;
  border: none;
  outline: none;
  background: #fff;
  color: #666;
  margin: .5em;
  font-weight: 500;
  font-size: .7em;
  padding: .5em;
  text-transform: uppercase;
  border-radius: .2em;
  opacity: .6;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  transition: all 0.3s cubic-bezier(.25, .8, .25, 1);
}

button:hover {
  background: #99ccff;
  color: #333;
  opacity: 1;
  box-shadow: 0 3px 3px rgba(0, 0, 0, 0.25), 0 6px 6px rgba(0, 0, 0, 0.22);
}

label {
  font-weight: 100;
}

#artist {
  display: inline;
  font-weight: 300;
}

#song {
  display: inline;
  font-weight: 300;
}

input {
  display: block;
  position: relative;
  margin: .5em auto;
  min-width: 30em;
  font-size: .5em;
  text-align: center;
}


/* SOUNDCLOUD */

#myCanvas {
  z-index: -1;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  image-rendering: crisp-edges;
  border-radius: .2em;
}

#canvas2 {
  width: 100%;
  height: 3em;
  margin-top: .5em;
}

.labelSpacer {
  position: relative;
  margin-top: .25em;
  margin-bottom: .25em;
}
.about{
   position:relative;
   opacity:.5;
   text-align:center;
   padding:1em;
   font-size:1em;
   display:block;
   font-style: italic;
}
.about img{
  width:6em;
  height:auto;
  margin:.5em;
}

a{
  color:#000 !important;
}
            
          
!
            
              var trackUrl;
var streamUrl;
var clientId = '1745017edcfeb72a175c95614a1cc212';
var songId;
var songTitle;
var songArtist;

SC.initialize({
  client_id: clientId
});

var audio = new Audio();
audio.crossOrigin = "anonymous";

var c = document.getElementById("myCanvas");
var canvasCtx = c.getContext("2d");
var c2 = document.getElementById("canvas2");
var canvasCtx2 = c2.getContext("2d");

var ctx = new AudioContext();
var audioSrc = ctx.createMediaElementSource(audio);
var analyser = ctx.createAnalyser();
analyser.fftSize = 1024;
var bufferLength = analyser.fftSize;
var dataArray = new Uint8Array(bufferLength);
analyser.getByteTimeDomainData(dataArray);
audioSrc.connect(analyser);
audioSrc.connect(ctx.destination);
var frequencyData = new Uint8Array(analyser.frequencyBinCount);

var analyser2 = ctx.createAnalyser();
analyser2.fftSize = 1024;
var bufferLength2 = analyser2.fftSize;
var dataArray2 = new Uint8Array(bufferLength2);
analyser2.getByteTimeDomainData(dataArray2);
audioSrc.connect(analyser2);
audioSrc.connect(ctx.destination);
var frequencyData2 = new Uint8Array(analyser2.frequencyBinCount);

function stopSoundcloud() {
  audio.pause();
  audio.currentTime = 0;
  stopDrawing = true;
  canvasCtx.canvas.width = canvasCtx.canvas.width
}

var fps = 60;
var now;
var then = Date.now();
var interval = 1000 / fps;
var delta;
var WIDTH = c.width;
var HEIGHT = c.height;
var joyInterval = 12;
var joyCount = 0;
var stopDrawing = false;

function playSoundcloud() {
  stopSoundcloud()
  stopDrawing = false;
  trackUrl = $("#trackUrl").val();
  $.get('https://api.soundcloud.com/resolve.json?url=' + trackUrl + '&client_id=' + clientId,
    function(result) {
      songId = result.id;
      songTitle = result.title;
      songArtist = result.user.username;
      songDescription = result.description;

      $('#artist').html(songArtist);
      $('#song').html(songTitle);
      $('#description').html(songDescription);

      streamUrl = result.stream_url;
      audio.src = streamUrl + "/?client_id=" + clientId;
      audio.play();
    }
  );

  function renderFrame() {
    requestAnimationFrame(renderFrame);
    // update data in frequencyData
    now = Date.now();
    delta = now - then;

    if (delta > interval && stopDrawing == false) {
      then = now - (delta % interval);
      if (joyCount < joyInterval) {
        // ... Code for Drawing the Frame ...

        // #1
        analyser.getByteFrequencyData(frequencyData);
        analyser.getByteTimeDomainData(dataArray);
        canvasCtx.strokeStyle = 'rgb(210, 210, 210)';
        canvasCtx.beginPath();

        var sliceWidth = WIDTH / bufferLength * 2;
        var x = 0;
        for (var i = 0; i < bufferLength; i++) {
          var v = dataArray[i] / 128;
          var y = (v * (HEIGHT) / 10);
          if (i === 0) {
            canvasCtx.moveTo(x, y);
          } else {
            canvasCtx.lineTo(x, y);
          }
          x += sliceWidth * 1;
        }
        canvasCtx.translate(0, 10);

        canvasCtx.lineWidth = 2;

        canvasCtx.lineTo(WIDTH, HEIGHT * 1.5);
        canvasCtx.stroke();
        canvasCtx.closePath();

        // #2
        analyser2.getByteFrequencyData(frequencyData2);
        analyser2.getByteTimeDomainData(dataArray2);

        canvasCtx2.strokeStyle = 'rgb(0, 0, 0)';
        canvasCtx2.canvas.width = canvasCtx2.canvas.width;
        canvasCtx2.beginPath();

        var sliceWidth = WIDTH / bufferLength * 2;
        var x = 0;
        for (var i = 0; i < bufferLength; i++) {
          var v = dataArray[i] / 128;
          var y = (v * (HEIGHT) / 2);
          if (i === 0) {
            canvasCtx2.moveTo(x, y);
          } else {
            canvasCtx2.lineTo(x, y);
          }
          x += sliceWidth * 1;
        }
        canvasCtx2.lineWidth = 5;

        canvasCtx2.lineTo(WIDTH, HEIGHT * 1.5);
        canvasCtx2.stroke();
        canvasCtx2.closePath();

        joyCount++;
      } else {
        canvasCtx.canvas.width = canvasCtx.canvas.width
        joyCount = 0;
      }
    }
    // render frame based on values in frequencyData
    //console.log(frequencyData)
  }
  renderFrame();
  WIDTH = c.width;
  HEIGHT = c.height;
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console