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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <header id="title">
  <h1><i class="ion-ios7-musical-notes"></i> SoundCloud Player</h1>
  <p>Mini player with css record animation, using SoundCloup API.<br />
  (hover to see band & track name, and controls)</p><br />
  REACT version <a href="https://codepen.io/SebL/details/ZQdbZY/">HERE</a>
</header>

<div id="player" class="closed">
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/154694/vinyl.png" alt=""  id="record"/>
  <div id="cover">
    <img src="http://placekitten.com/g/250/250" width="250" height="250" alt="" id="artwork" />
    <div id="trackInfos">
      <p class="now">NOW PLAYING</p>
      <p id="band"></p>
      <p id="track"></p>
      
      <a href="#" id="play" class="ion-ios7-play"></a>
    </div>
  </div>
</div>

































<p class="streamew">
  This is a technic I used for this project:
<a href="https://www.youtube.com/watch?v=p6kfbVDMI-4">STREAMew</a>
</p>

              
            
!

CSS

              
                @import "compass/css3";

html, body{
  height: 100%;
}
body{
  background-image: radial-gradient(ellipse at top, white, #bdc3c7 80%);
  font-family: 'Open Sans', sans-serif;
}

#player{
  transition: all 500ms ease;
  position: relative;
  margin: 0 auto;
  height: 250px;
  
  #cover{
    position: absolute;
    left:0;
    top:0;
    overflow: hidden;
    box-shadow: 0px 0px 30px 0px rgba(black, 0.5);

    &:after{
      content:' ';
      position: absolute;
      top: 0;
      left: 0;
      width: 80%;
      height: 50%;
      background-image: linear-gradient(-180deg, rgba(white, 0.5), transparent 90%);
      transform: skewX(-45deg);
      transform-origin: top left;
    }
    img{
      display: block; // remove unwanted space on the bottom of the image
    }
  } 
  #record{
    border-radius: 50%;
    position: absolute;
    top: 0;
    right: 0;
    width: 250px;
    height: 250px;
    box-shadow: 0px 0px 5px 0px rgba(black, 0.5);
  }
  #trackInfos{
    transition: all 500ms ease;
    box-sizing: border-box;
    position: absolute;
    z-index: 1;
    top: 0 ;
    left:0;
    width: 100%;
    height: 100%;
    padding: 1rem;
    background-color: rgba(black, 0.8);
    color: white;
    opacity: 0;
    
    &:hover{
      opacity: 1;  
    }
    
    .now{
      font-size: 0.8rem;
      color: #7f8c8d;
      margin-bottom: 0.5rem;
    }
    #band{
      text-transform: uppercase;
    }
    #track{
      font-weight: 300;
      color: #bdc3c7;
    }
    #play{
      position: absolute;
      top: calc(50% - 2.5rem);
      left: 0;
      display: block;
      width: 100%;
      height: 5rem;
      line-height: 5rem;
      text-align: center;
      font-size: 5rem;
      color: rgba(white, 0.5);
    }
  }
}
.closed{
  width: 250px;
}
.open{
  width: 350px;
}
.spinning{
  @include animation(turntable 4s linear infinite);
}



@keyframes turntable {
  0%{ transform: rotateZ(0); }
  100%{ transform: rotateZ(360deg); }
}
@-webkit-keyframes turntable {
  0%{ transform: rotateZ(0); }
  100%{ transform: rotateZ(360deg); }
}
@-moz-keyframes turntable {
  0%{ transform: rotateZ(0); }
  100%{ transform: rotateZ(360deg); }
}
@-o-keyframes turntable {
  0%{ transform: rotateZ(0); }
  100%{ transform: rotateZ(360deg); }
}








.streamew{
  text-align: center;
  margin-top: 5rem;
  color: #7f8c8d;
  
  a{
    color: #3498db;
    text-decoration: none;
  }
}
              
            
!

JS

              
                // settings
var clientId = '853fdb79a14a9ed748ec9fe482e859dd';
var trackId = '120912535';

// DOM elements
var artwork = $("#artwork");
var band = $('#band');
var song = $('#track');


// Init SoundCloud JS SDK (dont forget to include the .js SDK)
SC.initialize({
    client_id: clientId
});

// Getting SC track infos
SC.get('/tracks/'+trackId, function(track){
  
  // Injecting infos
  artwork.attr('src', track.artwork_url.replace('-large', '-crop')); // Cover (replacing the default image size "large" with "crop")
  band.html(track.user.username); // Band Name
  song.html(track.title); // Song name
  
  // Play btn
  var status = false; // play status
  
  $('#play').click(function(e){
    e.preventDefault();
    
    if(status == false){
      
      $('#player').addClass('open'); // Opening the player
      $('#record').addClass('spinning'); // vinyl now spinning
      $(this).removeClass('ion-ios7-play').addClass('ion-ios7-pause'); // change play btn to pause btn
      
      audioPlayer = new Audio(track.uri + '/stream?client_id=' + clientId); // Create audio object with stream url...
      audioPlayer.play(); // ...and play
      
      status = !status; // invert player status  
    } 
    else {
      
      $('#player').removeClass('open'); // Closing the player
      $('#record').removeClass('spinning'); // vinyl stopped spinning
      $(this).removeClass('ion-ios7-pause').addClass('ion-ios7-play'); // change pause btn to play btn
      
      audioPlayer.pause(); // Pause the player
      status = !status; // invert status
    }

    
  });
  
});
              
            
!
999px

Console