2023-10-02 10:49:28 +01:00
|
|
|
const audio = document.querySelector('#stream')
|
|
|
|
const playPauseButton = document.querySelector('[name="play-pause"]')
|
2024-02-28 18:36:23 +00:00
|
|
|
const playPauseButtonIcon = playPauseButton.querySelector('i.icon')
|
2023-10-02 10:49:28 +01:00
|
|
|
const volumeControl = document.querySelector('[name="volume"]')
|
|
|
|
const currentlyPlaying = document.querySelector('.currently-playing-title')
|
|
|
|
const volumeButton = document.querySelector('[name="mute"]')
|
2024-02-28 18:36:23 +00:00
|
|
|
const volumeButtonIcon = volumeButton.querySelector('i.icon')
|
2023-10-02 10:49:28 +01:00
|
|
|
|
|
|
|
let isPlaying = false
|
|
|
|
let fetchInterval = null
|
|
|
|
let currentVolume = 0.2
|
|
|
|
|
|
|
|
audio.volume = currentVolume
|
|
|
|
const adjustVolumeIcon = volume => {
|
2024-02-28 18:36:23 +00:00
|
|
|
volumeButtonIcon.classList.remove('icon-silenci')
|
|
|
|
volumeButtonIcon.classList.remove('icon-so')
|
2023-10-02 10:49:28 +01:00
|
|
|
|
|
|
|
if (volume === 0) {
|
2024-02-28 18:36:23 +00:00
|
|
|
volumeButtonIcon.classList.add('icon-silenci')
|
|
|
|
} else {
|
|
|
|
volumeButtonIcon.classList.add('icon-so')
|
|
|
|
}
|
2023-10-02 10:49:28 +01:00
|
|
|
}
|
|
|
|
volumeControl.addEventListener('input', () => {
|
|
|
|
const volume = parseFloat(volumeControl.value)
|
|
|
|
|
|
|
|
audio.volume = currentVolume = volume
|
|
|
|
currentVolume = volume
|
|
|
|
|
|
|
|
adjustVolumeIcon(volume)
|
|
|
|
})
|
|
|
|
|
|
|
|
volumeButton.addEventListener('click', () => {
|
|
|
|
if (audio.volume > 0) {
|
|
|
|
adjustVolumeIcon(0)
|
|
|
|
audio.volume = 0
|
|
|
|
volumeControl.value = 0
|
|
|
|
} else {
|
|
|
|
adjustVolumeIcon(currentVolume)
|
|
|
|
audio.volume = currentVolume
|
|
|
|
volumeControl.value = currentVolume
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
playPauseButton.addEventListener('click', () => {
|
|
|
|
if (isPlaying) {
|
|
|
|
audio.pause()
|
|
|
|
|
2024-02-28 18:36:23 +00:00
|
|
|
playPauseButtonIcon.classList.remove('icon-pausa')
|
|
|
|
playPauseButtonIcon.classList.add('icon-play')
|
2023-10-02 10:49:28 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
audio.play()
|
|
|
|
|
2024-02-28 18:36:23 +00:00
|
|
|
playPauseButtonIcon.classList.remove('icon-play')
|
|
|
|
playPauseButtonIcon.classList.add('icon-pausa')
|
2023-10-02 10:49:28 +01:00
|
|
|
}
|
|
|
|
isPlaying = !isPlaying
|
2024-02-28 18:36:23 +00:00
|
|
|
})
|