feat: add mobile scaffold layout and dedicated mobile video player implementation

This commit is contained in:
Michael committed 2026-03-29 12:07:14 +02:00
1 parent 36a7658cf9
commit ddb8110c40
3 files changed
+201 -244

No files matched your search

+150 -192
View File
@@ -15,8 +15,7 @@
-webkit-tap-highlight-color: transparent;
}
html,
body {
html, body {
background: #000;
width: 100%;
height: 100%;
@@ -40,50 +39,6 @@
background: #000;
}
/* Mobile-only overlay buttons */
#mobile-on-screen-controls {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
pointer-events: none;
z-index: 10;
}
#play-overlay {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 80px;
height: 80px;
background: rgba(0, 0, 0, 0.6);
border-radius: 50%;
display: none;
justify-content: center;
align-items: center;
pointer-events: auto;
border: 2px solid rgba(255, 255, 255, 0.3);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
z-index: 25;
transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#play-overlay:active {
transform: translate(-50%, -50%) scale(0.9);
}
#play-overlay svg {
width: 40px;
height: 40px;
fill: white;
margin-left: 4px;
/* Adjust for play icon alignment */
}
#loading {
position: absolute;
display: flex;
@@ -105,9 +60,33 @@
}
@keyframes spin {
to {
transform: rotate(360deg);
}
to { transform: rotate(360deg); }
}
/* Unmute button — shown when iOS plays muted */
#unmute-btn {
display: none;
position: absolute;
bottom: 32px;
left: 50%;
transform: translateX(-50%);
z-index: 30;
background: rgba(0, 0, 0, 0.75);
color: white;
border: 2px solid rgba(255, 255, 255, 0.6);
border-radius: 32px;
padding: 12px 28px;
font-size: 16px;
font-weight: 600;
letter-spacing: 0.5px;
cursor: pointer;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
pointer-events: auto;
}
#unmute-btn:active {
background: rgba(255, 255, 255, 0.2);
}
#error {
@@ -127,18 +106,11 @@
<body>
<div id="player-container">
<!-- iOS/Safari core attributes: playsinline, webkit-playsinline, preload -->
<video id="video" autoplay playsinline webkit-playsinline preload="auto"></video>
<!-- muted + autoplay: iOS Safari autorise l'autoplay uniquement si muted -->
<video id="video" autoplay muted playsinline webkit-playsinline preload="auto"></video>
<div id="mobile-on-screen-controls">
<!-- Play Overlay for Safari/Autoplay blocks -->
<div id="play-overlay">
<svg viewBox="0 0 24 24">
<path d="M8 5v14l11-7z" />
</svg>
</div>
</div>
<!-- Bouton son — affiché après démarrage muted sur iOS -->
<button id="unmute-btn">🔇 Appuyer pour activer le son</button>
<div id="loading">
<div class="spinner"></div>
@@ -148,15 +120,14 @@
<div id="error">
<div style="font-size: 40px; margin-bottom: 12px;">⚠️</div>
<div id="err-msg" style="font-weight: 600;">Erreur de lecture</div>
<div style="font-size: 12px; color: rgba(255,255,255,0.6); margin-top: 8px;">Format non supporté ou lien
expiré</div>
<div id="err-sub" style="font-size: 12px; color: rgba(255,255,255,0.6); margin-top: 8px;">Vérifiez votre connexion</div>
</div>
</div>
<script>
const video = document.getElementById('video');
const loading = document.getElementById('loading');
const playOverlay = document.getElementById('play-overlay');
const unmuteBtn = document.getElementById('unmute-btn');
const error = document.getElementById('error');
const params = new URLSearchParams(window.location.search);
@@ -165,195 +136,182 @@
function log(m) { console.log('[MobilePlayer] ' + m); }
let safariRetryCount = 0;
const safariMaxRetries = 3;
let isSafariMode = false;
let retryCount = 0;
const maxRetries = 3;
function showError(msg) {
function showError(code, msg) {
loading.style.display = 'none';
playOverlay.style.display = 'none';
unmuteBtn.style.display = 'none';
error.style.display = 'block';
document.getElementById('err-msg').textContent = msg;
document.getElementById('err-msg').textContent = 'Erreur ' + code;
document.getElementById('err-sub').textContent = msg || 'Format non supporté ou lien expiré';
}
playOverlay.addEventListener('click', (e) => {
// Bouton son : user gesture DIRECT dans l'iframe → iOS accepte le unmute
unmuteBtn.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
log('Manual play triggered');
video.play();
playOverlay.style.display = 'none';
video.muted = false;
video.volume = 1.0;
unmuteBtn.style.display = 'none';
log('Unmuted by user');
window.parent.postMessage({ type: 'unmuted' }, '*');
});
let lastTap = 0;
video.addEventListener('touchend', () => {
lastTap = Date.now();
window.parent.postMessage({ type: 'user_activity' }, '*');
});
video.addEventListener('playing', () => {
log('Video playing, muted=' + video.muted);
loading.style.display = 'none';
playOverlay.style.display = 'none';
safariRetryCount = 0;
});
video.addEventListener('pause', () => {
if (video.currentTime === 0 || video.paused) {
loading.style.display = 'none';
playOverlay.style.display = 'flex';
retryCount = 0;
// Si muted (iOS autoplay), afficher le bouton son
if (video.muted) {
unmuteBtn.style.display = 'block';
// Tenter de démueter automatiquement (fonctionne parfois après interaction)
video.muted = false;
if (video.muted) {
// iOS a refusé le unmute automatique — garder le bouton affiché
log('Unmute blocked by iOS, showing button');
} else {
unmuteBtn.style.display = 'none';
log('Auto-unmuted successfully');
}
}
});
video.addEventListener('error', () => {
const code = video.error?.code || 'unknown';
const code = video.error?.code || '?';
const msg = video.error?.message || '';
log('Video error - code: ' + code + ', message: ' + msg);
log('Video error code=' + code + ' msg=' + msg + ' retry=' + retryCount);
// Safari/iOS: auto-retry on transient errors
if (isSafariMode && safariRetryCount < safariMaxRetries) {
safariRetryCount++;
log('Safari retry ' + safariRetryCount + '/' + safariMaxRetries + ' in 2s');
if (retryCount < maxRetries) {
retryCount++;
log('Retry ' + retryCount + '/' + maxRetries + ' in 2s');
loading.style.display = 'flex';
error.style.display = 'none';
document.getElementById('l-text').textContent = 'Reconnexion ' + safariRetryCount + '/' + safariMaxRetries + '...';
setTimeout(loadSafariStream, 2000);
document.getElementById('l-text').textContent = 'Reconnexion ' + retryCount + '/' + maxRetries + '...';
setTimeout(startPlayback, 2000);
} else {
showError('Erreur ' + code + ': ' + (msg || 'Format non supporté ou lien expiré'));
showError(code, msg);
}
});
function loadSafariStream() {
function startPlayback() {
log('startPlayback: ' + streamUrl);
video.src = '';
video.load();
video.src = streamUrl;
video.load();
video.play().catch(() => {
log('Autoplay blocked by Safari, showing overlay');
loading.style.display = 'none';
playOverlay.style.display = 'flex';
video.play().catch(e => {
log('play() rejected: ' + e);
// Ne pas montrer erreur ici — laisser l'event error gérer
});
}
async function init() {
function initHlsJs() {
log('Using HLS.js');
const hls = new Hls({
maxBufferLength: 30,
maxMaxBufferLength: 60,
liveSyncDurationCount: 5,
liveMaxLatencyDurationCount: 10,
enableWorker: true,
lowLatencyMode: false,
nudgeOffset: 0.8,
nudgeMaxRetries: 10,
manifestLoadingRetryDelay: 1000,
levelLoadingRetryDelay: 1000
});
hls.loadSource(streamUrl);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
log('HLS manifest parsed');
video.play().catch(() => log('HLS autoplay blocked'));
});
hls.on(Hls.Events.ERROR, (e, d) => {
log('HLS error type=' + d.type + ' fatal=' + d.fatal);
if (d.fatal) {
if (d.type === Hls.ErrorTypes.NETWORK_ERROR) hls.startLoad();
else if (d.type === Hls.ErrorTypes.MEDIA_ERROR) hls.recoverMediaError();
else showError(d.type, 'Erreur HLS fatale');
}
});
}
function initMpegts() {
log('Using MpegTS');
const player = mpegts.createPlayer({
type: 'mpegts',
isLive: streamType === 'live',
url: streamUrl
}, {
enableWorker: true,
stashInitialSize: 512 * 1024,
enableStashBuffer: true,
liveBufferLatencyChasing: false,
maxStashSize: 30 * 1024 * 1024
});
player.on(mpegts.Events.ERROR, (type, detail) => {
log('MpegTS error type=' + type);
showError(type, JSON.stringify(detail));
});
player.attachMediaElement(video);
player.load();
player.play().catch(() => log('MpegTS autoplay blocked'));
}
function init() {
if (!streamUrl) {
log('No stream URL provided');
showError('No stream URL provided');
log('No stream URL');
showError('URL', 'Pas de lien de flux');
return;
}
log('Initing mobile player for: ' + streamUrl);
log('Stream type param: ' + streamType);
log('Init: ' + streamUrl + ' type=' + streamType);
const isHLS = streamUrl.toLowerCase().includes('m3u8');
const isTS = streamUrl.toLowerCase().endsWith('.ts');
log('Format detection - isHLS: ' + isHLS + ', isTS: ' + isTS);
log('isHLS=' + isHLS + ' isTS=' + isTS);
// Safari / iOS Native HLS
// iOS Safari — HLS natif avec muted autoplay
if (isHLS && video.canPlayType('application/vnd.apple.mpegurl')) {
log('Using native HLS (Safari/iOS)');
isSafariMode = true;
loadSafariStream();
log('iOS Safari native HLS (muted autoplay)');
startPlayback();
return;
}
// Android / Chrome - HLS.js
// Android/Chrome — HLS.js
if (isHLS && Hls.isSupported()) {
log('Using Hls.js optimized for mobile');
const hls = new Hls({
maxBufferLength: 60,
maxMaxBufferLength: 120,
liveSyncDurationCount: 10, // Buffer-First safety
liveMaxLatencyDurationCount: 20,
enableWorker: true,
lowLatencyMode: false,
nudgeOffset: 0.8,
nudgeMaxRetries: 30,
maxLiveSyncPlaybackRate: 1.1,
initialLiveManifestSize: 3,
abrEwmaDefaultEstimate: 1000000,
manifestLoadingRetryDelay: 1000,
levelLoadingRetryDelay: 1000
});
hls.loadSource(streamUrl);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
const checkBuffer = setInterval(() => {
if (video.buffered.length > 0 && video.buffered.end(0) > 1.5) {
clearInterval(checkBuffer);
video.play().catch(e => playOverlay.style.display = 'flex');
}
}, 200);
});
hls.on(Hls.Events.ERROR, (e, d) => {
log('HLS Error - type: ' + d.type + ', fatal: ' + d.fatal + ', details: ' + JSON.stringify(d.details));
if (d.fatal) {
log('Fatal error, attempting recovery...');
if (d.type === Hls.ErrorTypes.NETWORK_ERROR) {
log('Network error, restarting load');
hls.startLoad();
} else if (d.type === Hls.ErrorTypes.MEDIA_ERROR) {
log('Media error, recovering');
hls.recoverMediaError();
} else {
log('Unknown fatal error');
error.style.display = 'block';
document.getElementById('err-msg').textContent = 'Erreur HLS fatal: ' + d.type;
}
}
});
initHlsJs();
return;
}
// MpegTS Fallback
// MpegTS fallback
if (mpegts.isSupported()) {
log('Using MpegTS optimized for mobile');
const player = mpegts.createPlayer({
type: 'mpegts',
isLive: streamType === 'live',
url: streamUrl
}, {
enableWorker: true,
stashInitialSize: 512 * 1024,
enableStashBuffer: true,
liveBufferLatencyChasing: false,
maxStashSize: 30 * 1024 * 1024
});
player.on(mpegts.Events.ERROR, (type, detail) => {
log('MpegTS Error - type: ' + type + ', detail: ' + JSON.stringify(detail));
error.style.display = 'block';
document.getElementById('err-msg').textContent = 'Erreur MpegTS: ' + type;
});
player.attachMediaElement(video);
player.load();
const checkBuffer = setInterval(() => {
if (video.buffered.length > 0 && video.buffered.end(0) > 1.0) {
clearInterval(checkBuffer);
player.play().catch(e => {
log('MpegTS play error: ' + e);
playOverlay.style.display = 'flex';
});
}
}, 200);
initMpegts();
return;
}
// Direct play with play overlay fallback
video.src = streamUrl;
video.load();
video.play().catch(e => playOverlay.style.display = 'flex');
// Direct fallback
log('Direct fallback');
startPlayback();
}
// Communication with Flutter
// Messages depuis Flutter
window.addEventListener('message', (e) => {
const d = e.data;
if (d.type === 'play') video.play().catch(() => playOverlay.style.display = 'flex');
if (!d) return;
if (d.type === 'play') video.play().catch(() => {});
if (d.type === 'pause') video.pause();
if (d.type === 'set_volume') {
video.muted = d.value === 0;
video.volume = d.value;
if (d.value > 0) unmuteBtn.style.display = 'none';
}
});
init();
</script>
</body>
</html>
</html>