How to Build a Floating Corner Audio Player with Spinning Vinyl Disc & Scrub Waveform
A floating corner audio player binds an HTML `
Step 1: Structure the Compact Audio Player Layout
Build the player shell with spinning album disc art, track metadata, progress rail, and play/pause controls.
<div class="mini-audio-player" id="miniPlayer">
<div class="vinyl-disc" id="vinylDisc">
<div class="vinyl-grooves"></div>
<div class="vinyl-center">🎶</div>
</div>
<div class="player-body">
<div class="track-info">
<span class="track-title">Cybernetic Lo-Fi Breeze</span>
<span class="track-time" id="trackTime">0:00 / 2:45</span>
</div>
<input type="range" class="player-scrubber" id="scrubber" min="0" max="100" value="0">
</div>
<button class="player-btn-play" id="btnPlay" aria-label="Play audio">▶</button>
<audio id="audioEl" src="data:audio/wav;base64,UklGRiQAAABXQVZFZmx0cg..."></audio>
</div>
Step 2: Animate Spinning Vinyl with CSS Keyframes
Use CSS animation-play-state to seamlessly start and stop rotation without snapping back to 0 degrees.
.mini-audio-player {
position: fixed;
bottom: 24px;
left: 24px;
background: rgba(15, 23, 42, 0.9);
backdrop-filter: blur(16px);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 40px;
padding: 8px 16px 8px 8px;
display: flex;
align-items: center;
gap: 12px;
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}
.vinyl-disc {
width: 44px;
height: 44px;
border-radius: 50%;
background: radial-gradient(circle, #1e293b 35%, #0f172a 70%, #000 100%);
border: 2px solid rgba(255, 255, 255, 0.2);
display: flex;
align-items: center;
justify-content: center;
animation: spinVinyl 4s linear infinite;
animation-play-state: paused;
}
.mini-audio-player.is-playing .vinyl-disc {
animation-play-state: running;
}
@keyframes spinVinyl {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
Step 3: Hook Audio Events and Time Tracking
Bind HTMLAudioElement play, pause, and timeupdate events to update slider and timestamp displays.
const player = document.getElementById('miniPlayer');
const audio = document.getElementById('audioEl');
const btnPlay = document.getElementById('btnPlay');
const scrubber = document.getElementById('scrubber');
const trackTime = document.getElementById('trackTime');
function togglePlayback() {
if (audio.paused) {
audio.play();
player.classList.add('is-playing');
btnPlay.textContent = '⏸';
} else {
audio.pause();
player.classList.remove('is-playing');
btnPlay.textContent = '▶';
}
}
btnPlay.addEventListener('click', togglePlayback);
audio.addEventListener('timeupdate', () => {
if (!audio.duration) return;
const pct = (audio.currentTime / audio.duration) * 100;
scrubber.value = pct;
const curM = Math.floor(audio.currentTime / 60);
const curS = Math.floor(audio.currentTime % 60);
trackTime.textContent = `${curM}:${String(curS).padStart(2, '0')}`;
});
scrubber.addEventListener('input', () => {
if (audio.duration) {
audio.currentTime = (scrubber.value / 100) * audio.duration;
}
});
Next-Level Addons: Elevating Your Implementation
Take this technique further by combining it with complementary design token studios and animation tools:
Here's my golden rule when implementing this in production: test across multiple devices and browsers early. Keep your DOM hierarchy shallow, optimize assets with modern formats (like WebP/AVIF), and verify keyboard navigation for accessibility.
Frequently Asked Questions
Practical answers to common implementation questions, browser quirks, and performance tips.
Why does animation-play-state maintain the rotation angle when paused?
Unlike removing an animation class which resets transform to 0deg, `animation-play-state: paused` freezes the CSS animation at its exact current frame.
How can you autoplay audio when a user visits the page?
Modern browsers block unmuted autoplay without prior user gesture. If you wish to autoplay ambient music, mute the audio element initially and allow visitors to unmute.
Can the mini player persist playback across page navigations in a SPA or MPA?
In Single Page Applications (SPAs), place the mini player outside the router view. In Multi-Page Applications (MPAs), persist currentTime in sessionStorage and resume upon page load.
How do you handle keyboard Spacebar toggling without scrolling the page?
In the keydown event listener for keyCode 32 / e.code === "Space", invoke `e.preventDefault()` before toggling audio playback.
What is the performance overhead of playing audio in modern browsers?
Standard HTMLAudioElement hardware-decodes AAC and MP3 streams on background audio threads with under 1% CPU utilization.