-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvc.js
More file actions
31 lines (27 loc) · 953 Bytes
/
Copy pathvc.js
File metadata and controls
31 lines (27 loc) · 953 Bytes
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
document.addEventListener('DOMContentLoaded', function() {
var audio = document.getElementById('bg-music');
var playButton = document.getElementById('playButton');
// Set the initial time to 20 seconds
audio.currentTime = 20;
// Try to play the audio immediately if autoplay is allowed
var playPromise = audio.play();
if (playPromise !== undefined) {
playPromise.then(_ => {
// Autoplay started successfully
playButton.textContent = '⏸️';
}).catch(error => {
// Autoplay was prevented
console.log('Autoplay prevented:', error);
});
}
// Toggle playback with custom button
playButton.addEventListener('click', function() {
if (audio.paused) {
audio.play();
playButton.textContent = '⏸️';
} else {
audio.pause();
playButton.textContent = '🔊';
}
});
});