feat: add basic play/pause web ui
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
const playBtn = document.getElementById("play-btn");
|
||||
|
||||
let isPlaying = false;
|
||||
let currentAudio;
|
||||
let volume = 1;
|
||||
|
||||
function playAudio() {
|
||||
currentAudio = new Audio("/current.mp3");
|
||||
currentAudio.onplay = () => {
|
||||
isPlaying = true;
|
||||
playBtn.innerText = "pause";
|
||||
};
|
||||
currentAudio.onpause = () => {
|
||||
isPlaying = false;
|
||||
playBtn.innerText = "play";
|
||||
};
|
||||
|
||||
currentAudio.volume = volume;
|
||||
|
||||
currentAudio.load();
|
||||
currentAudio.play();
|
||||
}
|
||||
|
||||
function pauseAudio() {
|
||||
currentAudio.pause();
|
||||
}
|
||||
|
||||
playBtn.onclick = () => {
|
||||
if (isPlaying) {
|
||||
pauseAudio();
|
||||
} else {
|
||||
playAudio();
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user