Advertisement
izuemis

cr rundvrn | music player

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