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
+155 -198

No files matched your search

+22 -17
View File
@@ -55,19 +55,15 @@ class GlassContainer extends StatelessWidget {
final finalBgColor = backgroundColor ?? AppColors.glassBackground;
final finalBorderColor = borderColor ?? AppColors.glassBorder;
return Container(
width: width,
height: height,
margin: margin,
child: ClipRRect(
borderRadius: BorderRadius.circular(borderRadius),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: blur, sigmaY: blur),
child: Container(
// BackdropFilter is extremely expensive in Flutter Web on mobile Safari.
// On mobile web (width < 600), skip the blur entirely.
final screenWidth = MediaQuery.of(context).size.width;
final useBlur = blur > 0 && !(Theme.of(context).platform == TargetPlatform.iOS && screenWidth < 600);
final inner = Container(
padding: padding,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(borderRadius),
// Subtle gradient overlay for depth
gradient: showGradient
? LinearGradient(
begin: Alignment.topLeft,
@@ -78,13 +74,10 @@ class GlassContainer extends StatelessWidget {
],
)
: null,
color: showGradient ? null : finalBgColor.withOpacity(finalOpacity),
border: hasBorder
? Border.all(
color: finalBorderColor,
width: borderWidth,
)
? Border.all(color: finalBorderColor, width: borderWidth)
: null,
// Premium shadow
boxShadow: showShadow
? [
BoxShadow(
@@ -103,8 +96,20 @@ class GlassContainer extends StatelessWidget {
: [],
),
child: child,
),
),
);
return Container(
width: width,
height: height,
margin: margin,
child: ClipRRect(
borderRadius: BorderRadius.circular(borderRadius),
child: useBlur
? BackdropFilter(
filter: ImageFilter.blur(sigmaX: blur, sigmaY: blur),
child: inner,
)
: inner,
),
);
}
+2 -8
View File
@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:google_fonts/google_fonts.dart';
import 'dart:ui';
import '../../core/theme/app_colors.dart';
class MobileScaffold extends ConsumerWidget {
@@ -42,12 +41,9 @@ class MobileScaffold extends ConsumerWidget {
child,
],
),
bottomNavigationBar: ClipRRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),
child: Container(
bottomNavigationBar: Container(
decoration: BoxDecoration(
color: AppColors.surface.withOpacity(0.9),
color: AppColors.surface,
border: const Border(
top: BorderSide(
color: AppColors.border,
@@ -90,8 +86,6 @@ class MobileScaffold extends ConsumerWidget {
],
),
),
),
),
);
}
}
+131 -173
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,147 +136,111 @@
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() {
if (!streamUrl) {
log('No stream URL provided');
showError('No stream URL provided');
return;
}
log('Initing mobile player for: ' + streamUrl);
log('Stream type param: ' + streamType);
const isHLS = streamUrl.toLowerCase().includes('m3u8');
const isTS = streamUrl.toLowerCase().endsWith('.ts');
log('Format detection - isHLS: ' + isHLS + ', isTS: ' + isTS);
// Safari / iOS Native HLS
if (isHLS && video.canPlayType('application/vnd.apple.mpegurl')) {
log('Using native HLS (Safari/iOS)');
isSafariMode = true;
loadSafariStream();
return;
}
// Android / Chrome - HLS.js
if (isHLS && Hls.isSupported()) {
log('Using Hls.js optimized for mobile');
function initHlsJs() {
log('Using HLS.js');
const hls = new Hls({
maxBufferLength: 60,
maxMaxBufferLength: 120,
liveSyncDurationCount: 10, // Buffer-First safety
liveMaxLatencyDurationCount: 20,
maxBufferLength: 30,
maxMaxBufferLength: 60,
liveSyncDurationCount: 5,
liveMaxLatencyDurationCount: 10,
enableWorker: true,
lowLatencyMode: false,
nudgeOffset: 0.8,
nudgeMaxRetries: 30,
maxLiveSyncPlaybackRate: 1.1,
initialLiveManifestSize: 3,
abrEwmaDefaultEstimate: 1000000,
nudgeMaxRetries: 10,
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);
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 + ', details: ' + JSON.stringify(d.details));
log('HLS error type=' + d.type + ' fatal=' + d.fatal);
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;
}
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');
}
});
return;
}
// MpegTS Fallback
if (mpegts.isSupported()) {
log('Using MpegTS optimized for mobile');
function initMpegts() {
log('Using MpegTS');
const player = mpegts.createPlayer({
type: 'mpegts',
isLive: streamType === 'live',
@@ -317,39 +252,62 @@
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;
log('MpegTS error type=' + type);
showError(type, JSON.stringify(detail));
});
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';
});
player.play().catch(() => log('MpegTS autoplay blocked'));
}
}, 200);
function init() {
if (!streamUrl) {
log('No stream URL');
showError('URL', 'Pas de lien de flux');
return;
}
log('Init: ' + streamUrl + ' type=' + streamType);
const isHLS = streamUrl.toLowerCase().includes('m3u8');
const isTS = streamUrl.toLowerCase().endsWith('.ts');
log('isHLS=' + isHLS + ' isTS=' + isTS);
// iOS Safari — HLS natif avec muted autoplay
if (isHLS && video.canPlayType('application/vnd.apple.mpegurl')) {
log('iOS Safari native HLS (muted autoplay)');
startPlayback();
return;
}
// Direct play with play overlay fallback
video.src = streamUrl;
video.load();
video.play().catch(e => playOverlay.style.display = 'flex');
// Android/Chrome — HLS.js
if (isHLS && Hls.isSupported()) {
initHlsJs();
return;
}
// Communication with Flutter
// MpegTS fallback
if (mpegts.isSupported()) {
initMpegts();
return;
}
// Direct fallback
log('Direct fallback');
startPlayback();
}
// 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();