Bootstrap 5 Audio Music Player Card
A music player card with album art, a seekable progress bar, play and pause, skip controls and a like button, driven by a short synthesised demo track.
<section class="wdw-stage">
<div class="container" style="max-width: 400px">
<div class="wdw-card p-3 p-sm-4">
<div class="cover position-relative rounded-4 overflow-hidden mb-4">
<img src="https://images.unsplash.com/photo-1470225620780-dba8ba36b745?w=800&h=800&fit=crop&q=80" alt="DJ turntable with warm stage lights" class="w-100 d-block">
<span class="badge rounded-pill text-bg-dark position-absolute top-0 start-0 m-3 bg-opacity-75">Featured</span>
</div>
<div class="d-flex justify-content-between align-items-start gap-3 mb-3">
<div class="min-w-0"><h1 class="h5 wdw-heading mb-0 text-truncate">Midnight Bachata</h1><p class="wdw-muted mb-0">DJ Flam · Urban remix</p></div>
<button type="button" class="btn btn-outline-secondary border-0 rounded-circle p-0 text-body flex-none" style="width:44px" id="likeBtn" aria-pressed="false" aria-label="Like">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><path d="M20.8 4.600a5.500 5.500 0 0 0-7.800 0L12 5.700l-1-1.100a5.500 5.500 0 0 0-7.800 7.800l1 1.100L12 21.200l7.800-7.700 1-1.100a5.500 5.500 0 0 0 0-7.800z"/></svg>
</button>
</div>
<input type="range" class="seek w-100" id="seek" min="0" max="100" value="0" step="0.1" aria-label="Seek">
<div class="d-flex justify-content-between small wdw-muted mt-1 mb-3"><span id="tNow">0:00</span><span id="tTotal">0:12</span></div>
<div class="d-flex justify-content-center align-items-center gap-3">
<button type="button" class="btn btn-outline-secondary border-0 rounded-circle p-0 text-body" style="width:48px;min-height:48px" id="backBtn" aria-label="Back 5 seconds"><svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M6 6h2v12H6zM20 6v12L9.500 12z"/></svg></button>
<button type="button" class="btn btn-primary rounded-circle p-0" style="width:64px;min-height:64px" id="playBtn" aria-label="Play">
<svg width="26" height="26" viewBox="0 0 24 24" fill="currentColor" id="icoPlay" aria-hidden="true"><path d="M8 5v14l11-7z"/></svg>
<svg width="26" height="26" viewBox="0 0 24 24" fill="currentColor" id="icoPause" class="d-none" aria-hidden="true"><path d="M6 5h4v14H6zM14 5h4v14h-4z"/></svg>
</button>
<button type="button" class="btn btn-outline-secondary border-0 rounded-circle p-0 text-body" style="width:48px;min-height:48px" id="fwdBtn" aria-label="Forward 5 seconds"><svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M16 6h2v12h-2zM4 18V6l10.500 6z"/></svg></button>
</div>
<p class="text-center small wdw-muted mt-3 mb-0">Synthesised demo track</p>
</div>
</div>
</section>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
.min-w-0 { min-width: 0; }
.flex-none { flex: none; }
.cover img { aspect-ratio: 1 / 1; object-fit: cover; max-height: 260px; }
.seek { -webkit-appearance: none; appearance: none; height: 6px; border-radius: 999px; outline: none; cursor: pointer;
background: linear-gradient(to right, var(--bs-primary) var(--p, 0%), var(--bs-border-color) var(--p, 0%)); }
.seek::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--bs-primary); border: 3px solid var(--bs-body-bg); box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.seek::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--bs-primary); border: 3px solid var(--bs-body-bg); }
.seek:focus-visible { box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
#likeBtn[aria-pressed="true"] { color: #e11d48 !important; }
#likeBtn[aria-pressed="true"] path { fill: currentColor; }
function initAudioPlayer() {
const button = document.getElementById('playBtn');
const seekEl = document.getElementById('seek');
const AudioCtx = window.AudioContext || window.webkitAudioContext;
if (!button || !seekEl || !AudioCtx) return;
const icoPlay = document.getElementById('icoPlay');
const icoPause = document.getElementById('icoPause');
const tNow = document.getElementById('tNow');
const tTotal = document.getElementById('tTotal');
const melody = [261.6, 329.6, 392, 523.3, 392, 329.6, 440, 523.3, 659.3, 523.3, 440, 392, 349.2, 440, 523.3, 440, 392, 329.6, 293.7, 392, 329.6, 261.6, 0, 0];
const noteLen = 0.5;
const duration = melody.length * noteLen;
let ctx = null;
let playing = false;
let position = 0;
let startedAt = 0;
let voices = [];
let frame = 0;
let dragging = false;
function fmt(s) { s = Math.floor(s); return Math.floor(s / 60) + ':' + String(s % 60).padStart(2, '0'); }
tTotal.textContent = fmt(duration);
function setIcon() {
icoPlay.classList.toggle('d-none', playing);
icoPause.classList.toggle('d-none', !playing);
button.setAttribute('aria-label', playing ? 'Pause' : 'Play');
}
function current() { return playing ? Math.min(duration, position + ctx.currentTime - startedAt) : position; }
function render() {
const ratio = current() / duration;
seekEl.value = ratio * 100;
seekEl.style.setProperty('--p', (ratio * 100) + '%');
tNow.textContent = fmt(current());
}
function stopVoices() {
voices.forEach(function (o) { try { o.stop(); } catch (e) { /* already stopped */ } });
voices = [];
}
function schedule() {
const t0 = ctx.currentTime;
melody.forEach(function (freq, i) {
const start = i * noteLen;
const end = start + noteLen;
if (!freq || end <= position) return;
const osc = ctx.createOscillator();
const gain = ctx.createGain();
const when = t0 + Math.max(0, start - position);
osc.type = 'triangle';
osc.frequency.value = freq;
gain.gain.setValueAtTime(0.0001, when);
gain.gain.exponentialRampToValueAtTime(0.25, when + 0.03);
gain.gain.exponentialRampToValueAtTime(0.0001, t0 + end - position - 0.02);
osc.connect(gain).connect(ctx.destination);
osc.start(when);
osc.stop(t0 + end - position);
voices.push(osc);
});
startedAt = t0;
}
function tick() {
if (!playing) return;
if (current() >= duration) { pause(0); return; }
if (!dragging) render();
frame = requestAnimationFrame(tick);
}
function play() {
if (!ctx) ctx = new AudioCtx();
if (ctx.state === 'suspended') ctx.resume();
if (position >= duration) position = 0;
playing = true;
schedule();
setIcon();
tick();
}
function pause(resetTo) {
position = typeof resetTo === 'number' ? resetTo : current();
playing = false;
stopVoices();
cancelAnimationFrame(frame);
setIcon();
render();
}
function seekTo(t) {
const wasPlaying = playing;
pause(Math.min(duration, Math.max(0, t)));
if (wasPlaying) play();
}
button.addEventListener('click', function () { if (playing) pause(); else play(); });
seekEl.addEventListener('pointerdown', function () { dragging = true; });
seekEl.addEventListener('input', function () {
seekEl.style.setProperty('--p', seekEl.value + '%');
tNow.textContent = fmt(seekEl.value / 100 * duration);
});
seekEl.addEventListener('change', function () { dragging = false; seekTo(seekEl.value / 100 * duration); });
document.getElementById('backBtn').addEventListener('click', function () { seekTo(current() - 5); });
document.getElementById('fwdBtn').addEventListener('click', function () { seekTo(current() + 5); });
const like = document.getElementById('likeBtn');
if (like) like.addEventListener('click', function () {
like.setAttribute('aria-pressed', like.getAttribute('aria-pressed') !== 'true');
});
setIcon();
render();
}
initAudioPlayer();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.