Files
xtremflow/web/player_mobile.html
T

288 lines
9.3 KiB
HTML

<!DOCTYPE html>
<html>
<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>
<script src="https://cdn.jsdelivr.net/npm/hls.js@1.4.12/dist/hls.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mpegts.js@1.7.3/dist/mpegts.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
html,
body {
background: #000;
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: #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;
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 rgba(255, 255, 255, 0.2);
border-top-color: #fff;
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);
}
}
#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>
</head>
<body>
<div id="player-container">
<!-- iOS/Safari core attributes: playsinline, webkit-playsinline, preload -->
<video id="video" autoplay 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>
<div id="loading">
<div class="spinner"></div>
<div id="l-text" style="font-size: 14px; font-weight: 500;">Chargement...</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 style="font-size: 12px; color: rgba(255,255,255,0.6); margin-top: 8px;">Format non supporté ou lien
expiré</div>
</div>
</div>
<script>
const video = document.getElementById('video');
const loading = document.getElementById('loading');
const playOverlay = document.getElementById('play-overlay');
const error = document.getElementById('error');
const params = new URLSearchParams(window.location.search);
const streamUrl = params.get('url');
const streamType = params.get('type') || 'live';
function log(m) { console.log('[MobilePlayer] ' + m); }
playOverlay.addEventListener('click', (e) => {
e.preventDefault();
e.stopPropagation();
log('Manual play triggered');
video.play();
playOverlay.style.display = 'none';
});
// Double tap for fullscreen
let lastTap = 0;
video.addEventListener('touchend', (e) => {
const now = Date.now();
lastTap = now;
// Report activity to parent
window.parent.postMessage({ type: 'user_activity' }, '*');
});
video.addEventListener('playing', () => {
loading.style.display = 'none';
playOverlay.style.display = 'none';
});
video.addEventListener('pause', () => {
// If we're paused and not playing, and it looks like it was blocked or stopped
if (video.currentTime === 0 || video.paused) {
loading.style.display = 'none';
playOverlay.style.display = 'flex';
}
});
video.addEventListener('error', () => {
loading.style.display = 'none';
playOverlay.style.display = 'none';
error.style.display = 'block';
});
async function init() {
if (!streamUrl) {
log('No stream URL provided');
return;
}
log('Initing mobile player for: ' + streamUrl);
const isHLS = streamUrl.toLowerCase().includes('m3u8') || streamUrl.toLowerCase().includes('playlist.m3u8');
const isTS = streamUrl.toLowerCase().includes('/live/') || streamUrl.toLowerCase().endsWith('.ts');
// Safari / iOS Native HLS - MUST call load() and play()
if (isHLS && video.canPlayType('application/vnd.apple.mpegurl')) {
log('Using native HLS (Safari)');
video.src = streamUrl;
video.load();
video.play().catch(e => {
log('Autoplay blocked by Safari, showing overlay');
loading.style.display = 'none';
playOverlay.style.display = 'flex';
});
return;
}
// Android / Chrome - HLS.js
if (isHLS && Hls.isSupported()) {
log('Using Hls.js optimized for mobile');
const hls = new Hls({
maxBufferLength: 90,
maxMaxBufferLength: 180,
liveSyncDurationCount: 6,
liveMaxLatencyDurationCount: 12,
enableWorker: true,
lowLatencyMode: false
});
hls.loadSource(streamUrl);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
video.play().catch(e => playOverlay.style.display = 'flex');
});
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();
}
});
return;
}
// 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: 2 * 1024 * 1024,
enableStashBuffer: true
});
player.attachMediaElement(video);
player.load();
player.play().catch(e => playOverlay.style.display = 'flex');
return;
}
// Direct play with play overlay fallback
video.src = streamUrl;
video.load();
video.play().catch(e => playOverlay.style.display = 'flex');
}
// Communication with Flutter
window.addEventListener('message', (e) => {
const d = e.data;
if (d.type === 'play') video.play().catch(() => playOverlay.style.display = 'flex');
if (d.type === 'pause') video.pause();
});
init();
</script>
</body>
</html>