corawons

multi song music digi player

Oct 20th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 7.03 KB | None | 0 0
  1. <!-----
  2.  
  3. multiple song music player by adilene @ adilene.net. free to use and edit as you like! credit is not necessary, but it is appreciated! <3
  4.  
  5. if you need any help feel free to reach out to me at adilene.net!
  6.  
  7. source code: https://github.com/sayantanm19/js-music-player
  8.  
  9. ----->
  10.  
  11. <head>
  12. <script src="https://unpkg.com/phosphor-icons"></script>
  13.  
  14. <style>
  15. @font-face {
  16. font-family: Nintendo-DS-BIOS;
  17. src: url(https://dl.dropbox.com/s/vlxjtnvrl9s0snp/Nintendo-DS-BIOS.ttf);
  18. }
  19.  
  20. #musicplayer {
  21. position: relative;
  22. }
  23.  
  24. .songtitle {
  25. font-family: Nintendo-DS-BIOS;
  26. font-size: 1em;
  27. color: white;
  28. -webkit-filter: drop-shadow(0px 0px 1px #525252);
  29. }
  30.  
  31. .controls {
  32. font-size: 18px !important;
  33. text-align: center;
  34. width: 100%;
  35. }
  36.  
  37. .controls td {
  38. padding: 0px 5px 0px 5px;
  39. }
  40.  
  41. .seeking {
  42. display: flex;
  43. justify-content: space-evenly;
  44. }
  45.  
  46. .current-time {
  47. padding-right: 5px;
  48. font-family: Nintendo-DS-BIOS;
  49. font-size: 1em;
  50. color: #886c63;
  51. }
  52.  
  53. .total-duration {
  54. padding-left: 5px;
  55. font-family: Nintendo-DS-BIOS;
  56. font-size: 1em;
  57. color: #886c63;
  58. }
  59.  
  60. input[type=range] {
  61. -webkit-appearance: none;
  62. width: 100%;
  63. background-color: transparent;
  64. }
  65.  
  66. input[type=range]:focus {
  67. outline: none;
  68. }
  69.  
  70. input[type=range]::-webkit-slider-runnable-track {
  71. width: 100%;
  72. height: 2px;
  73. cursor: help;
  74. animate: 0.2s;
  75. background: #886c63;
  76. border-radius: 1px;
  77. }
  78.  
  79. input[type=range]::-webkit-slider-thumb {
  80. border: 0px solid #000;
  81. height: 10px;
  82. width: 10px;
  83. border-radius: 10px;
  84. background: #886c63;
  85. cursor: help;
  86. -webkit-appearance: none;
  87. margin-top: -4px;
  88. }
  89.  
  90. input[type=range]:focus::-webkit-slider-runnable-track {
  91. background: #886c63;
  92. }
  93.  
  94. input[type=range]::-moz-range-track {
  95. width: 100%;
  96. height: 2px;
  97. cursor: help;
  98. animate: 0.2s;
  99. background: #886c63;
  100. border-radius: 1px;
  101. }
  102.  
  103. input[type=range]::-moz-range-thumb {
  104. border: 0px solid #000;
  105. height: 10px;
  106. width: 10px;
  107. border-radius: 10px;
  108. background: #886c63;
  109. cursor: help;
  110. }
  111.  
  112. input[type=range]::-ms-track {
  113. width: 100%;
  114. height: 2px;
  115. cursor: help;
  116. animate: 0.2s;
  117. background: transparent;
  118. border-color: transparent;
  119. color: transparent;
  120. }
  121.  
  122. input[type=range]::-ms-fill-lower {
  123. background: #886c63;
  124. border-radius: 2px;
  125. }
  126.  
  127. input[type=range]::-ms-fill-upper {
  128. background: #886c63;
  129. border-radius: 2px;
  130. }
  131.  
  132. input[type=range]::-ms-thumb {
  133. margin-top: 1px;
  134. border: 0px solid #886c63;
  135. height: 10px;
  136. width: 10px;
  137. border-radius: 10px;
  138. background: #886c63;
  139. cursor: help;
  140. }
  141.  
  142. input[type=range]:focus::-ms-fill-lower {
  143. background: #886c63;
  144. }
  145.  
  146. input[type=range]:focus::-ms-fill-upper {
  147. background: #886c63;
  148. }
  149. </style>
  150. </head>
  151.  
  152. <body>
  153. <div id="musicplayer">
  154. <div>
  155.  
  156. <div class="songtitle"></div>
  157.  
  158. <table class="controls">
  159. <tr>
  160. <td>
  161. <div class="prev-track" onclick="prevTrack()"><i class="ph-skip-back-fill" style="color: #886c63"></i></div>
  162. </td>
  163. <td>
  164. <div class="playpause-track" onclick="playpauseTrack()" ><i class="ph-play-fill" style="color: #886c63"></i></div>
  165. </td>
  166. <td>
  167. <div class="next-track" onclick="nextTrack()"><i class="ph-skip-forward-fill" style="color: #886c63"></i></div>
  168. </td>
  169. </tr>
  170. </table>
  171.  
  172. <div class="seeking">
  173. <div class="current-time">0:00</div>
  174.  
  175. <input type="range" min="1" max="100" value="0" class="seek_slider" onchange="seekTo()">
  176.  
  177. <div class="total-duration">0:00</div>
  178. </div>
  179.  
  180. <audio id="music" src=""></audio>
  181. </div>
  182. </div>
  183.  
  184. <script>
  185. let track_name = document.querySelector(".songtitle");
  186.  
  187. let playpause_btn = document.querySelector(".playpause-track");
  188. let next_btn = document.querySelector(".next-track");
  189. let prev_btn = document.querySelector(".prev-track");
  190.  
  191. let seek_slider = document.querySelector(".seek_slider");
  192. let curr_time = document.querySelector(".current-time");
  193. let total_duration = document.querySelector(".total-duration");
  194.  
  195. let track_index = 0;
  196. let isPlaying = false;
  197. let updateTimer;
  198.  
  199. // Create new audio element
  200. let curr_track = document.getElementById("music");
  201.  
  202. //
  203. // DEFINE YOUR SONGS HERE!!!!!
  204. // MORE THAN FOUR SONGS CAN BE ADDED!!
  205. // JUST ADD ANOTHER BRACKET WITH NAME AND PATH
  206. // CATBOX.MOE IS RECOMMENDED FOR UPLOADING MP3 FILES
  207. let track_list = [
  208. {
  209. name:"3rd eye - stray kids",
  210. path:"https://dl.dropbox.com/s/lqdf91mf9nvshb4/3rd%20Eye.mp3"
  211. },
  212. {
  213. name:"inabakumori feat. kaai yuki - kimi ni kaikisen",
  214. path:"https://files.catbox.moe/1pxdnw.mp3"
  215. },
  216. {
  217. name:"pinocchio-p feat. hatsune miku - god-ish",
  218. path:"https://files.catbox.moe/xv3vdj.mp3"
  219. },
  220. {
  221. name: "syudou feat. hatsune miku - her boyfriend, jude",
  222. path: "https://files.catbox.moe/49iuxl.mp3",
  223. },
  224. ];
  225.  
  226. function loadTrack(track_index) {
  227. clearInterval(updateTimer);
  228. resetValues();
  229.  
  230. // Load a new track
  231. curr_track.src = track_list[track_index].path;
  232. curr_track.load();
  233.  
  234. // Set an interval of 1000 milliseconds for updating the seek slider
  235. updateTimer = setInterval(seekUpdate, 1000);
  236.  
  237. // Move to the next track if the current one finishes playing
  238. curr_track.addEventListener("ended", nextTrack);
  239.  
  240. }
  241.  
  242. // Reset Values
  243. function resetValues() {
  244. curr_time.textContent = "0:00";
  245. total_duration.textContent = "0:00";
  246. seek_slider.value = 0;
  247. }
  248.  
  249. function playpauseTrack() {
  250. if (!isPlaying) playTrack();
  251. else pauseTrack();
  252. }
  253.  
  254. function playTrack() {
  255. curr_track.play();
  256. isPlaying = true;
  257.  
  258. // Replace icon with the pause icon
  259. playpause_btn.innerHTML = '<i class="ph-pause-fill" style="color: #886c63"></i>';
  260. }
  261.  
  262. function pauseTrack() {
  263. curr_track.pause();
  264. isPlaying = false;
  265.  
  266. // Replace icon with the play icon
  267. playpause_btn.innerHTML = '<i class="ph-play-fill" style="color: #886c63"></i>';
  268. }
  269.  
  270. function nextTrack() {
  271. if (track_index < track_list.length - 1)
  272. track_index += 1;
  273. else track_index = 0;
  274. loadTrack(track_index);
  275. playTrack();
  276. }
  277.  
  278. function prevTrack() {
  279. if (track_index > 0)
  280. track_index -= 1;
  281. else track_index = track_list.length;
  282. loadTrack(track_index);
  283. playTrack();
  284. }
  285.  
  286. function seekTo() {
  287. seekto = curr_track.duration * (seek_slider.value / 100);
  288. curr_track.currentTime = seekto;
  289. }
  290.  
  291. function seekUpdate() {
  292. let seekPosition = 0;
  293.  
  294. // Check if the current track duration is a legible number
  295. if (!isNaN(curr_track.duration)) {
  296. seekPosition = curr_track.currentTime * (100 / curr_track.duration);
  297. seek_slider.value = seekPosition;
  298.  
  299. // Calculate the time left and the total duration
  300. let currentMinutes = Math.floor(curr_track.currentTime / 60);
  301. let currentSeconds = Math.floor(curr_track.currentTime - currentMinutes * 60);
  302. let durationMinutes = Math.floor(curr_track.duration / 60);
  303. let durationSeconds = Math.floor(curr_track.duration - durationMinutes * 60);
  304.  
  305. // Adding a zero to the single digit time values
  306. if (currentSeconds < 10) { currentSeconds = "0" + currentSeconds; }
  307. if (durationSeconds < 10) { durationSeconds = "0" + durationSeconds; }
  308. if (currentMinutes < 10) { currentMinutes = currentMinutes; }
  309. if (durationMinutes < 10) { durationMinutes = durationMinutes; }
  310.  
  311. curr_time.textContent = currentMinutes + ":" + currentSeconds;
  312. total_duration.textContent = durationMinutes + ":" + durationSeconds;
  313. }
  314. }
  315.  
  316. // Load the first track in the tracklist
  317. loadTrack(track_index);
  318. </script>
  319. </body>
Add Comment
Please, Sign In to add comment