Advertisement
BRodXI

HTML Music Player

Jan 13th, 2023 (edited)
153
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.65 KB | Music | 1 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Music Player</title>
  5.     <style>
  6.         /* Styles for the player */
  7.         .player {
  8.             width: 500px;
  9.             margin: 0 auto;
  10.         }
  11.  
  12.         .controls {
  13.             display: flex;
  14.             justify-content: space-between;
  15.             align-items: center;
  16.             padding: 10px;
  17.             background-color: #f5f5f5;
  18.             border-radius: 5px;
  19.             margin-bottom: 10px;
  20.         }
  21.         .play-pause-btn {
  22.             width: 50px;
  23.             height: 50px;
  24.             border-radius: 50%;
  25.             background-color: #fff;
  26.             border: none;
  27.             outline: none;
  28.             cursor: pointer;
  29.         }
  30.         .play-pause-btn.playing {
  31.             background-color: #28a745;
  32.             color: #fff;
  33.         }
  34.         .progress-bar {
  35.             width: 100%;
  36.             height: 5px;
  37.             background-color: #ddd;
  38.             border-radius: 5px;
  39.             overflow: hidden;
  40.             margin-bottom: 10px;
  41.         }
  42.  
  43.         .progress {
  44.             width: 0%;
  45.             height: 100%;
  46.             background-color: #007bff;
  47.             border-radius: 5px;
  48.         }
  49.         /* Style for the song image*/
  50.         .song-image {
  51.             width: 500px;
  52.             height: 500px;
  53.             margin: 0 auto;
  54.         }
  55.     </style>
  56. </head>
  57.  
  58. <body>
  59.     <div class="player">
  60.         <div class="controls">
  61.             <button class="play-pause-btn" onclick="playPause()"></button>
  62.             <div class="progress-bar">
  63.                 <div class="progress"></div>
  64.             </div>
  65.         </div>
  66.         <img class="song-image" src="cover.png" alt="song cover">
  67.     </div>
  68.  
  69.     <script>
  70.         // Audio element
  71.         var audio = new Audio();
  72.         audio.src = "template.mp3";
  73.  
  74.         // Play/pause button
  75.         var playPauseBtn = document.querySelector(".play-pause-btn");
  76.  
  77.         // Progress bar
  78.         var progressBar = document.querySelector(".progress-bar");
  79.         var progress = document.querySelector(".progress");
  80.  
  81.         // Play/pause function
  82.         function playPause() {
  83.             if (audio.paused) {
  84.                 audio.play();
  85.                 playPauseBtn.classList.add("playing");
  86.             } else {
  87.                 audio.pause();
  88.                 playPauseBtn.classList.remove("playing");
  89.             }
  90.         }
  91.  
  92.         // Update progress bar
  93.         audio.addEventListener("timeupdate", function () {
  94.             var percentage = (audio.currentTime / audio.duration) * 100;
  95.             progress.style.width = percentage + "%";
  96.         });
  97.     </script>
  98. </body>
  99.  
  100. </html>
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement