-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.html
More file actions
273 lines (236 loc) · 6.95 KB
/
Copy pathtemp.html
File metadata and controls
273 lines (236 loc) · 6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!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 with Waveform</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
body {
font-family: Arial, sans-serif;
background-color: #fff;
color: #333;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.progress-bar{
border-radius: 2px;
}
.audio-player {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
width: 90%;
max-width: 800px;
}
/* Waveform Container */
#waveform {
width: 100%;
height: 128px;
background-color: #f1f1f1;
margin-bottom: 20px;
border-radius: 5px;
}
.controls {
display: flex;
align-items: center;
justify-content: space-between;
width: 350px;
margin-top: 10px;
}
.controls button {
background: none;
border: none;
color: #333;
font-size: 24px;
cursor: pointer;
margin: 0 15px;
}
.controls button:hover {
color: #1DB954;
}
/* Progress Bar and Time Controls */
.time-bar-container {
display: flex;
align-items: center;
justify-content: center; /* Center horizontally */
width: 100%;
margin-top: 20px;
}
.time-bar {
display: flex;
align-items: center;
justify-content: space-between;
width: 80%;
margin: 0 10px;
position: relative;
}
.times {
font-size: 14px;
margin-left: 8px;
margin-right: 8px;
}
.progress-bar {
width: 100%;
height: 5px;
background: #ccc;
position: relative;
cursor: pointer;
}
.progress-bar div {
width: 0;
height: 100%;
background-color: #1DB954;
}
#progress{
border-radius: 2px;
}
/* Hidden dot until hover */
input[type="range"] {
-webkit-appearance: none;
appearance: none;
width: 100%;
background: transparent;
cursor: pointer;
position: absolute;
top: -7px;
z-index: 2;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
height: 12px;
width: 12px;
background: #1DB954;
border-radius: 50%;
transform: translateY(-50%);
opacity: 0;
transition: opacity 0.2s, transform 0.2s;
}
input[type="range"]::-moz-range-thumb {
height: 12px;
width: 12px;
background: #1DB954;
border-radius: 50%;
opacity: 0;
transition: opacity 0.2s, transform 0.2s;
}
/* Show dot only when hovering over the progress bar */
.progress-bar:hover{
opacity: 1;
transform: translateY(-150%); /* Move dot above the bar */
}
.progress-bar:hover{
opacity: 1;
transform: translateY(-150%);
}
</style>
</head>
<body>
<div class="audio-player">
<!-- Waveform -->
<div id="waveform"></div>
<!-- Controls -->
<div class="controls">
<button id="decreaseSpeedBtn"><i class="fas fa-backward"></i></button>
<button id="playPauseBtn"><i class="fas fa-play"></i></button>
<button id="increaseSpeedBtn"><i class="fas fa-forward"></i></button>
<span class="speed-multiplier" id="speedMultiplier">1.0x</span>
</div>
<!-- Time Bar and Progress -->
<div class="time-bar-container">
<span class="times" id="currentTime">0:00</span>
<div class="time-bar">
<input type="range" id="progressBar" value="0" min="0" step="1">
<div class="progress-bar">
<div id="progress"></div>
</div>
</div>
<span class="times" id="durationTime">0:00</span>
</div>
</div>
<script src="https://unpkg.com/wavesurfer.js"></script>
<script>
var wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: '#a0c4ff',
progressColor: '#1DB954',
cursorColor: '#1DB954',
barWidth: 2,
height: 128,
});
wavesurfer.load('https://cdn1.suno.ai/0bc3dcfd-d4ff-4d71-975d-4e7ba4f2a421.mp3');
const playPauseBtn = document.getElementById("playPauseBtn");
const decreaseSpeedBtn = document.getElementById("decreaseSpeedBtn");
const increaseSpeedBtn = document.getElementById("increaseSpeedBtn");
const speedMultiplierDisplay = document.getElementById("speedMultiplier");
const currentTimeSpan = document.getElementById("currentTime");
const durationTimeSpan = document.getElementById("durationTime");
const progressBar = document.getElementById("progressBar");
const progress = document.getElementById("progress");
let isPlaying = false;
let playbackRate = 1.0;
playPauseBtn.addEventListener("click", () => {
if (isPlaying) {
wavesurfer.pause();
playPauseBtn.innerHTML = '<i class="fas fa-play"></i>';
} else {
wavesurfer.play();
playPauseBtn.innerHTML = '<i class="fas fa-pause"></i>';
}
isPlaying = !isPlaying;
});
decreaseSpeedBtn.addEventListener("click", () => {
playbackRate = Math.max(0.5, playbackRate - 0.1); // Set minimum speed to 0.5x
wavesurfer.setPlaybackRate(playbackRate);
updateSpeedDisplay();
});
increaseSpeedBtn.addEventListener("click", () => {
playbackRate = Math.min(2.0, playbackRate + 0.1); // Set maximum speed to 2.0x
wavesurfer.setPlaybackRate(playbackRate);
updateSpeedDisplay();
});
function updateSpeedDisplay() {
speedMultiplierDisplay.textContent = playbackRate.toFixed(1) + 'x';
}
wavesurfer.on('audioprocess', () => {
const currentTime = wavesurfer.getCurrentTime();
const duration = wavesurfer.getDuration();
progressBar.max = duration;
progressBar.value = currentTime;
progress.style.width = (currentTime / duration) * 100 + '%';
currentTimeSpan.textContent = formatTime(currentTime);
durationTimeSpan.textContent = formatTime(duration);
});
// Sync progress bar on seek
progressBar.addEventListener("input", () => {
wavesurfer.seekTo(progressBar.value / progressBar.max);
});
// Scrubbing functionality on waveform
wavesurfer.on('seek', () => {
const currentTime = wavesurfer.getCurrentTime();
const duration = wavesurfer.getDuration();
progressBar.value = currentTime;
progress.style.width = (currentTime / duration) * 100 + '%';
currentTimeSpan.textContent = formatTime(currentTime);
});
// Format time into minutes and seconds
function formatTime(time) {
const minutes = Math.floor(time / 60);
const seconds = Math.floor(time % 60);
return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
}
// Set duration when the audio is ready
wavesurfer.on('ready', () => {
durationTimeSpan.textContent = formatTime(wavesurfer.getDuration());
});
</script>
</body>
</html>