Advertisement
zhansitos

music player

Oct 17th, 2022
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.77 KB | None | 0 0
  1. <head>
  2. <script src="https://unpkg.com/phosphor-icons"></script>
  3.  
  4. <style>
  5. @font-face {
  6. font-family: Nintendo-DS-BIOS;
  7. src: url(https://dl.dropbox.com/s/vlxjtnvrl9s0snp/Nintendo-DS-BIOS.ttf);
  8. }
  9.  
  10. #musicplayer {
  11. }
  12.  
  13. .songtitle {
  14. font-family: Nintendo-DS-BIOS;
  15. font-size: 1em;
  16. color: white;
  17. -webkit-filter: drop-shadow(0px 0px 1px #525252);
  18. }
  19.  
  20. .controls {
  21. font-size: 12px !important;
  22. text-align: center;
  23. width: 100%;
  24. }
  25.  
  26. .controls td {
  27. padding: 0px 5px 0px 5px;
  28. }
  29.  
  30. .seeking {
  31. display: flex;
  32. justify-content: space-evenly;
  33. }
  34.  
  35. .current-time {
  36. padding-right: 5px;
  37. font-family: Nintendo-DS-BIOS;
  38. font-size: 0.875em;
  39. color: #000000;
  40. }
  41.  
  42. .total-duration {
  43. padding-left: 5px;
  44. font-family: Nintendo-DS-BIOS;
  45. font-size: 0.875em;
  46. color: #000000;
  47. }
  48.  
  49. input[type=range] {
  50. -webkit-appearance: none;
  51. width: 100%;
  52. background-color: transparent;
  53. }
  54.  
  55. input[type=range]:focus {
  56. outline: none;
  57. }
  58.  
  59. input[type=range]::-webkit-slider-runnable-track {
  60. width: 100%;
  61. height: 5px;
  62. cursor: help;
  63. animate: 0.2s;
  64. background: #F8FCF8;
  65. border-radius: 1px;
  66. }
  67.  
  68. input[type=range]::-webkit-slider-thumb {
  69. border:ridge #CCCCCC;
  70. border-width: 4px 2px 4px 2px;
  71. height: 15px;
  72. width: 10px;
  73. border-radius: 2px;
  74. background: #F8FCF8;
  75. cursor: help;
  76. -webkit-appearance: none;
  77. margin-top: 3px;
  78. }
  79.  
  80. input[type=range]:focus::-webkit-slider-runnable-track {
  81. background: #F8FCF8;
  82. }
  83.  
  84. input[type=range]::-moz-range-track {
  85. width: 100%;
  86. height: 2px;
  87. cursor: help;
  88. animate: 0.2s;
  89. background: #F8FCF8;
  90. border-radius: 1px;
  91. }
  92.  
  93. input[type=range]::-moz-range-thumb {
  94. border: 0px solid #F8FCF8;
  95. height: 10px;
  96. width: 10px;
  97. border-radius: 10px;
  98. background: #F8FCF8;
  99. cursor: help;
  100. }
  101.  
  102. input[type=range]::-ms-track {
  103. width: 100%;
  104. height: 2px;
  105. cursor: help;
  106. animate: 0.2s;
  107. background: transparent;
  108. border-color: transparent;
  109. color: transparent;
  110. }
  111.  
  112. input[type=range]::-ms-fill-lower {
  113. background: #F8FCF8;
  114. border-radius: 2px;
  115. }
  116.  
  117. input[type=range]::-ms-fill-upper {
  118. background: #F8FCF8;
  119. border-radius: 2px;
  120. }
  121.  
  122. input[type=range]::-ms-thumb {
  123. margin-top: 1px;
  124. border: 0px solid #ffff00;
  125. height: 10px;
  126. width: 10px;
  127. border-radius: 10px;
  128. background: #808480;
  129. cursor: help;
  130. }
  131.  
  132. input[type=range]:focus::-ms-fill-lower {
  133. background: #808480;
  134. }
  135.  
  136. input[type=range]:focus::-ms-fill-upper {
  137. background: #808480;
  138. }
  139. </style>
  140. </head>
  141.  
  142. <body>
  143. <div id="musicplayer">
  144. <div>
  145.  
  146. <div class="seeking">
  147. <div class="current-time">00:00</div>
  148.  
  149. <input type="range" min="1" max="100" value="0" class="seek_slider" onchange="seekTo()">
  150.  
  151. <div class="total-duration">0:00</div>
  152. </div>
  153.  
  154. <audio id="music" src=""></audio>
  155. </div>
  156.  
  157. <br>
  158.  
  159. <div class="songtitle"></div>
  160.  
  161. <table class="controls">
  162. <tr>
  163. <td>
  164. <div class="prev-track" onclick="prevTrack()"><i class="ph-skip-back-fill" style="color: #808480"></i></div>
  165. </td>
  166. <td>
  167. <div class="playpause-track" onclick="playpauseTrack()" ><i class="ph-play-fill" style="color: #808480"></i></div>
  168. </td>
  169. <td>
  170. <div class="next-track" onclick="nextTrack()"><i class="ph-skip-forward-fill" style="color: #808480"></i></div>
  171. </td>
  172. </tr>
  173. </table>
  174.  
  175. </div>
  176.  
  177. <script>
  178. let track_name = document.querySelector(".songtitle");
  179.  
  180. let playpause_btn = document.querySelector(".playpause-track");
  181. let next_btn = document.querySelector(".next-track");
  182. let prev_btn = document.querySelector(".prev-track");
  183.  
  184. let seek_slider = document.querySelector(".seek_slider");
  185. let curr_time = document.querySelector(".current-time");
  186. let total_duration = document.querySelector(".total-duration");
  187.  
  188. let track_index = 0;
  189. let isPlaying = false;
  190. let updateTimer;
  191.  
  192. // Create new audio element
  193. let curr_track = document.getElementById("music");
  194.  
  195. // Define the tracks that have to be played
  196. let track_list = [
  197. {
  198. name:"pictureinmymind",
  199. path:"https://cdn.glitch.global/7eefa97e-e9ba-47ff-9a9a-ad662be1fc2f/Picture%20in%20my%20mind.mp3?v=1665967806994"
  200. },
  201. {
  202. name:"colordrive",
  203. path:"https://cdn.glitch.global/7eefa97e-e9ba-47ff-9a9a-ad662be1fc2f/Color%20Drive.mp3?v=1665968283490"
  204. },
  205. {
  206. name:"yellowcab",
  207. path:"https://cdn.glitch.global/7eefa97e-e9ba-47ff-9a9a-ad662be1fc2f/Yellow%20Cab.mp3?v=1665968992322"
  208. },
  209. {
  210. name: "wondrousplace",
  211. path: "https://cdn.glitch.global/7eefa97e-e9ba-47ff-9a9a-ad662be1fc2f/Wondrous%20Place.mp3?v=1665968516457",
  212. },
  213. ];
  214.  
  215. function loadTrack(track_index) {
  216. clearInterval(updateTimer);
  217. resetValues();
  218.  
  219. // Load a new track
  220. curr_track.src = track_list[track_index].path;
  221. curr_track.load();
  222.  
  223. // Set an interval of 1000 milliseconds for updating the seek slider
  224. updateTimer = setInterval(seekUpdate, 1000);
  225.  
  226. // Move to the next track if the current one finishes playing
  227. curr_track.addEventListener("ended", nextTrack);
  228.  
  229. }
  230.  
  231. // Reset Values
  232. function resetValues() {
  233. curr_time.textContent = "0:00";
  234. total_duration.textContent = "0:00";
  235. seek_slider.value = 0;
  236. }
  237.  
  238. function playpauseTrack() {
  239. if (!isPlaying) playTrack();
  240. else pauseTrack();
  241. }
  242.  
  243. function playTrack() {
  244. curr_track.play();
  245. isPlaying = true;
  246.  
  247. // Replace icon with the pause icon
  248. playpause_btn.innerHTML = '<i class="ph-pause-fill" style="color: #808480"></i>';
  249. }
  250.  
  251. function pauseTrack() {
  252. curr_track.pause();
  253. isPlaying = false;
  254.  
  255. // Replace icon with the play icon
  256. playpause_btn.innerHTML = '<i class="ph-play-fill" style="color: #808480"></i>';
  257. }
  258.  
  259. function nextTrack() {
  260. if (track_index < track_list.length - 1)
  261. track_index += 1;
  262. else track_index = 0;
  263. loadTrack(track_index);
  264. playTrack();
  265. }
  266.  
  267. function prevTrack() {
  268. if (track_index > 0)
  269. track_index -= 1;
  270. else track_index = track_list.length;
  271. loadTrack(track_index);
  272. playTrack();
  273. }
  274.  
  275. function seekTo() {
  276. seekto = curr_track.duration * (seek_slider.value / 100);
  277. curr_track.currentTime = seekto;
  278. }
  279.  
  280. function seekUpdate() {
  281. let seekPosition = 0;
  282.  
  283. // Check if the current track duration is a legible number
  284. if (!isNaN(curr_track.duration)) {
  285. seekPosition = curr_track.currentTime * (100 / curr_track.duration);
  286. seek_slider.value = seekPosition;
  287.  
  288. // Calculate the time left and the total duration
  289. let currentMinutes = Math.floor(curr_track.currentTime / 60);
  290. let currentSeconds = Math.floor(curr_track.currentTime - currentMinutes * 60);
  291. let durationMinutes = Math.floor(curr_track.duration / 60);
  292. let durationSeconds = Math.floor(curr_track.duration - durationMinutes * 60);
  293.  
  294. // Adding a zero to the single digit time values
  295. if (currentSeconds < 10) { currentSeconds = "0" + currentSeconds; }
  296. if (durationSeconds < 10) { durationSeconds = "0" + durationSeconds; }
  297. if (currentMinutes < 10) { currentMinutes = currentMinutes; }
  298. if (durationMinutes < 10) { durationMinutes = durationMinutes; }
  299.  
  300. curr_time.textContent = currentMinutes + ":" + currentSeconds;
  301. total_duration.textContent = durationMinutes + ":" + durationSeconds;
  302. }
  303. }
  304.  
  305. // Load the first track in the tracklist
  306. loadTrack(track_index);
  307. </script>
  308. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement