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="Player" id="player">
  <audio src="http://webplusdevelopers.com/demo/media/legacy.mp3" 
         v-el:audio></audio>
  
  <div class="Player__cover" @click="hideText">
    <div class="Player__lyrics">
      <div class="line"
           v-if="lyrics.show" 
           v-text="lyrics.currentLine"></div>
    </div>
  </div>
  
  <div class="Player__track"
       :style="{ width: song.progress + '%' }"></div>
  
  <div class="Player__details">
    <div class="title" 
         v-text="song.title + ' - ' + song.artist"></div>
  </div>
  
  <div class="Player__controls">
    <i class="disabled icon previous material-icons">skip_previous</i>
    <i class="icon play material-icons" 
       v-text="playing ? 'pause_circle_filled' : 'play_circle_filled'"
       @click="togglePlayback"></i>
    <i class="disabled icon next material-icons">skip_next</i>
  </div>
</div>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Roboto:400,300);
$primary = #F44336;

* {
  box-sizing: border-box;
}

body, html  {
  padding: 0;
  margin: 0;
  height: 100%;
  font-family: Roboto, sans-serif;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

.Player {
  width: 300px;
  height: 425px;
  box-shadow: 0 0 5px #BBB;
}

.Player__cover {
  width: 300px;
  height: 300px;
  background-image: url('https://upload.wikimedia.org/wikipedia/en/8/87/The_Marshall_Mathers_LP_2.png');
}

.Player__lyrics {
  height: 100%;
  width: 100%;
  display: flex;
  
  justify-content: center;
  align-items: flex-end;
  
  .line {
    display: flex;
    margin-bottom: 20px;
    width: 90%;
    color: #FFF;
    background-color: rgba(0, 0, 0, 0.6);
    border-radius: 3px;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 16px;
    
    justify-content: center;
    flex-direction: column;
    text-align: center;
  }
}

.Player__track {
  width: 0%;
  height: 3px;
  background-color: $primary;
}

.Player__details {
  padding: 12px 20px;
  
  .title {
    text-align: center;
    font-size: 20px;
  }
}

.Player__controls {
  display: flex;
  width: 100%;
  margin-top: 3px;
  
  justify-content: center;
  align-items: center;
  
  .icon {
    cursor: pointer;
    font-size: 36px;
    -webkit-user-select: none;
    
    &.disabled {
      color: #AAA;
      cursor: default;
    }
   
    &.play {
        margin-left: 10px;
        margin-right: 10px;
        
        font-size: 54px;
        color: $primary;
    }
  }
}

              
            
!

JS

              
                var lyricsText = [
  {
    "text": "[Intro: Polina]",
    "timeIn": "00:00.00",
    "duration": 460
}, {
    "text": "Tell me where to go, tell me what to do, I'll be right there for you",
    "timeIn": "00:00.46",
    "duration": 5500
}, {
    "text": "Tell me what to say, no matter if it's true, I'll say it all for you",
    "timeIn": "00:05.96",
    "duration": 6940
}, {
    "text": "[Verse 1: Eminem]",
    "timeIn": "00:12.90",
    "duration": 1380
}, {
    "text": "I used to be the type of kid that would always think the sky is fallin'",
    "timeIn": "00:14.28",
    "duration": 3700
}, {
    "text": "Why am I so differently wired? Am I a martian?",
    "timeIn": "00:17.98",
    "duration": 2960
}, {
    "text": "What kind of twisted experiment am I involved in?",
    "timeIn": "00:20.94",
    "duration": 2880
}, {
    "text": "Cause I don't belong in this world",
    "timeIn": "00:23.82",
    "duration": 1870
}, {
    "text": "That's why I'm scoffin' at authority",
    "timeIn": "00:25.69",
    "duration": 1470
}, {
    "text": "Defiant often flyin' off at the handle at my mom, no dad",
    "timeIn": "00:27.16",
    "duration": 3300
}, {
    "text": "So I am noncompliant at home, at school, I'm just shy and awkward",
    "timeIn": "00:30.46",
    "duration": 4920
}, {
    "text": "And I don't need no goddamn psychologist",
    "timeIn": "00:35.38",
    "duration": 2380
}, {
    "text": "Trying to diagnose why I have all these underlying problems",
    "timeIn": "00:37.76",
    "duration": 3340
}, {
    "text": "Thinking he can try and solve 'em",
    "timeIn": "00:41.10",
    "duration": 1520
}, {
    "text": "I'm outside chalking up drawings on the sidewalk and in the front drive",
    "timeIn": "00:42.62",
    "duration": 3830
}, {
    "text": "Talking to myself, either that or inside hiding off in",
    "timeIn": "00:46.45",
    "duration": 3510
}, {
    "text": "The corner somewhere quiet, trying not to be noticed",
    "timeIn": "00:49.96",
    "duration": 3460
}, {
    "text": "Cause I'm crying and sobbin'",
    "timeIn": "00:53.42",
    "duration": 1960
}, {
    "text": "I had a bad day at school so I ain't talkin'",
    "timeIn": "00:55.38",
    "duration": 1860
}, {
    "text": "Some cocksucker shoved me into a fucking locker",
    "timeIn": "00:57.24",
    "duration": 2660
}, {
    "text": "Cause he said that I eye-balled him",
    "timeIn": "00:59.90",
    "duration": 1990
}, {
    "text": "[Pre-Hook: Polina]",
    "timeIn": "01:01.89",
    "duration": 420
}, {
    "text": "And if you fall, I'll catch you there",
    "timeIn": "01:02.31",
    "duration": 4730
}, {
    "text": "I'll be your savior from all the wars",
    "timeIn": "01:07.04",
    "duration": 6000
}, {
    "text": "That are fought inside your world",
    "timeIn": "01:13.04",
    "duration": 4240
}, {
    "text": "Please have faith in my words",
    "timeIn": "01:17.28",
    "duration": 4070
}, {
    "text": "[Hook: Polina]",
    "timeIn": "01:21.35",
    "duration": 1790
}, {
    "text": "Cause this is my legacy, legacy, yeah",
    "timeIn": "01:23.14",
    "duration": 6220
}, {
    "text": "This is my legacy, legacy, yeah",
    "timeIn": "01:29.36",
    "duration": 5840
}, {
    "text": "There's no guarantee, it's not up to me, we can only see",
    "timeIn": "01:35.20",
    "duration": 6210
}, {
    "text": "This is my legacy, legacy, legacy, legacy",
    "timeIn": "01:41.41",
    "duration": 5540
}, {
    "text": "[Verse 2]",
    "timeIn": "01:46.95",
    "duration": 1040
}, {
    "text": "I used to be the type of kid that would always think the sky is fallin'",
    "timeIn": "01:47.99",
    "duration": 3380
}, {
    "text": "Why am I so differently wired in my noggin?",
    "timeIn": "01:51.37",
    "duration": 3020
}, {
    "text": "Cause sporadic as my thoughts come, it's mind-bogglin'",
    "timeIn": "01:54.39",
    "duration": 2680
}, {
    "text": "Cause I obsess on everything in my mind",
    "timeIn": "01:57.07",
    "duration": 2630
}, {
    "text": "Small shit bothers me, but not my father",
    "timeIn": "01:59.70",
    "duration": 3190
}, {
    "text": "He said sayonara then split but I don’t give a shit",
    "timeIn": "02:02.89",
    "duration": 1870
}, {
    "text": "I'm fine long as there's batteries in my Walkman",
    "timeIn": "02:04.76",
    "duration": 3100
}, {
    "text": "Nothing is the matter with me",
    "timeIn": "02:07.86",
    "duration": 1330
}, {
    "text": "Shit look on the bright side at least I ain't walkin'",
    "timeIn": "02:09.19",
    "duration": 2570
}, {
    "text": "I bike ride through the neighborhood of my apartment",
    "timeIn": "02:11.76",
    "duration": 2790
}, {
    "text": "Complex on a ten-speed which I've acquired parts that",
    "timeIn": "02:14.55",
    "duration": 2960
}, {
    "text": "I find in the garbage, a frame then put tires on it",
    "timeIn": "02:17.51",
    "duration": 2960
}, {
    "text": "Headphones on, look straight ahead if kids try and start shit",
    "timeIn": "02:20.47",
    "duration": 2980
}, {
    "text": "But if this is all there is for me, life offers",
    "timeIn": "02:23.45",
    "duration": 2100
}, {
    "text": "Why bother even trying to put up a fight? It's nonsense",
    "timeIn": "02:25.55",
    "duration": 3730
}, {
    "text": "But I think a light bulb just lit up in my conscience",
    "timeIn": "02:29.28",
    "duration": 2970
}, {
    "text": "What about them rhymes I've been jottin'",
    "timeIn": "02:32.25",
    "duration": 2120
}, {
    "text": "They are kind of giving me confidence",
    "timeIn": "02:34.37",
    "duration": 1280
}, {
    "text": "Instead of trying to escape through my comics",
    "timeIn": "02:35.65",
    "duration": 2380
}, {
    "text": "Why don't I just blast a little something, like Onyx",
    "timeIn": "02:38.03",
    "duration": 2980
}, {
    "text": "To put me in the mood to wanna fight and write songs that",
    "timeIn": "02:41.01",
    "duration": 2900
}, {
    "text": "Say what I want to say to the kid that said that I eyeballed him",
    "timeIn": "02:43.91",
    "duration": 2980
}, {
    "text": "Grab hold of my balls like that's right, fight's on bitch",
    "timeIn": "02:46.89",
    "duration": 2930
}, {
    "text": "Who woulda knew from the moment I turned the mic on that",
    "timeIn": "02:49.82",
    "duration": 2870
}, {
    "text": "I could be iconic, in my conquest",
    "timeIn": "02:52.69",
    "duration": 2680
}, {
    "text": "That's word to Phife Dawg from a Tribe Called Quest",
    "timeIn": "02:55.37",
    "duration": 2160
}, {
    "text": "[Hook: Polina]",
    "timeIn": "02:57.53",
    "duration": 500
}, {
    "text": "Cause this is my legacy, legacy, yeah",
    "timeIn": "02:58.03",
    "duration": 5620
}, {
    "text": "This is my legacy, legacy, yeah",
    "timeIn": "03:03.65",
    "duration": 5370
}, {
    "text": "There's no guarantee, it's not up to me, we can only see",
    "timeIn": "03:09.02",
    "duration": 6010
}, {
    "text": "This is my legacy, legacy, legacy, legacy",
    "timeIn": "03:15.03",
    "duration": 5860
}, {
    "text": "[Verse 3]",
    "timeIn": "03:20.89",
    "duration": 530
}, {
    "text": "I used to be the type of kid that would always think the sky is fallin'",
    "timeIn": "03:21.42",
    "duration": 3460
}, {
    "text": "Now I think the fact that I'm differently wired's awesome",
    "timeIn": "03:24.88",
    "duration": 2800
}, {
    "text": "Cause if I wasn't, I wouldn't be able to work words like this",
    "timeIn": "03:27.68",
    "duration": 3500
}, {
    "text": "And connect lines like crosswords",
    "timeIn": "03:31.18",
    "duration": 2130
}, {
    "text": "And use my enemy's words as strength",
    "timeIn": "03:33.31",
    "duration": 1910
}, {
    "text": "To try and draw from, and get inspired off 'em",
    "timeIn": "03:35.22",
    "duration": 2830
}, {
    "text": "Cause all my life I was told and taught I am not shit",
    "timeIn": "03:38.05",
    "duration": 2850
}, {
    "text": "By you wack fucking giant sacks of lying dog shit",
    "timeIn": "03:40.90",
    "duration": 3350
}, {
    "text": "Now you shut up bitch, I am talkin' thought I was full of horseshit",
    "timeIn": "03:44.25",
    "duration": 3810
}, {
    "text": "And now you fucking worship the ground on which I am walkin'",
    "timeIn": "03:48.06",
    "duration": 3100
}, {
    "text": "Me against the world, so what? I'm Brian Dawkins",
    "timeIn": "03:51.16",
    "duration": 3000
}, {
    "text": "Versus the whole 0-16 Lions offense",
    "timeIn": "03:54.16",
    "duration": 2870
}, {
    "text": "So bring on the Giants, Falcons and Miami Dolphins",
    "timeIn": "03:57.03",
    "duration": 2830
}, {
    "text": "It's the body bag game, bitch, I'm supplyin' coffins",
    "timeIn": "03:59.86",
    "duration": 2820
}, {
    "text": "Cause you dicks butt kiss, bunch of Brian Baldingers",
    "timeIn": "04:02.68",
    "duration": 3700
}, {
    "text": "You're going to die a ball licker, I've been diabolical",
    "timeIn": "04:06.38",
    "duration": 2500
}, {
    "text": "With this dialogue since '99 Rawkus",
    "timeIn": "04:08.88",
    "duration": 3150
}, {
    "text": "You don't respect the legacy I leave behind y'all can suck a dick",
    "timeIn": "04:12.03",
    "duration": 3330
}, {
    "text": "The day you beat me, pigs'll fly out my ass",
    "timeIn": "04:15.36",
    "duration": 2880
}, {
    "text": "In a flying saucer full of Italian sausage",
    "timeIn": "04:18.24",
    "duration": 2620
}, {
    "text": "The most high exalting and I ain't haltin'",
    "timeIn": "04:20.86",
    "duration": 2500
}, {
    "text": "'til I die of exhaustion, inhale my exhaust fumes",
    "timeIn": "04:23.36",
    "duration": 1620
}, {
    "text": "The best part about me is I am not you",
    "timeIn": "04:24.98",
    "duration": 5070
}, {
    "text": "I'm me, I'm the Fire Marshall and this is my...",
    "timeIn": "04:30.05",
    "duration": 2550
}, {
    "text": "[Hook: Polina]",
    "timeIn": "04:32.60",
    "duration": 1060
}, {
    "text": "Cause this is my legacy, legacy, yeah",
    "timeIn": "04:33.66",
    "duration": 3080
}, {
    "text": "This is my legacy, legacy, yeah",
    "timeIn": "04:36.74",
    "duration": 6320
}, {
    "text": "There's no guarantee, it's not up to me, we can only see",
    "timeIn": "04:43.06",
    "duration": 5880
}, {
    "text": "This is my legacy, legacy, legacy, legacy",
    "timeIn": "04:48.94",
    "duration": 7800
}, {
    "text": "--- www.LRCgenerator.com ---",
    "timeIn": "04:56.74"
}];

var player = new Vue({
  el: '#player',
  
  data: {
    lyrics: {
      show: false,
      timer: null,
      currentLine: '',
      text: lyricsText,
    },
    
    song : {
      artist: 'Eminem',
      title: 'Legacy',
      progress: 0
    },
    
    audio: null,
    
    playing: false,
    
    playerTouched: false
  },
  
  ready: function() {
    // Setup the audio element
    this.audio = this.$els.audio;
    
    // Setup time tracker updates
    this.audio.addEventListener('timeupdate', this.updateTimeTracker, false);
    
    // Setup end reset
    this.audio.addEventListener('ended', this.resetPlayer, false);
  },
  
  methods: {
    hideText: function() {
      this.lyrics.show = !this.lyrics.show;
    },
    
    startPlayback: function() {
        this.playing = true;
      
        this.audio.volume = 0.5;
        this.audio.play();
      
        this.lyrics.show = true;
        this.displayNextLine(0);
    },
    
    togglePlayback: function() {
      if (!this.playerTouched) {
        this.startPlayback();
        this.playerTouched = true;
        return;
      }
      
      this.playing = !this.playing;
      
      if (this.audio.paused) {
        this.audio.play();
        this.resumeLyrics();
      } else {
        this.audio.pause();
        this.pauseLyrics();
      }
    },
    
    pauseLyrics: function() {
      if (this.lyrics.timer) {
        this.lyrics.timer.pause();
      }
    },
    
    resumeLyrics: function() {
      if (this.lyrics.timer) {
        this.lyrics.timer.resume();
      }
    },
    
    displayNextLine: function(line) {
      var _this = this;
      
      // Set the currentLine, which will auto display
      _this.lyrics.currentLine = _this.lyrics.text[line].text;

      if (_this.lyrics.text[line + 1] !== undefined) {
        _this.lyrics.timer = new Timer(function() {
          _this.displayNextLine(line + 1);
        }, _this.lyrics.text[line].duration);
      } else {
          _this.lyrics.currentLine = 'THE END';
      }      
    },
    
    updateTimeTracker: function() {
      this.song.progress = 100 * (this.audio.currentTime / this.audio.duration);
    },
    
    resetPlayer: function() {
      this.playing = false;
      this.playerTouched = false;
    }
  }
  
});

function Timer(callback, delay) {
    var timerId;
    var start;
    var remaining = delay;

    this.pause = function() {
        window.clearTimeout(timerId);
        remaining -= new Date() - start;
    };

    this.resume = function() {
        start = new Date();
        window.clearTimeout(timerId);
        timerId = window.setTimeout(callback, remaining);
    };

    this.resume();
}

              
            
!
999px

Console