-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
89 lines (79 loc) · 3.04 KB
/
script.js
File metadata and controls
89 lines (79 loc) · 3.04 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
document.addEventListener("DOMContentLoaded", () => {
const audioFolderInput = document.getElementById("audio-folder");
const audioFileSelect = document.getElementById("audio-file");
const playButton = document.getElementById("play-button");
const pauseButton = document.getElementById("pause-button");
const stopButton = document.getElementById("stop-button");
const volumeSlider = document.getElementById("volume-slider");
const playSchedule = document.getElementById("play-schedule");
const scheduleButton = document.getElementById("schedule-button");
const statusText = document.getElementById("status");
let audio = new Audio();
let scheduledTime = null;
// Load files from selected folder
audioFolderInput.addEventListener("change", (event) => {
audioFileSelect.innerHTML = "<option value=''>Select a file...</option>";
Array.from(event.target.files).forEach(file => {
if (file.type.startsWith("audio/")) {
const option = document.createElement("option");
option.value = URL.createObjectURL(file);
option.textContent = file.name;
audioFileSelect.appendChild(option);
}
});
});
// Load selected audio file
audioFileSelect.addEventListener("change", () => {
if (audioFileSelect.value) {
audio.src = audioFileSelect.value;
audio.load();
playButton.disabled = false;
}
});
// Play audio
playButton.addEventListener("click", () => {
audio.play();
statusText.textContent = "Playing...";
playButton.disabled = true;
pauseButton.disabled = false;
stopButton.disabled = false;
});
// Pause audio
pauseButton.addEventListener("click", () => {
audio.pause();
statusText.textContent = "Paused.";
playButton.disabled = false;
pauseButton.disabled = true;
});
// Stop audio
stopButton.addEventListener("click", () => {
audio.pause();
audio.currentTime = 0;
statusText.textContent = "Stopped.";
playButton.disabled = false;
pauseButton.disabled = true;
stopButton.disabled = true;
});
// Volume control
volumeSlider.addEventListener("input", (event) => {
audio.volume = event.target.value;
});
// Schedule playback
scheduleButton.addEventListener("click", () => {
const time = playSchedule.value;
if (time) {
const [hours, minutes] = time.split(":").map(Number);
scheduledTime = new Date();
scheduledTime.setHours(hours, minutes, 0);
statusText.textContent = `Playback scheduled at ${time}.`;
}
});
// Check scheduled playback every second
setInterval(() => {
if (scheduledTime && new Date() >= scheduledTime) {
audio.play();
statusText.textContent = "Playing scheduled audio...";
scheduledTime = null; // Clear schedule after playing
}
}, 1000);
});