Создание кастомного HTML-аудиоплеера с использованием SVG для кнопок, Bootstrap для стилей, а также с ползунком изменения громкости, скорости и времени воспроизведения, возможно в одном файле. Вот пример такой реализации:
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Custom Audio Player</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
.audio-player {
max-width: 500px;
margin: 0 auto;
padding: 15px;
background: #f8f9fa;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.controls svg {
width: 24px;
height: 24px;
cursor: pointer;
}
.progress-bar-container {
display: flex;
align-items: center;
}
.progress-bar {
width: 100%;
height: 6px;
cursor: pointer;
background-color: #dee2e6;
position: relative;
margin: 0 10px;
border-radius: 4px;
}
.progress-bar .fill {
height: 100%;
background-color: #007bff;
width: 0;
border-radius: 4px;
}
.progress-bar span {
display: none;
}
</style>
</head>
<body>
<div class="audio-player">
<audio id="audio">
<source src="sample.mp3" type="audio/mp3">
Your browser does not support the audio element.
</audio>
<div class="controls d-flex justify-content-between align-items-center mb-3">
<div class="play-pause">
<svg id="play-icon" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16">
<path d="M10.804 8.393 5.825 5.019a.5.5 0 0 1 .675-.738L11.5 7.654a.5.5 0 0 1 0 .677l-5 3.373a.5.5 0 0 1-.675-.738l4.978-3.273z"/>
</svg>
<svg id="pause-icon" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16" style="display: none;">
<path d="M5.5 3.5A.5.5 0 0 1 6 3h1a.5.5 0 0 1 .5.5v9a.5.5 0 0 1-.5.5H6a.5.5 0 0 1-.5-.5v-9zm4 0A.5.5 0 0 1 10 3h1a.5.5 0 0 1 .5.5v9a.5.5 0 0 1-.5.5h-1a.5.5 0 0 1-.5-.5v-9z"/>
</svg>
</div>
</div>
<div class="progress-bar-container">
<div class="progress-bar">
<div class="fill"></div>
</div>
<span id="current-time">0:00</span> / <span id="duration">0:00</span>
</div>
<div class="settings mt-3">
<label for="volume">Volume</label>
<input type="range" id="volume" class="form-range" min="0" max="1" step="0.1" value="1">
<label for="speed">Speed</label>
<input type="range" id="speed" class="form-range" min="0.5" max="2" step="0.1" value="1">
</div>
</div>
<script>
const audio = document.getElementById('audio');
const playIcon = document.getElementById('play-icon');
const pauseIcon = document.getElementById('pause-icon');
const progressBar = document.querySelector('.progress-bar');
const fill = document.querySelector('.progress-bar .fill');
const volume = document.getElementById('volume');
const speed = document.getElementById('speed');
const currentTime = document.getElementById('current-time');
const duration = document.getElementById('duration');
audio.addEventListener('loadeddata', () => {
duration.textContent = formatTime(audio.duration);
});
audio.addEventListener('timeupdate', () => {
const progress = (audio.currentTime / audio.duration) * 100;
fill.style.width = progress + '%';
currentTime.textContent = formatTime(audio.currentTime);
});
progressBar.addEventListener('click', (e) => {
const rect = progressBar.getBoundingClientRect();
const percentage = (e.clientX - rect.left) / rect.width;
audio.currentTime = percentage * audio.duration;
});
document.querySelector('.play-pause').addEventListener('click', () => {
if (audio.paused) {
audio.play();
playIcon.style.display = 'none';
pauseIcon.style.display = 'block';
} else {
audio.pause();
playIcon.style.display = 'block';
pauseIcon.style.display = 'none';
}
});
volume.addEventListener('input', () => {
audio.volume = volume.value;
});
speed.addEventListener('input', () => {
audio.playbackRate = speed.value;
});
function formatTime(seconds) {
const minutes = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60).toString().padStart(2, '0');
return `${minutes}:${secs}`;
}
</script>
</body>
</html>
Как использовать:
Замените sample.mp3 на вашу аудиозапись.
Этот код включает кастомные элементы SVG, Bootstrap 5 для стилей и ползунки для громкости и скорости.
Когда вы вставите этот код в свой HTML-документ, он будет работать в любом современном браузере.