vers. 2.4.0

This commit is contained in:
2026-02-07 00:31:18 +01:00
parent 71af2b9407
commit 5b3e05726b
6 changed files with 202 additions and 8 deletions

122
js/app.js
View File

@@ -596,7 +596,127 @@ document.addEventListener('DOMContentLoaded', function () {
*/
function initializeTVPlayer() {
console.log('TV Player inizializzato');
// Implementare logica specifica per TV se necessario
const video = document.getElementById('tvVideoPlayer');
if (!video) {
console.log('Elemento video TV non trovato');
return;
}
// Cleanup istanza precedente se esiste
if (video.hlsInstance) {
video.hlsInstance.destroy();
delete video.hlsInstance;
}
const videoSrc = video.getAttribute('data-src');
console.log('Video Source:', videoSrc);
if (!videoSrc) {
console.error('Nessuna sorgente video specificata in data-src');
return;
}
// Creazione elemento per errori se non esiste già
let errorDisplay = video.parentNode.querySelector('.tv-error-display');
if (!errorDisplay) {
errorDisplay = document.createElement('div');
errorDisplay.className = 'tv-error-display';
errorDisplay.style.display = 'none';
errorDisplay.style.position = 'absolute';
errorDisplay.style.top = '50%';
errorDisplay.style.left = '50%';
errorDisplay.style.transform = 'translate(-50%, -50%)';
errorDisplay.style.backgroundColor = 'rgba(0, 0, 0, 0.8)';
errorDisplay.style.color = '#fff';
errorDisplay.style.padding = '20px';
errorDisplay.style.borderRadius = '8px';
errorDisplay.style.textAlign = 'center';
errorDisplay.style.zIndex = '2000';
errorDisplay.style.maxWidth = '90%';
if (video.parentNode) {
video.parentNode.appendChild(errorDisplay);
// Assicurati che il parent sia relative per il posizionamento absolute
if (getComputedStyle(video.parentNode).position === 'static') {
video.parentNode.style.position = 'relative';
}
}
}
function showError(msg, details) {
console.error(msg, details);
errorDisplay.innerHTML = '<strong>Errore:</strong><br>' + msg + (details ? '<br><small>' + details + '</small>' : '');
errorDisplay.style.display = 'block';
}
// Controllo libreria HLS
if (typeof Hls === 'undefined') {
// Riprova tra poco se magari sta ancora caricando
setTimeout(() => {
if (typeof Hls === 'undefined') {
showError('Libreria HLS non caricata correttamente.');
} else {
initializeTVPlayer(); // Riprova inizializzazione
}
}, 500);
return;
}
if (Hls.isSupported()) {
console.log('HLS Supported - Loading stream');
var hls = new Hls({
debug: false,
enableWorker: true
});
hls.loadSource(videoSrc);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, function () {
console.log('TV Manifest Parsed - Ready to play');
var playPromise = video.play();
if (playPromise !== undefined) {
playPromise.catch(error => {
console.log('Autoplay blocked or failed:', error);
});
}
});
// Gestione errori estesa
hls.on(Hls.Events.ERROR, function (event, data) {
console.warn('HLS Error:', data);
if (data.fatal) {
switch (data.type) {
case Hls.ErrorTypes.NETWORK_ERROR:
console.log('Network error, recovering...');
hls.startLoad();
break;
case Hls.ErrorTypes.MEDIA_ERROR:
console.log('Media error, recovering...');
hls.recoverMediaError();
break;
default:
showError('Errore fatale riproduzione.', data.type);
hls.destroy();
break;
}
}
});
video.hlsInstance = hls;
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
console.log('Native HLS Supported (Safari/iOS)');
video.src = videoSrc;
video.addEventListener('loadedmetadata', function () {
video.play().catch(e => console.log("Autoplay iOS prevented"));
});
video.addEventListener('error', function (e) {
showError('Errore riproduzione nativa.', e.message);
});
} else {
showError('Il tuo browser non supporta HLS.');
}
}
/**