-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (29 loc) · 1.1 KB
/
script.js
File metadata and controls
33 lines (29 loc) · 1.1 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
document.addEventListener("DOMContentLoaded", async () => {
const stationSelect = document.getElementById("stationSelect");
const playButton = document.getElementById("playButton");
const stopButton = document.getElementById("stopButton");
const audioPlayer = document.getElementById("audioPlayer");
try {
const response = await fetch("radio_stations.json");
const stations = await response.json();
Object.keys(stations).forEach(name => {
const option = document.createElement("option");
option.value = stations[name];
option.textContent = name;
stationSelect.appendChild(option);
});
} catch (error) {
console.error("Error loading stations:", error);
}
playButton.addEventListener("click", () => {
const selectedStation = stationSelect.value;
if (selectedStation) {
audioPlayer.src = selectedStation;
audioPlayer.play();
}
});
stopButton.addEventListener("click", () => {
audioPlayer.pause();
audioPlayer.src = "";
});
});