const playPauseBtn = document.getElementById('playPauseBtn'); const volumeControl = document.getElementById('volumeControl'); const muteBtn = document.getElementById('muteBtn'); const albumCover = document.getElementById('albumCover'); const songTitle = document.getElementById('songTitle'); const artistName = document.getElementById('artistName'); const lyricsBtn = document.getElementById('lyricsBtn'); const lyricsModal = new bootstrap.Modal(document.getElementById('lyricsModal')); const lyricsContent = document.getElementById('lyricsContent'); const pedidoBtn = document.getElementById('pedidoBtn'); const pedidoModal = new bootstrap.Modal(document.getElementById('pedidoModal')); const pedidoContent = document.getElementById('pedidoContent'); const emailBtn = document.getElementById('emailBtn'); const emailModal = new bootstrap.Modal(document.getElementById('emailModal')); const emailContent = document.getElementById('emailContent'); const progBtn = document.getElementById('progBtn'); const progModal = new bootstrap.Modal(document.getElementById('progModal')); const progContent = document.getElementById('progContent'); const sobreBtn = document.getElementById('sobreBtn'); const sobreModal = new bootstrap.Modal(document.getElementById('sobreModal')); const sobreContent = document.getElementById('sobreContent'); const colorThief = new ColorThief(); const streamUrl = 'https://azura.servercast.com.br/listen/radio-novacast/stream'; let audioElement = null; let isMuted = false; let previousVolume = 1; let currentSong = ''; let isFirstLoad = true; let lastAlbumCoverUrl = ''; let recentSongs = []; const MAX_RECENT_SONGS = 7; const lastfmApiKey = ''; playPauseBtn.addEventListener('click', togglePlay); volumeControl.addEventListener('input', updateVolume); muteBtn.addEventListener('click', toggleMute); lyricsBtn.addEventListener('click', showLyrics); pedidoBtn.addEventListener('click', showPedido); emailBtn.addEventListener('click', showEmail); progBtn.addEventListener('click', showProg); sobreBtn.addEventListener('click', showSobre); function togglePlay() { if (!audioElement) { startNewStream(); } else if (audioElement.paused) { startNewStream(); } else { audioElement.pause(); audioElement.src = ''; audioElement = null; playPauseBtn.innerHTML = ''; } } function startNewStream() { if (audioElement) { audioElement.pause(); audioElement.src = ''; } audioElement = new Audio(); audioElement.src = streamUrl + '?nocache=' + new Date().getTime(); audioElement.volume = isMuted ? 0 : volumeControl.value / 100; audioElement.play(); playPauseBtn.innerHTML = ''; } function updateVolume() { if (audioElement) { audioElement.volume = volumeControl.value / 100; if (isMuted && volumeControl.value > 0) { toggleMute(); } } updateMuteButtonIcon(); } function toggleMute() { isMuted = !isMuted; if (audioElement) { if (isMuted) { previousVolume = audioElement.volume; audioElement.volume = 0; volumeControl.value = 0; } else { audioElement.volume = previousVolume; volumeControl.value = previousVolume * 100; } } updateMuteButtonIcon(); } function updateMuteButtonIcon() { if (isMuted || volumeControl.value == 0) { muteBtn.innerHTML = ''; } else if (volumeControl.value < 50) { muteBtn.innerHTML='' ; } else { muteBtn.innerHTML='' ; } } // Add this function to update the recent songs list function updateRecentSongs(artist, title, albumArt) { const newSong={ artist, title, albumArt }; recentSongs.unshift(newSong); if (recentSongs.length> MAX_RECENT_SONGS) { recentSongs.pop(); } displayRecentSongs(); } // Add this function to display the recent songs function displayRecentSongs() { const recentSongsList = document.getElementById('recentSongsList'); recentSongsList.innerHTML = ''; recentSongs.forEach(song => { const songItem = document.createElement('div'); songItem.className = 'recent-song-item'; songItem.innerHTML = ` ${song.title} - ${song.artist}
${song.artist}
${song.title}
`; recentSongsList.appendChild(songItem); }); } 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; fetchAlbumCover(newArtist, 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'; } }); } function fetchAlbumCover(artist, track) { const searchTerm = encodeURIComponent(`${artist} - ${track}`); const url = `https://itunes.apple.com/search?term=${searchTerm}&media=music&limit=1`; $.ajax({ url: url, dataType: 'jsonp', success: function(data) { if (data.results && data.results.length > 0) { const artworkUrl = data.results[0].artworkUrl100.replace('100x100', '600x600'); if (artworkUrl !== lastAlbumCoverUrl) { lastAlbumCoverUrl = artworkUrl; fadeImage(artworkUrl); updateRecentSongs(artist, track, artworkUrl); } } else { setDefaultCover(); updateRecentSongs(artist, track, './img/logo.png?v=1738752413'); } }, error: function(xhr, status, error) { console.error('Error fetching iTunes data:', error); setDefaultCover(); updateRecentSongs(artist, track, './img/logo.png?v=1738752413'); } }); } function setDefaultCover() { if (lastAlbumCoverUrl !== './img/logo.png?v=1738752413') { lastAlbumCoverUrl = './img/logo.png?v=1738752413'; fadeImage(lastAlbumCoverUrl); } } function fadeImage(newSrc) { albumCover.style.opacity = 0; setTimeout(() => { albumCover.src = newSrc; albumCover.style.opacity = 1; albumCover.onload = () => { updateBackgroundColor(); }; }, 300); } function updateBackgroundColor() { if (albumCover.complete && albumCover.naturalHeight !== 0) { try { const dominantColor = colorThief.getColor(albumCover); const [r, g, b] = dominantColor; document.body.style.backgroundColor = `rgba(${r}, ${g}, ${b}, 0.9)`; } catch (error) { console.error('Error getting dominant color:', error); document.body.style.backgroundColor = 'rgba(240, 240, 240, 0.9)'; } } else { console.error('Image not fully loaded'); document.body.style.backgroundColor = 'rgba(240, 240, 240, 0.9)'; } } albumCover.addEventListener('load', updateBackgroundColor); albumCover.addEventListener('error', () => { console.error('Error loading image'); document.body.style.backgroundColor = 'rgba(240, 240, 240, 0.9)'; }); function showLyrics() { const artist = artistName.textContent; const title = songTitle.textContent; fetchLyrics(artist, title); lyricsModal.show(); } function showPedido() { pedidoModal.show(); } function showHistorico() { historicoModal.show(); } function showEmail() { emailModal.show(); } function showProg() { progModal.show(); } function showSobre() { sobreModal.show(); } async function fetchLyrics(artist, title) { lyricsContent.textContent = 'Carregando letra...'; const url = `https://api.lyrics.ovh/v1/${encodeURIComponent(artist)}/${encodeURIComponent(title)}`; try { const response = await fetch(url); const data = await response.json(); if (data && data.lyrics) { lyricsContent.innerHTML = data.lyrics.replace(/\n/g, '
'); } else { lyricsContent.textContent = 'Letra não encontrada para esta música.'; } } catch (error) { console.error('Error fetching lyrics:', error); lyricsContent.textContent = 'Não foi possível carregar a letra. Por favor, tente novamente mais tarde.'; } } updateMetadata(); setInterval(updateMetadata, 25000); updateMuteButtonIcon(); // Background animation const canvas = document.getElementById('backgroundCanvas'); const ctx = canvas.getContext('2d'); // Set canvas size function resizeCanvas() { canvas.width = window.innerWidth; canvas.height = window.innerHeight; } window.addEventListener('resize', resizeCanvas); resizeCanvas(); // Ball class class Ball { constructor() { this.x = Math.random() * canvas.width; this.y = Math.random() * canvas.height; this.size = Math.random() * 5 + 1; this.speedX = Math.random() * 1 - 0.5; this.speedY = Math.random() * 1 - 0.5; } update() { this.x += this.speedX; this.y += this.speedY; if (this.x > canvas.width || this.x < 0) { this.speedX=-this.speedX; } if (this.y> canvas.height || this.y < 0) { this.speedY=-this.speedY; } } draw() { ctx.fillStyle='rgba(255, 255, 255, 0.5)' ; ctx.beginPath(); ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2); ctx.closePath(); ctx.fill(); } } const balls=[]; for (let i=0; i < 50; i++) { balls.push(new Ball()); } function animate() { ctx.clearRect(0, 0, canvas.width, canvas.height); balls.forEach(ball=> { ball.update(); ball.draw(); }); requestAnimationFrame(animate); } animate(); document.addEventListener('DOMContentLoaded', (event) => { const videoModal = new bootstrap.Modal(document.getElementById('videoModal')); const videoContainer = document.getElementById('video-container'); // URL do vídeo que será carregado no modal const videoLink = 'https://www.youtube.com/embed/ByED80IKdIU?si=hXTX8wjr3EDXK5MA'; // Mostrar o modal após xx segundos setTimeout(() => { videoContainer.innerHTML = ``; videoModal.show(); }, 3000); // Limpar o vídeo ao fechar o modal document.getElementById('videoModal').addEventListener('hidden.bs.modal', () => { videoContainer.innerHTML = ''; }); });