feat(design): Warm Cinema theme + event-driven adaptive players

Replaces the Projector Noir palette with "Warm Cinema" and rebuilds the
web players around a shared, event-driven engine.

Design
- app_colors: warm charcoal (#0B0908), cream (#F3E9DF), ember (#D9541F);
  adds posterScrim/heroScrim gradients, lift()/emberFocus() shadows,
  const cream-alpha tokens replacing Colors.whiteNN, and primaryFill,
  a deeper ember reserved for text-bearing fills so white labels clear
  the 4.5:1 AA threshold that #D9541F alone does not
- app_theme / mobile_theme: Fraunces (display serif) + Karla (body),
  tighter radii, 20+ component themes
- glass_container: opaque layered surfaces replace the blurred glass
- themed_loading_screen restyled; players and boot splash follow

Performance
- drop every BackdropFilter: backdrop blur forced a full framebuffer
  read per frame per card, the main source of scroll jank
- bundle Fraunces/Karla as assets so google_fonts stops fetching from
  fonts.gstatic.com at startup
- bound image decode size on 12 sites: a 40-poster grid drops from
  ~240 MB to a few tens of MB of GPU memory

Players (new shared engine: web/xf-player-core.js)
- start on media events instead of polling the buffer every 100-200 ms
- hls.js/mpegts.js loaded on demand, so ~213 KB of mpegts is never
  fetched for HLS streams
- liveSyncDurationCount 10 -> 2, startFragPrefetch on, testBandwidth
  off, MPEG-TS initial stash 512 KB -> 64 KB
- adaptive escalation fast -> balanced -> safe after repeated stalls in
  a 60 s window, applied live for HLS so there is no visible cut

Preserved from the recent streaming work on main: server-side quality
selection, stable player viewId, the turbo direct MPEG-TS path, vendored
library cache headers and the CI/Docker changes. Only the theme layer and
the player front-end were replaced; GlassCard stays in ui_components.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Opus 5 committed 2026-08-10 21:42:56 +02:00
1 parent e332895d7d
commit 1feeaae78a
49 files changed
+2341 -1751

No files matched your search

+83 -47
View File
@@ -1,25 +1,29 @@
<!DOCTYPE html>
<html>
<html lang="fr">
<head>
<base href="$FLUTTER_BASE_HREF">
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="XtremFlow - Modern IPTV Streaming Application">
<meta name="description" content="XtremFlow — streaming IPTV">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="XtremFlow">
<meta name="theme-color" content="#0A0E1A">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>XtremFlow IPTV</title>
<meta name="theme-color" content="#0B0908">
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>XtremFlow</title>
<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<link rel="manifest" href="manifest.json">
<style>
/* =============================================================
* Amorce « Warm Cinema » — charbon chaud, crème, braise.
* Aucune police web, aucun script tiers : rien ne retarde le boot.
* ============================================================= */
* {
margin: 0;
padding: 0;
@@ -27,16 +31,15 @@
}
body {
background: linear-gradient(135deg, #0B0A08 0%, #1B1812 100%);
background: radial-gradient(120% 90% at 22% 0%, #1A1310 0%, #0B0908 62%);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
font-family: 'Inter', 'Roboto', sans-serif;
overflow: hidden;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
/* Fullscreen mode - prevent scrollbars */
:fullscreen,
::backdrop {
overflow: hidden !important;
@@ -47,68 +50,101 @@
overflow: hidden !important;
}
.loading-container {
.boot {
text-align: center;
animation: fadeIn 0.5s ease-out;
animation: rise 620ms cubic-bezier(0.16, 1, 0.3, 1) both;
}
.logo {
font-size: 48px;
.mark {
font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
font-size: clamp(34px, 7vw, 58px);
font-weight: 600;
letter-spacing: 0.14em;
color: #F3E9DF;
text-transform: uppercase;
line-height: 1;
}
/* Le « W » d'XtremFlow porte la braise */
.mark em {
font-style: normal;
color: #D9541F;
}
/* Barre d'amorce : balayage lent, comme une pellicule qui se lance */
.leader {
position: relative;
width: min(240px, 56vw);
height: 2px;
margin: 26px auto 0;
background: rgba(243, 233, 223, 0.12);
overflow: hidden;
}
.leader::after {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 42%;
background: linear-gradient(90deg, transparent, #D9541F, transparent);
animation: wipe 1150ms cubic-bezier(0.5, 0, 0.5, 1) infinite;
}
.caption {
margin-top: 16px;
font-size: 10px;
font-weight: 700;
background: linear-gradient(135deg, #E8941A 0%, #FFC36A 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 24px;
letter-spacing: -1px;
letter-spacing: 0.32em;
text-transform: uppercase;
color: rgba(243, 233, 223, 0.38);
}
.spinner {
width: 40px;
height: 40px;
margin: 0 auto 16px;
border: 3px solid rgba(243, 154, 31, 0.2);
border-top-color: #F39A1F;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes wipe {
from {
transform: translateX(-100%);
}
.loading-text {
color: rgba(255, 255, 255, 0.7);
font-size: 14px;
font-weight: 500;
font-family: 'Outfit', sans-serif;
}
@keyframes spin {
to {
transform: rotate(360deg);
transform: translateX(340%);
}
}
@keyframes fadeIn {
@keyframes rise {
from {
opacity: 0;
transform: translateY(10px);
transform: translateY(12px);
}
to {
opacity: 1;
transform: translateY(0);
transform: none;
}
}
@media (prefers-reduced-motion: reduce) {
.boot,
.leader::after {
animation-duration: 2.4s;
}
}
</style>
</head>
<body>
<div class="loading-container">
<div class="logo">XtremFlow</div>
<div class="spinner"></div>
<div class="loading-text">Loading...</div>
<div class="boot">
<div class="mark">Xtrem<em>Flow</em></div>
<div class="leader"></div>
<div class="caption">Projection</div>
</div>
<!-- HLS.js for HLS video playback on Chrome/Firefox (vendored, pinned) -->
<script src="vendor/hls.min.js"></script>
<!--
hls.js n'est plus chargé ici. Il était récupéré depuis un CDN de façon
BLOQUANTE avant flutter_bootstrap.js alors qu'aucun code Dart ne
l'utilise : seuls les iframes de lecture en ont besoin, et elles le
chargent désormais elles-mêmes, en local et à la demande.
-->
<script src="flutter_bootstrap.js" async></script>
</body>
</html>
</html>
+71 -344
View File
@@ -1,128 +1,21 @@
<!DOCTYPE html>
<html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>XtremFlow Player</title>
<!-- Vendored, pinned player libraries (no CDN dependency) -->
<script src="vendor/hls.min.js"></script>
<script src="vendor/mpegts.min.js"></script>
<link rel="stylesheet" href="theme.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
html,
body {
background: var(--color-bg);
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#player-container {
width: 100%;
height: 100%;
position: relative;
}
#video {
width: 100%;
height: 100%;
background: var(--color-bg);
}
#error {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: var(--color-text);
text-align: center;
font-family: Arial, sans-serif;
z-index: 30;
}
#error-icon {
font-size: 64px;
color: var(--color-error);
margin-bottom: 16px;
}
#loading {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: var(--color-text);
text-align: center;
font-family: Arial, sans-serif;
z-index: 20;
}
.spinner {
width: 48px;
height: 48px;
border: 4px solid var(--color-border);
border-top-color: var(--color-accent);
border-radius: 50%;
animation: spin 1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
margin: 0 auto 16px;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
/* Safari Autoplay Hint Overlay */
#play-overlay {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 90px;
height: 90px;
background: var(--color-overlay);
border-radius: 50%;
display: none;
justify-content: center;
align-items: center;
cursor: pointer;
border: 2px solid var(--color-border);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
z-index: 25;
transition: transform 0.2s;
}
#play-overlay:active {
transform: translate(-50%, -50%) scale(0.9);
}
#play-overlay svg {
width: 44px;
height: 44px;
fill: white;
margin-left: 5px;
}
</style>
<!--
Les libs hls.js / mpegts.js ne sont PLUS chargées depuis un CDN ni de
façon bloquante : xf-player-core.js ne récupère que celle réellement
nécessaire au flux courant, en local. Deux requêtes bloquantes en moins
et environ 200 Ko de JS jamais téléchargés dans le cas courant.
-->
<link rel="stylesheet" href="xf-player.css">
<link rel="preload" href="vendor/hls.min.js" as="script">
</head>
<body>
<div id="player-container">
<!-- iOS/Safari core attributes -->
<video id="video" autoplay playsinline webkit-playsinline preload="auto"></video>
<div id="play-overlay">
@@ -131,247 +24,81 @@
</svg>
</div>
<div id="loading">
<div class="spinner"></div>
<div id="loading-text">Chargement du flux...</div>
<div id="loading" class="xf-center">
<div class="xf-leader">
<div class="xf-leader-cross"></div>
</div>
<div class="xf-label" id="loading-text">Ouverture du flux</div>
<div class="xf-hint" id="loading-hint"></div>
</div>
<div id="error">
<div id="error-icon">⚠</div>
<div id="error-message">Erreur de chargement</div>
<div id="error" class="xf-center">
<div class="xf-error-mark">!</div>
<div class="xf-error-title" id="error-message">Erreur de chargement</div>
<div class="xf-error-sub">Vérifiez le lien ou votre connexion</div>
</div>
</div>
<script src="xf-player-core.js"></script>
<script>
const video = document.getElementById('video');
const loading = document.getElementById('loading');
const loadingText = document.getElementById('loading-text');
const error = document.getElementById('error');
const errorMessage = document.getElementById('error-message');
const playOverlay = document.getElementById('play-overlay');
(function () {
var video = document.getElementById('video');
var loading = document.getElementById('loading');
var loadingText = document.getElementById('loading-text');
var loadingHint = document.getElementById('loading-hint');
var errorBox = document.getElementById('error');
var errorMessage = document.getElementById('error-message');
var playOverlay = document.getElementById('play-overlay');
const urlParams = new URLSearchParams(window.location.search);
let streamUrl = urlParams.get('url');
const startTime = parseFloat(urlParams.get('t') || '0');
const streamType = urlParams.get('type') || '';
const injectedDuration = parseFloat(urlParams.get('duration') || '0');
function log(msg) { console.log('[Player] ' + msg); }
function showLoading(msg) {
loading.style.display = 'block';
loadingText.textContent = msg || 'Chargement du flux...';
error.style.display = 'none';
}
function hideLoading() { loading.style.display = 'none'; }
function showError(message) {
hideLoading();
error.style.display = 'block';
errorMessage.textContent = message || 'Erreur de chargement';
playOverlay.style.display = 'none';
}
playOverlay.addEventListener('click', () => {
log('Manual play triggered');
video.play();
playOverlay.style.display = 'none';
});
video.addEventListener('loadedmetadata', () => {
if (startTime > 0 && startTime < video.duration) {
video.currentTime = startTime;
}
});
// Parent (Flutter app) is always same-origin: never broadcast to '*'
const PARENT_ORIGIN = window.location.origin;
let lastReportedTime = 0;
function reportPosition() {
if (video.currentTime > 0 && !video.paused && video.readyState > 2) {
if (Math.abs(video.currentTime - lastReportedTime) >= 1) {
lastReportedTime = video.currentTime;
let duration = video.duration;
const hlsDuration = window.currentHlsDuration || 0;
if (!isFinite(duration) || isNaN(duration) || duration < 1) {
duration = hlsDuration > 0 ? hlsDuration : (injectedDuration > 0 ? injectedDuration : 0);
} else if (hlsDuration > duration) {
duration = hlsDuration;
} else if (injectedDuration > 0 && duration < injectedDuration * 0.9) {
duration = injectedDuration;
}
window.parent.postMessage({ type: 'playback_position', currentTime: video.currentTime, duration: duration }, PARENT_ORIGIN);
}
}
}
setInterval(reportPosition, 5000);
video.addEventListener('pause', () => {
window.parent.postMessage({ type: 'playback_status', status: 'paused' }, PARENT_ORIGIN);
});
video.addEventListener('playing', () => {
window.parent.postMessage({ type: 'playback_status', status: 'playing' }, PARENT_ORIGIN);
hideLoading();
playOverlay.style.display = 'none';
});
video.addEventListener('ended', () => {
window.parent.postMessage({ type: 'playback_ended', duration: isFinite(video.duration) ? video.duration : injectedDuration }, PARENT_ORIGIN);
});
function reportActivity() { window.parent.postMessage({ type: 'user_activity' }, PARENT_ORIGIN); }
document.addEventListener('mousemove', reportActivity);
document.addEventListener('touchstart', reportActivity);
document.addEventListener('click', reportActivity);
window.addEventListener('message', (event) => {
if (event.origin !== window.location.origin) return;
const data = event.data;
if (!data) return;
switch (data.type) {
case 'play': video.play().catch(() => playOverlay.style.display = 'flex'); break;
case 'pause': video.pause(); break;
case 'seek': if (Number.isFinite(data.value)) video.currentTime = data.value; break;
case 'set_volume': video.volume = Math.max(0, Math.min(1, data.value)); video.muted = video.volume === 0; break;
}
});
async function playWithHLS(url) {
log('Trying HLS.js with: ' + url);
showLoading('Chargement HLS...');
if (!Hls.isSupported()) {
if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url;
video.load();
video.play().catch(() => {
loading.style.display = 'none';
playOverlay.style.display = 'flex';
});
return true;
}
return false;
function showLoading(msg) {
loading.style.display = 'block';
loadingText.textContent = msg || 'Ouverture du flux';
errorBox.style.display = 'none';
}
const isTurbo = urlParams.get('turbo') === 'true';
const isRecording = urlParams.get('is_recording') === 'true';
const hlsOptions = {
maxBufferLength: 120,
enableWorker: true,
nudgeOffset: 0.8, // More aggressive jump over corrupted frames
nudgeMaxRetries: 30,
maxLiveSyncPlaybackRate: 1.1, // Slower catch-up to avoid chaos
initialLiveManifestSize: 1, // Start as soon as one segment exists
abrEwmaDefaultEstimate: 1000000,
manifestLoadingRetryDelay: 1000,
levelLoadingRetryDelay: 1000
};
// Limit live sync only for actual LIVE IPTV, not recordings
if (!isRecording && streamType === 'live') {
hlsOptions.liveSyncDurationCount = 10;
hlsOptions.liveMaxLatencyDurationCount = 20;
function hideLoading() {
loading.style.display = 'none';
loadingHint.textContent = '';
}
const hls = new Hls(hlsOptions);
window.hlsInstance = hls;
hls.loadSource(url);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
function showError(msg) {
hideLoading();
// Wait for a small buffer before playing to avoid chaos
const checkBuffer = setInterval(() => {
if (video.buffered.length > 0) {
const bufferEnd = video.buffered.end(0);
if (bufferEnd > 0.8) { // Start fast, hls.js keeps buffering
clearInterval(checkBuffer);
video.play().catch(() => playOverlay.style.display = 'flex');
}
}
}, 100);
});
hls.on(Hls.Events.LEVEL_LOADED, (e, d) => {
if (d.details && d.details.totalduration > injectedDuration) window.currentHlsDuration = d.details.totalduration;
});
hls.on(Hls.Events.ERROR, (e, d) => {
if (d.fatal) {
if (d.type === Hls.ErrorTypes.NETWORK_ERROR) hls.startLoad();
else if (d.type === Hls.ErrorTypes.MEDIA_ERROR) hls.recoverMediaError();
else showError('HLS Error: ' + d.details);
}
});
return true;
}
async function playWithMpegTS(url, isLive = true) {
log('Trying mpegts.js with: ' + url);
showLoading('Chargement MPEG-TS...');
if (!mpegts.isSupported()) return false;
const player = mpegts.createPlayer({ type: 'mpegts', isLive: isLive, url: url }, {
enableWorker: true,
stashInitialSize: 512 * 1024, // Buffer-First: 512KB
enableStashBuffer: true,
liveBufferLatencyChasing: false, // Avoid chaotic catch-up
maxStashSize: 30 * 1024 * 1024
});
player.attachMediaElement(video);
player.load();
// Wait for buffer to fill slightly before playing
const checkBuffer = setInterval(() => {
if (video.buffered.length > 0) {
if (video.buffered.end(0) > 1.0) {
clearInterval(checkBuffer);
player.play().catch(() => playOverlay.style.display = 'flex');
}
}
}, 200);
player.on(mpegts.Events.ERROR, (type, detail) => {
log('MpegTS Error: ' + type + ' - ' + detail);
setTimeout(() => {
player.destroy();
playWithMpegTS(url, isLive);
}, 2000);
});
return true;
}
async function playDirect(url) {
log('Direct play logic for Safari stability: ' + url);
showLoading('Lancement...');
video.src = url;
video.load();
video.play().catch(async () => {
log('Direct play blocked, trying fallbacks...');
if (url.toLowerCase().includes('.m3u8')) await playWithHLS(url);
else playOverlay.style.display = 'flex';
});
video.addEventListener('canplay', () => hideLoading(), { once: true });
video.addEventListener('error', () => showError('Format non supporté'), { once: true });
return true;
}
async function initPlayer() {
if (!streamUrl) return showError('No URL');
const lowerUrl = streamUrl.toLowerCase();
if (streamType === 'live') {
if (lowerUrl.includes('.m3u8')) await playWithHLS(streamUrl);
else await playWithMpegTS(streamUrl, true);
} else if (streamType === 'vod') {
if (lowerUrl.includes('.m3u8')) await playWithHLS(streamUrl);
else await playDirect(streamUrl);
} else {
if (lowerUrl.includes('.m3u8')) await playWithHLS(streamUrl);
else await playDirect(streamUrl);
errorBox.style.display = 'block';
errorMessage.textContent = msg || 'Erreur de chargement';
playOverlay.style.display = 'none';
}
}
initPlayer();
var player = new XFPlayer({
video: video,
logPrefix: '[Player]',
onLoading: showLoading,
onReady: function () {
hideLoading();
playOverlay.style.display = 'none';
},
onError: showError,
onBlocked: function () {
hideLoading();
playOverlay.style.display = 'flex';
},
onProfileChange: function (name) {
// Retour visuel discret : l'utilisateur comprend pourquoi
// la latence augmente légèrement après des coupures.
loadingHint.textContent =
name === 'safe' ? 'Réseau instable — buffer maximal'
: 'Réseau instable — buffer élargi';
}
});
playOverlay.addEventListener('click', function () {
video.play();
playOverlay.style.display = 'none';
});
player.start();
window.xfPlayer = player;
})();
</script>
</body>
</html>
</html>
+70 -332
View File
@@ -1,121 +1,15 @@
<!DOCTYPE html>
<html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>IPTV Player Lite</title>
<!-- Vendored, pinned player libraries (no CDN dependency) -->
<script src="vendor/hls.min.js"></script>
<script src="vendor/mpegts.min.js"></script>
<link rel="stylesheet" href="theme.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
html,
body {
background: var(--color-bg);
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#player-container {
width: 100%;
height: 100%;
position: relative;
}
#video {
width: 100%;
height: 100%;
background: var(--color-bg);
}
#error {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: var(--color-text);
text-align: center;
z-index: 30;
}
#error-icon {
font-size: 64px;
color: var(--color-error);
margin-bottom: 16px;
}
#loading {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: var(--color-text);
text-align: center;
z-index: 20;
}
.spinner {
width: 48px;
height: 48px;
border: 4px solid var(--color-border);
border-top-color: var(--color-accent);
border-radius: 50%;
animation: spin 1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
margin: 0 auto 16px;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
/* Safari Autoplay Hint Overlay */
#play-overlay {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 80px;
height: 80px;
background: var(--color-overlay);
border-radius: 50%;
display: none;
justify-content: center;
align-items: center;
cursor: pointer;
border: 2px solid var(--color-border);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
z-index: 25;
}
#play-overlay svg {
width: 40px;
height: 40px;
fill: white;
margin-left: 4px;
}
</style>
<title>XtremFlow Player Lite</title>
<link rel="stylesheet" href="xf-player.css">
<link rel="preload" href="vendor/hls.min.js" as="script">
</head>
<body>
<div id="player-container">
<!-- iOS/Safari core attributes -->
<video id="video" autoplay playsinline webkit-playsinline preload="auto"></video>
<div id="play-overlay">
@@ -124,243 +18,87 @@
</svg>
</div>
<div id="loading">
<div class="spinner"></div>
<div id="loading-text">Chargement du flux...</div>
<div id="loading" class="xf-center">
<div class="xf-leader">
<div class="xf-leader-cross"></div>
</div>
<div class="xf-label" id="loading-text">Ouverture du flux</div>
<div class="xf-hint" id="loading-hint"></div>
</div>
<div id="error">
<div id="error-icon">⚠</div>
<div id="error-message">Erreur de chargement</div>
<div id="error" class="xf-center">
<div class="xf-error-mark">!</div>
<div class="xf-error-title" id="error-message">Erreur de chargement</div>
<div class="xf-error-sub">Vérifiez le lien ou votre connexion</div>
</div>
</div>
<script src="xf-player-core.js"></script>
<script>
const video = document.getElementById('video');
const loading = document.getElementById('loading');
const loadingText = document.getElementById('loading-text');
const error = document.getElementById('error');
const errorMessage = document.getElementById('error-message');
const playOverlay = document.getElementById('play-overlay');
(function () {
var video = document.getElementById('video');
var loading = document.getElementById('loading');
var loadingText = document.getElementById('loading-text');
var loadingHint = document.getElementById('loading-hint');
var errorBox = document.getElementById('error');
var errorMessage = document.getElementById('error-message');
var playOverlay = document.getElementById('play-overlay');
// Get parameters from query string
const urlParams = new URLSearchParams(window.location.search);
let streamUrl = urlParams.get('url');
const startTime = parseFloat(urlParams.get('t') || '0');
const streamType = urlParams.get('type') || ''; // 'live' or 'vod'
function log(msg) {
console.log('[LitePlayer] ' + msg);
}
function showLoading(msg) {
loading.style.display = 'block';
loadingText.textContent = msg || 'Chargement du flux...';
error.style.display = 'none';
}
function hideLoading() {
loading.style.display = 'none';
}
function showError(message) {
hideLoading();
error.style.display = 'block';
errorMessage.textContent = message || 'Erreur de chargement';
}
playOverlay.addEventListener('click', () => {
log('Manual play triggered');
video.play();
playOverlay.style.display = 'none';
});
// Seek to startTime when video is ready
video.addEventListener('loadedmetadata', () => {
if (startTime > 0 && startTime < video.duration) {
video.currentTime = startTime;
function showLoading(msg) {
loading.style.display = 'block';
loadingText.textContent = msg || 'Ouverture du flux';
errorBox.style.display = 'none';
}
});
// Parent (Flutter app) is always same-origin: never broadcast to '*'
const PARENT_ORIGIN = window.location.origin;
// Report position to parent
let lastReportedTime = 0;
function reportPosition() {
if (video.currentTime > 0 && !video.paused && video.readyState > 2) {
if (Math.abs(video.currentTime - lastReportedTime) >= 5) {
lastReportedTime = video.currentTime;
window.parent.postMessage({
type: 'playback_position',
currentTime: video.currentTime,
duration: isFinite(video.duration) ? video.duration : 0
}, PARENT_ORIGIN);
}
}
}
setInterval(reportPosition, 5000);
video.addEventListener('pause', () => {
window.parent.postMessage({ type: 'playback_status', status: 'paused' }, PARENT_ORIGIN);
if (video.currentTime === 0 || video.paused) {
function hideLoading() {
loading.style.display = 'none';
playOverlay.style.display = 'flex';
}
});
video.addEventListener('playing', () => {
window.parent.postMessage({ type: 'playback_status', status: 'playing' }, PARENT_ORIGIN);
hideLoading();
playOverlay.style.display = 'none';
});
video.addEventListener('ended', () => {
window.parent.postMessage({
type: 'playback_ended',
duration: isFinite(video.duration) ? video.duration : 0
}, PARENT_ORIGIN);
});
// Activity reporting
function reportActivity() {
window.parent.postMessage({ type: 'user_activity' }, PARENT_ORIGIN);
}
document.addEventListener('mousemove', reportActivity);
document.addEventListener('touchstart', reportActivity);
document.addEventListener('click', reportActivity);
async function playWithHLS(url) {
log('Trying HLS.js with: ' + url);
showLoading('Chargement HLS...');
if (!Hls.isSupported()) {
if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url;
video.load();
video.play().catch(() => {
loading.style.display = 'none';
playOverlay.style.display = 'flex';
});
return true;
}
return false;
loadingHint.textContent = '';
}
const isTurbo = urlParams.get('turbo') === 'true';
const hls = new Hls({
maxBufferLength: 120,
maxMaxBufferLength: 240,
enableWorker: true,
liveSyncDurationCount: 3,
liveMaxLatencyDurationCount: 10,
lowLatencyMode: false,
nudgeOffset: 0.8,
nudgeMaxRetries: 30,
maxLiveSyncPlaybackRate: 1.1,
initialLiveManifestSize: 1,
abrEwmaDefaultEstimate: 1000000,
manifestLoadingRetryDelay: 1000,
levelLoadingRetryDelay: 1000
});
window.hlsInstance = hls;
hls.loadSource(url);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
function showError(msg) {
hideLoading();
const checkBuffer = setInterval(() => {
if (video.buffered.length > 0 && video.buffered.end(0) > 0.8) {
clearInterval(checkBuffer);
video.play().catch(() => playOverlay.style.display = 'flex');
}
}, 100);
});
hls.on(Hls.Events.ERROR, (event, data) => {
if (data.fatal) {
if (data.type === Hls.ErrorTypes.NETWORK_ERROR) hls.startLoad();
else if (data.type === Hls.ErrorTypes.MEDIA_ERROR) hls.recoverMediaError();
else showError('HLS Error: ' + data.details);
}
});
return true;
}
async function playWithMpegTS(url, isLive = true) {
log('Trying mpegts.js with: ' + url);
showLoading('Chargement MPEG-TS...');
if (!mpegts.isSupported()) return false;
const isTurbo = urlParams.get('turbo') === 'true';
const player = mpegts.createPlayer({
type: 'mpegts',
isLive: isLive,
url: url
}, {
enableWorker: true,
stashInitialSize: 128 * 1024,
enableStashBuffer: true,
liveBufferLatencyChasing: false,
maxStashSize: 30 * 1024 * 1024
});
player.attachMediaElement(video);
player.load();
const checkBuffer = setInterval(() => {
if (video.buffered.length > 0 && video.buffered.end(0) > 0.5) {
clearInterval(checkBuffer);
player.play().catch(() => playOverlay.style.display = 'flex');
}
}, 100);
player.on(mpegts.Events.ERROR, (type, detail, info) => {
log('MpegTS Error: ' + type + ' - ' + detail);
// Auto-recover after 2 seconds
setTimeout(() => {
try {
player.unload();
player.detachMediaElement();
player.destroy();
playWithMpegTS(url, isLive);
} catch (e) {
showError('MpegTS Recovery Failed');
}
}, 2000);
});
return true;
}
async function initPlayer() {
if (!streamUrl) return showError('No URL');
log('Stream URL: ' + streamUrl);
const lowerUrl = streamUrl.toLowerCase();
const isHLS = lowerUrl.includes('.m3u8') || lowerUrl.includes('/playlist.m3u8');
if (isHLS) {
await playWithHLS(streamUrl);
} else {
await playWithMpegTS(streamUrl, streamType === 'live');
errorBox.style.display = 'block';
errorMessage.textContent = msg || 'Erreur de chargement';
playOverlay.style.display = 'none';
}
}
window.addEventListener('message', (event) => {
if (event.origin !== window.location.origin) return;
const data = event.data;
if (!data) return;
if (data.type === 'play') video.play().catch(() => playOverlay.style.display = 'flex');
else if (data.type === 'pause') video.pause();
else if (data.type === 'set_volume') { video.volume = Math.max(0, Math.min(1, data.value)); video.muted = video.volume === 0; }
});
var player = new XFPlayer({
video: video,
logPrefix: '[LitePlayer]',
onLoading: showLoading,
onReady: function () {
hideLoading();
playOverlay.style.display = 'none';
},
onError: showError,
onBlocked: function () {
hideLoading();
playOverlay.style.display = 'flex';
},
onProfileChange: function (name) {
loadingHint.textContent =
name === 'safe' ? 'Réseau instable — buffer maximal'
: 'Réseau instable — buffer élargi';
}
});
initPlayer();
playOverlay.addEventListener('click', function () {
video.play();
playOverlay.style.display = 'none';
});
// Contrat historique du lite : mise en pause manuelle → overlay lecture.
video.addEventListener('pause', function () {
if (video.currentTime === 0 || video.paused) {
loading.style.display = 'none';
playOverlay.style.display = 'flex';
}
});
player.start();
window.xfPlayer = player;
})();
</script>
</body>
</html>
</html>
+102 -287
View File
@@ -1,319 +1,134 @@
<!DOCTYPE html>
<html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Mobile IPTV Player</title>
<!-- Vendored, pinned player libraries (no CDN dependency) -->
<script src="vendor/hls.min.js"></script>
<script src="vendor/mpegts.min.js"></script>
<link rel="stylesheet" href="theme.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
html, body {
background: var(--color-bg);
width: 100%;
height: 100%;
overflow: hidden;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#player-container {
width: 100%;
height: 100%;
position: relative;
display: flex;
justify-content: center;
align-items: center;
}
#video {
width: 100%;
height: 100%;
object-fit: contain;
background: var(--color-bg);
}
#loading {
position: absolute;
display: flex;
flex-direction: column;
align-items: center;
color: white;
z-index: 20;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}
.spinner {
width: 40px;
height: 40px;
border: 3px solid var(--color-border);
border-top-color: var(--color-accent);
border-radius: 50%;
animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
margin-bottom: 12px;
}
@keyframes spin {
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 {
display: none;
position: absolute;
color: white;
text-align: center;
padding: 24px;
background: rgba(0, 0, 0, 0.85);
border-radius: 16px;
z-index: 30;
max-width: 80%;
border: 1px solid rgba(255, 255, 255, 0.1);
}
</style>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>XtremFlow Player Mobile</title>
<link rel="stylesheet" href="xf-player.css">
<link rel="preload" href="vendor/hls.min.js" as="script">
</head>
<body>
<div id="player-container">
<!-- muted + autoplay: iOS Safari autorise l'autoplay uniquement si muted -->
<!-- muted au départ : seul moyen fiable d'obtenir l'autoplay sur iOS -->
<video id="video" autoplay muted playsinline webkit-playsinline preload="auto"></video>
<!-- 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>
<div id="l-text" style="font-size: 14px; font-weight: 500;">Chargement...</div>
<div id="loading" class="xf-center">
<div class="xf-leader">
<div class="xf-leader-cross"></div>
</div>
<div class="xf-label" id="l-text">Ouverture du flux</div>
<div class="xf-hint" id="loading-hint"></div>
</div>
<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 id="err-sub" style="font-size: 12px; color: rgba(255,255,255,0.6); margin-top: 8px;">Vérifiez votre connexion</div>
<button id="unmute-btn" class="xf-sound-btn" type="button">
<svg viewBox="0 0 24 24">
<path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3a4.5 4.5 0 0 0-2.5-4v8a4.5 4.5 0 0 0 2.5-4z" />
</svg>
Activer le son
</button>
<div id="error" class="xf-center">
<div class="xf-error-mark">!</div>
<div class="xf-error-title" id="err-msg">Erreur de lecture</div>
<div class="xf-error-sub" id="err-sub">Vérifiez votre connexion</div>
</div>
</div>
<script src="xf-player-core.js"></script>
<script>
const video = document.getElementById('video');
const loading = document.getElementById('loading');
const unmuteBtn = document.getElementById('unmute-btn');
const error = document.getElementById('error');
(function () {
var video = document.getElementById('video');
var loading = document.getElementById('loading');
var loadingText = document.getElementById('l-text');
var loadingHint = document.getElementById('loading-hint');
var unmuteBtn = document.getElementById('unmute-btn');
var errorBox = document.getElementById('error');
const params = new URLSearchParams(window.location.search);
const streamUrl = params.get('url');
const streamType = params.get('type') || 'live';
var retryCount = 0;
var maxRetries = 3;
var player = null;
function log(m) { console.log('[MobilePlayer] ' + m); }
function showLoading(msg) {
loading.style.display = 'block';
loadingText.textContent = msg || 'Ouverture du flux';
errorBox.style.display = 'none';
}
let retryCount = 0;
const maxRetries = 3;
function hideLoading() {
loading.style.display = 'none';
loadingHint.textContent = '';
}
function showError(code, msg) {
loading.style.display = 'none';
unmuteBtn.style.display = 'none';
error.style.display = 'block';
document.getElementById('err-msg').textContent = 'Erreur ' + code;
document.getElementById('err-sub').textContent = msg || 'Format non supporté ou lien expiré';
}
function showError(msg) {
hideLoading();
unmuteBtn.style.display = 'none';
errorBox.style.display = 'block';
document.getElementById('err-sub').textContent =
msg || 'Format non supporté ou lien expiré';
}
// Bouton son : user gesture DIRECT dans l'iframe → iOS accepte le unmute
unmuteBtn.addEventListener('click', (e) => {
e.preventDefault();
video.muted = false;
video.volume = 1.0;
unmuteBtn.style.display = 'none';
log('Unmuted by user');
window.parent.postMessage({ type: 'unmuted' }, window.location.origin);
});
video.addEventListener('touchend', () => {
window.parent.postMessage({ type: 'user_activity' }, window.location.origin);
});
video.addEventListener('playing', () => {
log('Video playing, muted=' + video.muted);
loading.style.display = 'none';
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)
// Le geste utilisateur doit avoir lieu DANS l'iframe : iOS
// n'accepte le démutage que dans ce contexte.
unmuteBtn.addEventListener('click', function (e) {
e.preventDefault();
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 || '?';
const msg = video.error?.message || '';
log('Video error code=' + code + ' msg=' + msg + ' retry=' + retryCount);
if (retryCount < maxRetries) {
retryCount++;
log('Retry ' + retryCount + '/' + maxRetries + ' in 2s');
loading.style.display = 'flex';
error.style.display = 'none';
document.getElementById('l-text').textContent = 'Reconnexion ' + retryCount + '/' + maxRetries + '...';
setTimeout(startPlayback, 2000);
} else {
showError(code, msg);
}
});
function startPlayback() {
log('startPlayback: ' + streamUrl);
video.src = '';
video.load();
video.src = streamUrl;
video.load();
video.play().catch(e => {
log('play() rejected: ' + e);
// Ne pas montrer erreur ici — laisser l'event error gérer
video.volume = 1.0;
unmuteBtn.style.display = 'none';
window.parent.postMessage({ type: 'unmuted' }, '*');
});
}
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 buildPlayer() {
if (player) { try { player.destroy(); } catch (e) {} }
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'));
}
player = new XFPlayer({
video: video,
logPrefix: '[MobilePlayer]',
onLoading: showLoading,
onReady: function () {
hideLoading();
retryCount = 0;
// Tentative de démutage auto ; si iOS refuse, on propose le bouton.
if (video.muted) {
video.muted = false;
unmuteBtn.style.display = video.muted ? 'flex' : 'none';
}
},
onError: function (msg) {
if (retryCount < maxRetries) {
retryCount++;
showLoading('Reconnexion ' + retryCount + '/' + maxRetries);
setTimeout(buildPlayer, 1500);
} else {
showError(msg);
}
},
onBlocked: function () {
// Autoplay refusé même en sourdine : le bouton son sert
// aussi de déclencheur de lecture.
hideLoading();
unmuteBtn.style.display = 'flex';
},
onProfileChange: function (name) {
loadingHint.textContent =
name === 'safe' ? 'Réseau instable — buffer maximal'
: 'Réseau instable — buffer élargi';
}
});
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;
player.start();
window.xfPlayer = player;
}
// Android/Chrome — HLS.js
if (isHLS && Hls.isSupported()) {
initHlsJs();
return;
}
video.addEventListener('touchend', function () {
window.parent.postMessage({ type: 'user_activity' }, '*');
}, { passive: true });
// MpegTS fallback
if (mpegts.isSupported()) {
initMpegts();
return;
}
// Direct fallback
log('Direct fallback');
startPlayback();
}
// Messages depuis Flutter
window.addEventListener('message', (e) => {
if (e.origin !== window.location.origin) return;
const d = e.data;
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();
buildPlayer();
})();
</script>
</body>
+495
View File
@@ -0,0 +1,495 @@
/* =====================================================================
* XtremFlow — Moteur de lecture partagé
* ---------------------------------------------------------------------
* Objectifs :
* 1. ZAP RAPIDE — premier frame le plus tôt possible.
* 2. ADAPTATIF — si le réseau décroche, le buffer s'élargit tout seul.
* 3. ZÉRO CDN — hls.js / mpegts.js servis en local, chargés à la demande.
*
* Utilisé par player.html, player_lite.html et player_mobile.html.
* ===================================================================== */
(function (global) {
'use strict';
// ------------------------------------------------------------------
// Profils de buffer — escalade automatique en cas de micro-coupures
// ------------------------------------------------------------------
var PROFILES = {
// Démarrage : le plus agressif possible.
fast: {
name: 'fast',
hls: {
maxBufferLength: 24,
maxMaxBufferLength: 60,
liveSyncDurationCount: 2,
liveMaxLatencyDurationCount: 8,
initialLiveManifestSize: 1
},
mpegtsStash: 64 * 1024
},
// 2 coupures : on respire.
balanced: {
name: 'balanced',
hls: {
maxBufferLength: 60,
maxMaxBufferLength: 120,
liveSyncDurationCount: 4,
liveMaxLatencyDurationCount: 14,
initialLiveManifestSize: 2
},
mpegtsStash: 192 * 1024
},
// 4 coupures : priorité absolue à la stabilité.
safe: {
name: 'safe',
hls: {
maxBufferLength: 120,
maxMaxBufferLength: 240,
liveSyncDurationCount: 8,
liveMaxLatencyDurationCount: 24,
initialLiveManifestSize: 3
},
mpegtsStash: 512 * 1024
}
};
var ORDER = ['fast', 'balanced', 'safe'];
// ------------------------------------------------------------------
// Chargement paresseux des libs (aucune requête inutile)
// ------------------------------------------------------------------
var _scriptCache = {};
function loadScript(src) {
if (_scriptCache[src]) return _scriptCache[src];
_scriptCache[src] = new Promise(function (resolve, reject) {
var s = document.createElement('script');
s.src = src;
s.async = true;
s.onload = resolve;
s.onerror = function () { reject(new Error('Échec du chargement : ' + src)); };
document.head.appendChild(s);
});
return _scriptCache[src];
}
/** Ouvre la connexion vers l'hôte du flux avant même de connaître l'URL finale. */
function preconnect(url) {
try {
var origin = new URL(url, location.href).origin;
if (origin === location.origin) return;
['preconnect', 'dns-prefetch'].forEach(function (rel) {
var l = document.createElement('link');
l.rel = rel;
l.href = origin;
l.crossOrigin = 'anonymous';
document.head.appendChild(l);
});
} catch (e) { /* URL relative ou invalide : rien à préconnecter */ }
}
// ------------------------------------------------------------------
// Moteur
// ------------------------------------------------------------------
function XFPlayer(options) {
this.video = options.video;
this.vendorPath = options.vendorPath || 'vendor/';
this.logPrefix = options.logPrefix || '[XFPlayer]';
// Callbacks UI (toutes optionnelles)
this.onLoading = options.onLoading || function () {};
this.onReady = options.onReady || function () {};
this.onError = options.onError || function () {};
this.onBlocked = options.onBlocked || function () {};
this.onProfileChange = options.onProfileChange || function () {};
var p = new URLSearchParams(location.search);
this.params = p;
this.url = options.url || p.get('url');
this.type = options.type || p.get('type') || '';
this.startTime = parseFloat(p.get('t') || '0');
this.injectedDuration = parseFloat(p.get('duration') || '0');
this.isRecording = p.get('is_recording') === 'true';
// Profil de départ : forçable via ?buffer=balanced|safe
var forced = p.get('buffer');
this.profile = PROFILES[forced] ? PROFILES[forced] : PROFILES.fast;
this.profileLocked = !!PROFILES[forced];
this.hls = null;
this.mpegts = null;
this._started = false;
this._stalls = 0;
this._stallTimes = [];
this._destroyed = false;
this._reportedTime = 0;
this._hlsDuration = 0;
}
XFPlayer.prototype.log = function (m) {
if (global.console && console.log) console.log(this.logPrefix + ' ' + m);
};
XFPlayer.prototype.send = function (msg) {
try { global.parent.postMessage(msg, '*'); } catch (e) {}
};
// ---------------- Démarrage ----------------
XFPlayer.prototype.start = function () {
var self = this;
if (!this.url) { this.onError('Aucun flux fourni'); return Promise.resolve(); }
preconnect(this.url);
this._wireVideoEvents();
this._wireParentMessages();
var lower = this.url.toLowerCase();
var isHls = lower.indexOf('.m3u8') !== -1;
var isLive = this.type === 'live';
this.onLoading('Ouverture du flux');
// Safari / iOS : HLS natif = le chemin le plus rapide, aucune lib à charger.
if (isHls && this._canPlayNativeHls()) {
this.log('HLS natif (Safari/iOS)');
return Promise.resolve(this._playDirect(this.url));
}
if (isHls) return this._startHls();
if (isLive || lower.indexOf('.ts') !== -1) return this._startMpegts(isLive || true);
// VOD progressif (mp4, mkv…) : lecture directe.
return Promise.resolve(this._playDirect(this.url));
};
XFPlayer.prototype._canPlayNativeHls = function () {
return this.video.canPlayType('application/vnd.apple.mpegurl') !== '';
};
// ---------------- HLS ----------------
XFPlayer.prototype._hlsConfig = function () {
var prof = this.profile.hls;
return {
enableWorker: true,
lowLatencyMode: false,
// ---- Fenêtre de buffer (pilotée par le profil) ----
maxBufferLength: prof.maxBufferLength,
maxMaxBufferLength: prof.maxMaxBufferLength,
backBufferLength: 30,
maxBufferSize: 30 * 1000 * 1000,
// ---- Démarrage rapide ----
// 1 seul segment suffit pour commencer (au lieu de 3) : ~2 segments
// de latence en moins au zap, soit souvent 4 à 12 secondes gagnées.
initialLiveManifestSize: prof.initialLiveManifestSize,
startFragPrefetch: true, // précharge le 1er fragment pendant le parse
testBandwidth: false, // pas de mesure préalable : on joue tout de suite
// ---- Live ----
liveSyncDurationCount: prof.liveSyncDurationCount,
liveMaxLatencyDurationCount: prof.liveMaxLatencyDurationCount,
maxLiveSyncPlaybackRate: 1.15,
// ---- Robustesse ----
nudgeOffset: 0.6,
nudgeMaxRetries: 20,
abrEwmaDefaultEstimate: 2000000,
manifestLoadingRetryDelay: 500,
levelLoadingRetryDelay: 500,
fragLoadingRetryDelay: 500,
manifestLoadingMaxRetry: 4,
levelLoadingMaxRetry: 4,
fragLoadingMaxRetry: 6
};
};
XFPlayer.prototype._startHls = function () {
var self = this;
return loadScript(this.vendorPath + 'hls.min.js').then(function () {
if (!global.Hls || !global.Hls.isSupported()) {
if (self._canPlayNativeHls()) return self._playDirect(self.url);
self.onError('HLS non supporté par ce navigateur');
return;
}
var Hls = global.Hls;
var hls = new Hls(self._hlsConfig());
self.hls = hls;
global.hlsInstance = hls; // compat : code existant qui inspecte l'instance
hls.loadSource(self.url);
hls.attachMedia(self.video);
hls.on(Hls.Events.MANIFEST_PARSED, function () {
// Démarrage immédiat : on ne sonde plus le buffer toutes les 200 ms.
// Si le réseau ne suit pas, l'escalade de profil s'en chargera.
self._attemptPlay();
});
hls.on(Hls.Events.LEVEL_LOADED, function (e, d) {
if (d.details && d.details.totalduration > self._hlsDuration) {
self._hlsDuration = d.details.totalduration;
global.currentHlsDuration = self._hlsDuration;
}
});
hls.on(Hls.Events.ERROR, function (e, d) {
if (!d.fatal) return;
self.log('Erreur HLS fatale : ' + d.details);
if (d.type === Hls.ErrorTypes.NETWORK_ERROR) {
self._escalate('erreur réseau');
hls.startLoad();
} else if (d.type === Hls.ErrorTypes.MEDIA_ERROR) {
self._escalate('erreur média');
hls.recoverMediaError();
} else {
self.onError('Erreur HLS : ' + d.details);
}
});
}).catch(function (err) {
self.onError(err.message);
});
};
// ---------------- MPEG-TS ----------------
XFPlayer.prototype._startMpegts = function (isLive) {
var self = this;
return loadScript(this.vendorPath + 'mpegts.min.js').then(function () {
if (!global.mpegts || !global.mpegts.isSupported()) {
return self._playDirect(self.url);
}
self._createMpegts(isLive);
}).catch(function (err) {
self.onError(err.message);
});
};
XFPlayer.prototype._createMpegts = function (isLive) {
var self = this;
var mpegts = global.mpegts;
var player = mpegts.createPlayer(
{ type: 'mpegts', isLive: isLive, url: this.url },
{
enableWorker: true,
enableStashBuffer: true,
// Le stash initial conditionne directement le délai avant la 1re image.
// 64 Ko en profil « fast » contre 512 Ko auparavant.
stashInitialSize: this.profile.mpegtsStash,
maxStashSize: 30 * 1024 * 1024,
liveBufferLatencyChasing: false,
lazyLoad: false
}
);
this.mpegts = player;
this._mpegtsIsLive = isLive;
player.on(mpegts.Events.ERROR, function (type, detail) {
self.log('Erreur MPEG-TS : ' + type + ' / ' + detail);
if (self._destroyed) return;
self._escalate('erreur MPEG-TS');
// Recréation propre avec le nouveau profil.
setTimeout(function () {
if (self._destroyed) return;
try {
player.unload();
player.detachMediaElement();
player.destroy();
} catch (e) {}
self._createMpegts(self._mpegtsIsLive);
}, 1200);
});
player.attachMediaElement(this.video);
player.load();
this._attemptPlay();
};
// ---------------- Lecture directe ----------------
XFPlayer.prototype._playDirect = function (url) {
var self = this;
this.video.src = url;
this.video.load();
this._attemptPlay();
this.video.addEventListener('error', function () {
self.onError('Format non supporté');
}, { once: true });
return true;
};
XFPlayer.prototype._attemptPlay = function () {
var self = this;
var p = this.video.play();
if (p && typeof p.catch === 'function') {
p.catch(function () {
// Autoplay refusé (Safari/iOS) : on tente en sourdine, sinon overlay.
self.video.muted = true;
var q = self.video.play();
if (q && typeof q.catch === 'function') {
q.catch(function () { self.onBlocked(); });
}
});
}
};
// ---------------- Escalade adaptative ----------------
/**
* Passe au profil supérieur après des coupures répétées.
* Fenêtre glissante de 60 s : deux stalls rapprochés déclenchent l'escalade,
* des stalls isolés dans le temps ne pénalisent pas la latence.
*/
XFPlayer.prototype._escalate = function (reason) {
if (this.profileLocked || this._destroyed) return;
var idx = ORDER.indexOf(this.profile.name);
if (idx >= ORDER.length - 1) return; // déjà au maximum
var next = PROFILES[ORDER[idx + 1]];
this.profile = next;
this.log('Escalade buffer → ' + next.name + ' (' + reason + ')');
this.onProfileChange(next.name, reason);
// HLS : les fenêtres de buffer sont modifiables à chaud, pas besoin de
// recharger le flux — donc aucune coupure visible pour l'utilisateur.
if (this.hls) {
try {
this.hls.config.maxBufferLength = next.hls.maxBufferLength;
this.hls.config.maxMaxBufferLength = next.hls.maxMaxBufferLength;
this.hls.config.liveSyncDurationCount = next.hls.liveSyncDurationCount;
this.hls.config.liveMaxLatencyDurationCount =
next.hls.liveMaxLatencyDurationCount;
} catch (e) {}
}
// MPEG-TS : le stash est figé à la création — appliqué à la prochaine
// recréation du lecteur (déclenchée par le handler d'erreur).
};
XFPlayer.prototype._noteStall = function () {
if (!this._started) return; // les attentes d'amorçage ne comptent pas
var now = Date.now();
this._stallTimes.push(now);
this._stallTimes = this._stallTimes.filter(function (t) {
return now - t < 60000;
});
if (this._stallTimes.length >= 2) {
this._stallTimes = [];
this._escalate('coupures répétées');
}
};
// ---------------- Événements vidéo & pont Flutter ----------------
XFPlayer.prototype._wireVideoEvents = function () {
var self = this;
var v = this.video;
v.addEventListener('loadedmetadata', function () {
if (self.startTime > 0 && self.startTime < v.duration) {
v.currentTime = self.startTime;
}
});
v.addEventListener('playing', function () {
self._started = true;
self.onReady();
self.send({ type: 'playback_status', status: 'playing' });
});
v.addEventListener('pause', function () {
self.send({ type: 'playback_status', status: 'paused' });
});
v.addEventListener('waiting', function () { self._noteStall(); });
v.addEventListener('stalled', function () { self._noteStall(); });
v.addEventListener('ended', function () {
self.send({
type: 'playback_ended',
duration: isFinite(v.duration) ? v.duration : self.injectedDuration
});
});
// Remontée de position (5 s) — même contrat qu'avant.
this._posTimer = setInterval(function () { self._reportPosition(); }, 5000);
// Activité utilisateur → masquage auto des contrôles côté Flutter.
function activity() { self.send({ type: 'user_activity' }); }
document.addEventListener('mousemove', activity, { passive: true });
document.addEventListener('touchstart', activity, { passive: true });
document.addEventListener('click', activity, { passive: true });
};
XFPlayer.prototype._reportPosition = function () {
var v = this.video;
if (!(v.currentTime > 0) || v.paused || v.readyState <= 2) return;
if (Math.abs(v.currentTime - this._reportedTime) < 1) return;
this._reportedTime = v.currentTime;
var duration = v.duration;
var hlsDur = this._hlsDuration || 0;
if (!isFinite(duration) || isNaN(duration) || duration < 1) {
duration = hlsDur > 0 ? hlsDur : (this.injectedDuration > 0 ? this.injectedDuration : 0);
} else if (hlsDur > duration) {
duration = hlsDur;
} else if (this.injectedDuration > 0 && duration < this.injectedDuration * 0.9) {
duration = this.injectedDuration;
}
this.send({
type: 'playback_position',
currentTime: v.currentTime,
duration: duration
});
};
XFPlayer.prototype._wireParentMessages = function () {
var self = this;
global.addEventListener('message', function (event) {
var d = event.data;
if (!d || !d.type) return;
var v = self.video;
switch (d.type) {
case 'play':
self._attemptPlay();
break;
case 'pause':
v.pause();
break;
case 'seek':
if (isFinite(d.value)) v.currentTime = d.value;
break;
case 'set_volume':
v.volume = Math.max(0, Math.min(1, d.value));
v.muted = v.volume === 0;
break;
case 'unmute':
v.muted = false;
if (v.volume === 0) v.volume = 1;
break;
}
});
};
XFPlayer.prototype.destroy = function () {
this._destroyed = true;
clearInterval(this._posTimer);
try { if (this.hls) this.hls.destroy(); } catch (e) {}
try {
if (this.mpegts) {
this.mpegts.unload();
this.mpegts.detachMediaElement();
this.mpegts.destroy();
}
} catch (e) {}
};
global.XFPlayer = XFPlayer;
global.XFPlayerProfiles = PROFILES;
})(window);
+255
View File
@@ -0,0 +1,255 @@
/* =====================================================================
* XtremFlow — Habillage des lecteurs, thème « Warm Cinema »
* Charbon chaud (#0B0908), crème (#F3E9DF), braise (#D9541F).
*
* PERF : aucun backdrop-filter. Le flou de fond force le compositeur à
* relire le framebuffer à chaque frame — inacceptable par-dessus une vidéo.
* ===================================================================== */
:root {
--xf-ink: #0B0908;
--xf-cream: #F3E9DF;
--xf-cream-dim: #C5B3A5;
--xf-ember: #D9541F;
--xf-ember-light: #FFB68C;
--xf-danger: #E5484D;
--xf-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
html,
body {
background: var(--xf-ink);
width: 100%;
height: 100%;
overflow: hidden;
font-family: var(--xf-ui);
color: var(--xf-cream);
}
#player-container {
width: 100%;
height: 100%;
position: relative;
background: var(--xf-ink);
}
#video {
width: 100%;
height: 100%;
background: var(--xf-ink);
display: block;
}
/* ---------------------------------------------------------------
* Amorce de projection — l'anneau de compte à rebours d'une bobine
* --------------------------------------------------------------- */
.xf-center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
z-index: 20;
}
#loading {
display: none;
}
.xf-leader {
width: 64px;
height: 64px;
margin: 0 auto 20px;
position: relative;
}
/* Anneau fixe, très discret */
.xf-leader::before {
content: "";
position: absolute;
inset: 0;
border-radius: 50%;
border: 2px solid rgba(243, 233, 223, 0.14);
}
/* Balayage braise */
.xf-leader::after {
content: "";
position: absolute;
inset: 0;
border-radius: 50%;
border: 2px solid transparent;
border-top-color: var(--xf-ember);
border-right-color: var(--xf-ember);
animation: xf-sweep 900ms cubic-bezier(0.5, 0, 0.5, 1) infinite;
}
/* Réticule central : croix d'amorce de pellicule */
.xf-leader-cross,
.xf-leader-cross::before {
position: absolute;
background: rgba(243, 233, 223, 0.22);
}
.xf-leader-cross {
top: 50%;
left: 12px;
right: 12px;
height: 1px;
transform: translateY(-0.5px);
}
.xf-leader-cross::before {
content: "";
top: -14px;
bottom: -14px;
left: 50%;
width: 1px;
height: 28px;
transform: translateX(-0.5px);
}
@keyframes xf-sweep {
to {
transform: rotate(360deg);
}
}
.xf-label {
font-size: 12px;
font-weight: 600;
letter-spacing: 0.18em;
text-transform: uppercase;
color: var(--xf-cream-dim);
}
/* Mention discrète quand le buffer s'élargit tout seul */
.xf-hint {
margin-top: 10px;
font-size: 11px;
letter-spacing: 0.08em;
color: rgba(243, 233, 223, 0.42);
min-height: 14px;
}
/* ---------------------------------------------------------------
* Erreur
* --------------------------------------------------------------- */
#error {
display: none;
max-width: 78vw;
}
.xf-error-mark {
width: 52px;
height: 52px;
margin: 0 auto 18px;
border: 2px solid var(--xf-danger);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 26px;
line-height: 1;
color: var(--xf-danger);
}
.xf-error-title {
font-size: 15px;
font-weight: 700;
letter-spacing: 0.02em;
color: var(--xf-cream);
}
.xf-error-sub {
margin-top: 8px;
font-size: 12px;
letter-spacing: 0.04em;
color: rgba(243, 233, 223, 0.5);
}
/* ---------------------------------------------------------------
* Overlay lecture (autoplay bloqué)
* --------------------------------------------------------------- */
#play-overlay {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 92px;
height: 92px;
border-radius: 50%;
background: rgba(11, 9, 8, 0.82);
border: 2px solid var(--xf-ember);
box-shadow: 0 0 40px rgba(217, 84, 31, 0.35);
display: none;
align-items: center;
justify-content: center;
cursor: pointer;
z-index: 25;
transition: transform 160ms cubic-bezier(0.16, 1, 0.3, 1);
}
#play-overlay:hover {
transform: translate(-50%, -50%) scale(1.06);
}
#play-overlay:active {
transform: translate(-50%, -50%) scale(0.94);
}
#play-overlay svg {
width: 40px;
height: 40px;
fill: var(--xf-cream);
margin-left: 5px;
}
/* ---------------------------------------------------------------
* Bouton « activer le son » (iOS)
* --------------------------------------------------------------- */
.xf-sound-btn {
position: absolute;
bottom: 26px;
left: 50%;
transform: translateX(-50%);
display: none;
align-items: center;
gap: 9px;
padding: 12px 22px;
border: 1px solid var(--xf-ember);
border-radius: 999px;
background: rgba(11, 9, 8, 0.88);
color: var(--xf-cream);
font-family: var(--xf-ui);
font-size: 12px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
cursor: pointer;
z-index: 26;
}
.xf-sound-btn svg {
width: 17px;
height: 17px;
fill: var(--xf-ember-light);
}
/* Respect des préférences d'accessibilité */
@media (prefers-reduced-motion: reduce) {
.xf-leader::after {
animation-duration: 2s;
}
#play-overlay {
transition: none;
}
}