-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
50 lines (41 loc) · 1.53 KB
/
Copy pathscripts.js
File metadata and controls
50 lines (41 loc) · 1.53 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
const waveformContainer = document.getElementById('waveform');
const audioFileInput = document.getElementById('audio-input');
const playButton = document.getElementById('play-button');
const stopButton = document.getElementById('stop-button');
const wavesurfer = WaveSurfer.create({
container: waveformContainer,
});
audioFileInput.addEventListener('change', (event) => {
const playIcon = playButton.querySelector('i') || playButton;
playIcon.classList.remove('fa-pause');
playIcon.classList.add('fa-play');
const files = event.target.files;
if(!files || !files[0]) {
return;
}
const fileUrl = URL.createObjectURL(files[0]);
wavesurfer.load(fileUrl);
});
playButton.addEventListener('click', () => {
const playIcon = playButton.querySelector('i') || playButton;
if (wavesurfer.isPlaying()) {
wavesurfer.pause();
playIcon.classList.remove('fa-pause');
playIcon.classList.add('fa-play');
} else {
wavesurfer.play();
playIcon.classList.remove('fa-play');
playIcon.classList.add('fa-pause');
}
});
stopButton.addEventListener('click', () => {
const playIcon = playButton.querySelector('i') || playButton;
wavesurfer.stop()
playIcon.classList.remove('fa-pause');
playIcon.classList.add('fa-play');
});
wavesurfer.on('finish', () => {
const playIcon = playButton.querySelector('i') || playButton;
playIcon.classList.remove('fa-pause');
playIcon.classList.add('fa-play');
});