<div class="audio-widget">
<div class="audio-info">
<img src="https://placehold.co/60x60/3b82f6/ffffff?text=Art" alt="Album Art" class="album-art">
<div class="track-details">
<h3>Late Night Vibes</h3>
<p>Lofi Producer</p>
</div>
</div>
<div class="audio-controls">
<button class="play-circle" id="play-btn">
<svg id="play-icon" viewBox="0 0 24 24" width="20" height="20" fill="currentColor"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
<svg id="pause-icon" viewBox="0 0 24 24" width="20" height="20" fill="currentColor" style="display: none;"><rect x="6" y="4" width="4" height="16"></rect><rect x="14" y="4" width="4" height="16"></rect></svg>
</button>
<div class="progress-container">
<div class="progress-bar" id="progress-bar"></div>
</div>
</div>
<audio id="audio-element" src="https://codeshack.io/web/example.mp4"></audio>
</div>*, *::before, *::after {
box-sizing: border-box;
}
body {
font-family: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
background: url("https://placehold.co/1920x1080/4c1d95/1e1b4b?text=Gradient") center/cover;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
padding: 20px;
}
.audio-widget {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(16px);
border: 1px solid rgba(255, 255, 255, 0.2);
padding: 20px;
border-radius: 20px;
width: 100%;
max-width: 350px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
color: #ffffff;
}
.audio-info {
display: flex;
align-items: center;
gap: 16px;
margin-bottom: 24px;
}
.album-art {
border-radius: 12px;
box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.track-details h3 {
margin: 0 0 4px 0;
font-size: 1.125rem;
}
.track-details p {
margin: 0;
color: #cbd5e1;
font-size: 0.875rem;
}
.audio-controls {
display: flex;
align-items: center;
gap: 16px;
}
.play-circle {
background: #ffffff;
color: #4c1d95;
border: none;
width: 44px;
height: 44px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
flex-shrink: 0;
transition: transform 0.2s;
}
.play-circle:active {
transform: scale(0.95);
}
.progress-container {
flex-grow: 1;
height: 6px;
background: rgba(255, 255, 255, 0.2);
border-radius: 3px;
overflow: hidden;
}
.progress-bar {
height: 100%;
width: 0%;
background: #ffffff;
border-radius: 3px;
}const audio = document.getElementById("audio-element");
const playBtn = document.getElementById("play-btn");
const playIcon = document.getElementById("play-icon");
const pauseIcon = document.getElementById("pause-icon");
const progressBar = document.getElementById("progress-bar");
playBtn.addEventListener("click", function() {
if (audio.paused) {
audio.play();
playIcon.style.display = "none";
pauseIcon.style.display = "block";
} else {
audio.pause();
playIcon.style.display = "block";
pauseIcon.style.display = "none";
}
});
audio.addEventListener("timeupdate", function() {
if (!isNaN(audio.duration)) {
const percentage = (audio.currentTime / audio.duration) * 100;
progressBar.style.width = percentage + "%";
}
});
// Reset when finished
audio.addEventListener("ended", function() {
playIcon.style.display = "block";
pauseIcon.style.display = "none";
progressBar.style.width = "0%";
});Nothing to show yetType HTML, CSS or JavaScript and your page appears here.
Click any element to find its code Esc
Check this code before you run it
It came from a shared link. It runs with fewer permissions, so it cannot open pop-ups, submit forms or start downloads.
0.00s / 0.00s
Nothing has animated yet. Hover, click or type in the preview and each CSS animation, transition or
element.animate() call shows up here as it plays.