Dark Mode Audio Player - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Dark Mode Audio Player</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"> <style> body { display: flex; justify-content: center; align-items: center; height: 100vh; background: #121212; font-family: 'Arial', sans-serif; color: #ffffff; } .audio-player { background: #1f1f1f; border-radius: 15px; padding: 20px; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5); text-align: center; max-width: 350px; width: 100%; } .audio-player img { width: 80px; height: 80px; border-radius: 50%; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5); margin-bottom: 20px; } .audio-player audio { width: 100%; margin-bottom: 10px; outline: none; border: none; background: none; } .controls { display: flex; justify-content: center; align-items: center; gap: 10px; } .controls button { background: #ffffff; border: 1px solid #000; border-radius: 5px; width: 40px; height: 40px; font-size: 18px; color: #000; cursor: pointer; outline: none; transition: background 0.3s ease; } .controls button:hover { background: #cccccc; } .progress-container { position: relative; height: 8px; background: #333; border-radius: 4px; overflow: hidden; margin: 15px 0; } .progress { height: 100%; width: 0; background: #ffffff; border-radius: 4px; transition: width 0.1s; } .time { font-size: 12px; } .emoji { position: absolute; bottom: 10px; right: 10px; font-size: 16px; } </style> </head> <body> <div class="audio-player"> <img src="https://i.imgur.com/ZXBtVw7.jpg" alt="Audio Cover"> <audio id="audio" src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3"></audio> <div class="controls"> <button type="button" id="playPauseBtn" title="Play"><i class="fas fa-play"></i></button> <button type="button" id="stopBtn" title="Stop"><i class="fas fa-stop"></i></button> </div> <div class="progress-container"> <div class="progress"></div> </div> <div class="time"> <span id="currentTime">0:00</span> / <span id="duration">0:00</span> </div> <div class="emoji">🎧</div> </div> <script> const audio = document.getElementById('audio'); const playPauseBtn = document.getElementById('playPauseBtn'); const stopBtn = document.getElementById('stopBtn'); const progressContainer = document.querySelector('.progress-container'); const progress = document.querySelector('.progress'); const currentTimeEl = document.getElementById('currentTime'); const durationEl = document.getElementById('duration'); playPauseBtn.addEventListener('click', () => { if (audio.paused) { audio.play(); playPauseBtn.innerHTML = '<i class="fas fa-pause"></i>'; } else { audio.pause(); playPauseBtn.innerHTML = '<i class="fas fa-play"></i>'; } }); stopBtn.addEventListener('click', () => { audio.pause(); audio.currentTime = 0; playPauseBtn.innerHTML = '<i class="fas fa-play"></i>'; }); audio.addEventListener('timeupdate', () => { const progressPercent = (audio.currentTime / audio.duration) * 100; progress.style.width = `${progressPercent}%`; const minutes = Math.floor(audio.currentTime / 60); const seconds = Math.floor(audio.currentTime % 60); currentTimeEl.textContent = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`; }); audio.addEventListener('loadedmetadata', () => { const minutes = Math.floor(audio.duration / 60); const seconds = Math.floor(audio.duration % 60); durationEl.textContent = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`; }); progressContainer.addEventListener('click', (e) => { const width = progressContainer.clientWidth; const clickX = e.offsetX; const duration = audio.duration; audio.currentTime = (clickX / width) * duration; }); </script> </body> </html>