let isPlaying = false; let currentSong = ''; let isFirstLoad = true; const audio = new Audio('https://azura.servercast.com.br/listen/radio-novacast/stream' + '?nocache=' + new Date().getTime()); const playButton = document.getElementById('playButton'); const volumeSlider = document.getElementById('volumeSlider'); const playIcon = document.getElementById('playIcon'); const volumeIcon = document.getElementById('volumeIcon'); const artistName = document.getElementById('artist'); const songTitle = document.getElementById('song'); playButton.addEventListener('click', () => { if (isPlaying) { audio.pause(); playIcon.className = 'bi bi-play-fill'; } else { audio.src = 'https://azura.servercast.com.br/listen/radio-novacast/stream' + '?nocache=' + new Date().getTime(); audio.play(); playIcon.className = 'bi bi-stop-fill'; } isPlaying = !isPlaying; }); volumeSlider.addEventListener('input', (e) => { const volume = e.target.value / 100; audio.volume = volume; if (volume === 0) { volumeIcon.className = 'bi bi-volume-mute-fill'; } else if (volume < 0.5) { volumeIcon.className='bi bi-volume-down-fill' ; } else { volumeIcon.className='bi bi-volume-up-fill' ; } }); function updateMetadata() { $.ajax({ url: 'https://azura.servercast.com.br/api/nowplaying/23' , dataType: 'json' , success: function(data) { if (data && data.now_playing && data.now_playing.song) { const newArtist=data.now_playing.song.artist; const newTitle=data.now_playing.song.title; if (currentSong !==`${newArtist} - ${newTitle}` || isFirstLoad) { currentSong=`${newArtist} - ${newTitle}`; artistName.textContent=newArtist; songTitle.textContent=newTitle; isFirstLoad=false; } } else { songTitle.textContent='Transmissão Online' ; artistName.textContent=data.station.name || 'Rádio Desconhecida' ; } }, error: function(xhr, status, error) { console.error('Error fetching metadata:', error); songTitle.textContent='Não foi possível obter os dados' ; artistName.textContent='Tente novamente' ; } }); } updateMetadata(); setInterval(updateMetadata, 25000);