Advertisement
GodinaNicolae

HTML5 miniPlayer

Feb 16th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3.     <title>xBattle Player</title>
  4.     <script type="text/javascript">
  5.         window.onload = function () {
  6.             var player = new Audio;
  7.             var bplay = document.getElementById('play');
  8.             var bnext = document.getElementById('next');
  9.             var bprev = document.getElementById('prev');
  10.             var bvolum = document.getElementById('volume');
  11.             var ctitle = document.getElementById('title');
  12.             var list = [['http://k007.kiwi6.com/hotlink/wp1i7pay90/rock_-_i_am_rock.mp3','Rock - I Am Rock'],
  13.                         ['http://k007.kiwi6.com/hotlink/n2mgmg4z8r/linkin.mp3','Linkin Park - CASTLE OF GLASS'],
  14.                         ['http://k007.kiwi6.com/hotlink/7345o21bo7/hardwellspaceman.mp3','Hardwell - Spaceman'],
  15.                         ['http://k007.kiwi6.com/hotlink/cadaqmymtv/linkin_park_-_in_the_end.mp3','Linkin Park - In the end'],
  16.                         ['http://k007.kiwi6.com/hotlink/43j9ocga54/rammstein_-_sonne.mp3','Rammstein - Stonne'],
  17.                         ['http://k007.kiwi6.com/hotlink/1977vs4lap/asian_dub_foundation_-_fortress_europe.mp3','Asian Dub Foundation - Fortress Europe'],
  18.                         ['http://k007.kiwi6.com/hotlink/ffjq7sil65/rob_zombie_-_two_lane_blacktop.mp3','Rob Zombie - Two lane blacktop']];
  19.             var curTack = 0;
  20.  
  21.  
  22.             function Change(track) {
  23.                 player.setAttribute('src', list[track][0]);
  24.                 ctitle.innerText = list[track][1];
  25.                 ctitle.style.display = 'inherit';
  26.                 setTimeout(function(){
  27.                     ctitle.style.display = 'none';
  28.                 },3000);
  29.                 player.play();
  30.                 bplay.src = "img/pause.png";
  31.             }
  32.  
  33.  
  34.             player.volume = 0.7;
  35.             player.canPlayType('audio/wav;codecs="1"');
  36.  
  37.             bplay.addEventListener("click", function() {
  38.                 if (player.paused) {
  39.                     if (player.currentSrc == '') Change(0);
  40.                     player.play();
  41.                     bplay.src = "img/pause.png";
  42.                 } else {
  43.                     player.pause();
  44.                     bplay.src = "img/play.png";
  45.                 }
  46.             }, false);
  47.  
  48.             bnext.addEventListener("click", function() {
  49.                 if (curTack+1 == list.length) curTack = 0; else curTack++;
  50.                 Change(curTack);
  51.             }, false);
  52.  
  53.             bprev.addEventListener("click", function() {
  54.                 if (curTack == 0) curTack = list.length-1; else curTack--;
  55.                 Change(curTack);
  56.             }, false);
  57.  
  58.             bvolum.addEventListener("change", function() {
  59.                 player.volume = this.value/100;
  60.             }, false);
  61.  
  62.             player.addEventListener("ended", function() {
  63.                 bnext.click();
  64.             }, false);
  65.  
  66.             bplay.click();
  67.         }
  68.     </script>
  69.     <style type="text/css">
  70. #player {
  71.     background: #fff;
  72.     border: #444 1px solid;
  73.     width: 120px;
  74.     padding: 3px;
  75.     position: fixed;
  76.     bottom: 0px;
  77.     left: 0px;
  78.     z-index: 9999;
  79. }
  80.  
  81. #player:hover > #title  {
  82.     display:inherit;
  83. }
  84.  
  85. #title {
  86.     display: none;
  87.     font-family: Tahoma;
  88.     font-size: 10px;
  89.     white-space:nowrap;
  90.     overflow:hidden;
  91. }
  92.  
  93. #player #buttons {
  94.     margin-top: 2px;
  95. }
  96.  
  97. #player img:hover {
  98.     background: #ccc;
  99. }
  100.  
  101. #player input[type='range'] {
  102.     -webkit-appearance: none !important;
  103.     background:black;
  104.     height:2px;
  105.     width: 60px;
  106.     margin-top: 4px;
  107.     position: absolute;
  108.     bottom: 10px;
  109.     right: 5px;
  110. }
  111.  
  112. #player #play {
  113.     margin-right: 5px;
  114.     margin-left: 5px;
  115. }
  116.  
  117. #player input[type='range']::-webkit-slider-thumb {
  118.     -webkit-appearance: none !important;
  119.     background: #333;
  120.     height: 6px;
  121.     width: 9px;
  122. }
  123.     </style>
  124. </head>
  125. <body>
  126.     <div id="player">
  127.         <div id="title"></div>
  128.  
  129.         <div id="buttons">
  130.             <img src="img/play.png" id="play"/>
  131.             <img src="img/prev.png" id="prev"/>
  132.             <img src="img/next.png" id="next"/>
  133.         </div>
  134.  
  135.         <div id="slider">
  136.             <input id="volume" type="range" min="0" value="70" max="100" step="1" />
  137.         </div>
  138.     </div>
  139. </body>
  140. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement