vers. 2.4.1
This commit is contained in:
56
js/app.js
56
js/app.js
@@ -7,6 +7,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
let currentXHR = null;
|
||||
let isLoading = false;
|
||||
let loadingOverlay = null;
|
||||
let metadataInterval = null;
|
||||
|
||||
// WeakMap per tracciare i listener degli elementi
|
||||
const linkListeners = new WeakMap();
|
||||
@@ -56,6 +57,12 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
function cleanupPlayer() {
|
||||
console.log('Pulizia player audio...');
|
||||
|
||||
// Stop metadata updates
|
||||
if (metadataInterval) {
|
||||
clearInterval(metadataInterval);
|
||||
metadataInterval = null;
|
||||
}
|
||||
|
||||
// Distruggi istanza HLS
|
||||
if (hlsInstance) {
|
||||
try {
|
||||
@@ -588,6 +595,55 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
// Setup Media Session
|
||||
setupMediaSession(stationName, playPauseBtn.getAttribute('data-station-slogan'), playPauseBtn.getAttribute('data-station-logo'), playIcon, pauseIcon);
|
||||
|
||||
// --- GESTIONE METADATI (Now Playing) ---
|
||||
const apiUrl = playPauseBtn.getAttribute('data-api-url');
|
||||
if (apiUrl) {
|
||||
console.log('Starting metadata polling for:', apiUrl);
|
||||
|
||||
function updateMetadata() {
|
||||
fetch(apiUrl)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.now_playing && data.now_playing.song) {
|
||||
const song = data.now_playing.song;
|
||||
|
||||
// Aggiorna DOM
|
||||
const songsEl = document.getElementById('songs');
|
||||
const artistEl = document.getElementById('artist');
|
||||
const albumArtEl = document.getElementById('albumsong');
|
||||
|
||||
if (songsEl) songsEl.textContent = song.title;
|
||||
if (artistEl) artistEl.textContent = song.artist;
|
||||
if (albumArtEl && song.art) {
|
||||
// Evita refresh se l'immagine è la stessa
|
||||
if (albumArtEl.src !== song.art) {
|
||||
albumArtEl.src = song.art;
|
||||
}
|
||||
}
|
||||
|
||||
// Aggiorna Media Session
|
||||
if ('mediaSession' in navigator) {
|
||||
navigator.mediaSession.metadata = new MediaMetadata({
|
||||
title: song.title,
|
||||
artist: song.artist,
|
||||
album: stationName,
|
||||
artwork: [
|
||||
{ src: song.art || playPauseBtn.getAttribute('data-station-logo'), sizes: '512x512', type: 'image/png' }
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(err => console.error('Error fetching metadata:', err));
|
||||
}
|
||||
|
||||
// Chiamata immediata
|
||||
updateMetadata();
|
||||
|
||||
// Polling ogni 10 secondi
|
||||
metadataInterval = setInterval(updateMetadata, 10000);
|
||||
}
|
||||
|
||||
console.log('Player System Ready with format toggle.');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user