mirror of
https://github.com/R0m1k3/xtremobile.git
synced 2026-10-11 17:29:26 +02:00
375 lines
13 KiB
HTML
375 lines
13 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>IPTV Player</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
background: #000;
|
|
width: 100%;
|
|
height: 100vh;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
font-family: Arial, sans-serif;
|
|
}
|
|
|
|
#player-container {
|
|
width: 100%;
|
|
height: 100%;
|
|
position: relative;
|
|
}
|
|
|
|
#video {
|
|
width: 100%;
|
|
height: 100%;
|
|
background: #000;
|
|
}
|
|
|
|
#error {
|
|
display: none;
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
color: #fff;
|
|
text-align: center;
|
|
}
|
|
|
|
#error-icon {
|
|
font-size: 64px;
|
|
color: #f44336;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
#loading {
|
|
display: none;
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
color: #fff;
|
|
text-align: center;
|
|
}
|
|
|
|
.spinner {
|
|
width: 48px;
|
|
height: 48px;
|
|
border: 4px solid #fff;
|
|
border-top-color: transparent;
|
|
border-radius: 50%;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto 16px;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to {
|
|
transform: rotate(360deg);
|
|
}
|
|
}
|
|
|
|
#debug {
|
|
display: none;
|
|
/* Hidden in production */
|
|
position: absolute;
|
|
bottom: 10px;
|
|
left: 10px;
|
|
color: #0f0;
|
|
font-size: 12px;
|
|
font-family: monospace;
|
|
background: rgba(0, 0, 0, 0.7);
|
|
padding: 8px;
|
|
border-radius: 4px;
|
|
max-width: 80%;
|
|
word-break: break-all;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="player-container">
|
|
<video id="video" controls autoplay></video>
|
|
<div id="loading">
|
|
<div class="spinner"></div>
|
|
<div id="loading-text">Loading stream...</div>
|
|
</div>
|
|
<div id="error">
|
|
<div id="error-icon">⚠</div>
|
|
<div id="error-message">Failed to load stream</div>
|
|
</div>
|
|
<div id="debug"></div>
|
|
</div>
|
|
|
|
<!-- Try HLS.js first, then fall back to mpegts.js -->
|
|
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/mpegts.js@latest/dist/mpegts.min.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 debug = document.getElementById('debug');
|
|
|
|
// Get parameters from query string
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
let streamUrl = urlParams.get('url');
|
|
const startTime = parseFloat(urlParams.get('startTime') || '0');
|
|
let lastReportedTime = 0;
|
|
|
|
function log(msg) {
|
|
console.log(msg);
|
|
debug.textContent = msg;
|
|
}
|
|
|
|
// Report current playback position to parent (for resume feature)
|
|
function reportPosition() {
|
|
if (video.currentTime > 0 && !video.paused && video.readyState > 2) {
|
|
// Only report every 5 seconds or if time changed significantly
|
|
if (Math.abs(video.currentTime - lastReportedTime) >= 5) {
|
|
lastReportedTime = video.currentTime;
|
|
window.parent.postMessage({
|
|
type: 'playback_position',
|
|
currentTime: video.currentTime,
|
|
duration: video.duration || 0
|
|
}, '*');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Set up periodic position reporting
|
|
setInterval(reportPosition, 5000);
|
|
|
|
// Also report on pause
|
|
video.addEventListener('pause', () => {
|
|
window.parent.postMessage({
|
|
type: 'playback_position',
|
|
currentTime: video.currentTime,
|
|
duration: video.duration || 0
|
|
}, '*');
|
|
});
|
|
|
|
// Report when video ends
|
|
video.addEventListener('ended', () => {
|
|
window.parent.postMessage({
|
|
type: 'playback_ended',
|
|
duration: video.duration || 0
|
|
}, '*');
|
|
});
|
|
|
|
// Seek to startTime when video is ready
|
|
video.addEventListener('loadedmetadata', () => {
|
|
if (startTime > 0 && startTime < video.duration) {
|
|
video.currentTime = startTime;
|
|
log('Resuming from ' + Math.floor(startTime / 60) + 'm ' + Math.floor(startTime % 60) + 's');
|
|
}
|
|
});
|
|
|
|
function showLoading(msg) {
|
|
loading.style.display = 'block';
|
|
loadingText.textContent = msg || 'Loading stream...';
|
|
error.style.display = 'none';
|
|
}
|
|
|
|
function hideLoading() {
|
|
loading.style.display = 'none';
|
|
}
|
|
|
|
function showError(message) {
|
|
hideLoading();
|
|
error.style.display = 'block';
|
|
errorMessage.textContent = message || 'Failed to load stream';
|
|
}
|
|
|
|
async function playWithHLS(url) {
|
|
log('Trying HLS.js with: ' + url);
|
|
showLoading('Loading HLS stream...');
|
|
|
|
if (!Hls.isSupported()) {
|
|
// Try native HLS (Safari)
|
|
if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
|
video.src = url;
|
|
video.addEventListener('canplay', () => {
|
|
hideLoading();
|
|
video.play().catch(e => log('Autoplay prevented: ' + e));
|
|
});
|
|
video.addEventListener('error', () => {
|
|
showError('HLS playback error');
|
|
});
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Optimized HLS.js configuration for stable live streaming
|
|
const hls = new Hls({
|
|
// Increase buffer for smoother playback
|
|
maxBufferLength: 30, // Max 30 seconds of buffer
|
|
maxMaxBufferLength: 60, // Allow up to 60 seconds in stressed conditions
|
|
maxBufferSize: 60 * 1000000, // 60MB max buffer size
|
|
maxBufferHole: 0.5, // Tolerate 0.5s gaps in buffer
|
|
|
|
// Low latency settings (balanced)
|
|
liveSyncDurationCount: 3, // Sync to 3 segments behind live
|
|
liveMaxLatencyDurationCount: 6, // Max 6 segments behind before seeking
|
|
liveDurationInfinity: true, // Treat live streams as infinite
|
|
|
|
// Faster recovery from errors
|
|
manifestLoadingTimeOut: 15000, // 15s timeout for manifest
|
|
manifestLoadingMaxRetry: 4, // Retry manifest 4 times
|
|
manifestLoadingRetryDelay: 1000, // 1s between retries
|
|
levelLoadingTimeOut: 15000, // 15s for level playlist
|
|
levelLoadingMaxRetry: 4,
|
|
levelLoadingRetryDelay: 1000,
|
|
fragLoadingTimeOut: 20000, // 20s for fragments
|
|
fragLoadingMaxRetry: 6, // Retry fragments 6 times
|
|
fragLoadingRetryDelay: 1000,
|
|
|
|
// Better quality selection
|
|
startLevel: -1, // Auto-select start level
|
|
abrEwmaDefaultEstimate: 500000, // Start assuming 500kbps
|
|
abrBandWidthFactor: 0.95, // Use 95% of measured bandwidth
|
|
abrBandWidthUpFactor: 0.7, // Be cautious when upgrading quality
|
|
|
|
// Enable worker for better performance
|
|
enableWorker: true,
|
|
|
|
// Don't add extra headers
|
|
xhrSetup: function (xhr, url) { }
|
|
});
|
|
|
|
hls.loadSource(url);
|
|
hls.attachMedia(video);
|
|
|
|
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
|
log('HLS manifest parsed, starting playback');
|
|
hideLoading();
|
|
video.play().catch(e => log('Autoplay prevented: ' + e));
|
|
});
|
|
|
|
// Better error recovery
|
|
hls.on(Hls.Events.ERROR, (event, data) => {
|
|
log('HLS Error: ' + data.type + ' - ' + data.details);
|
|
|
|
if (data.fatal) {
|
|
switch (data.type) {
|
|
case Hls.ErrorTypes.NETWORK_ERROR:
|
|
log('Network error, attempting recovery...');
|
|
hls.startLoad(); // Try to recover network errors
|
|
break;
|
|
case Hls.ErrorTypes.MEDIA_ERROR:
|
|
log('Media error, attempting recovery...');
|
|
hls.recoverMediaError(); // Try to recover media errors
|
|
break;
|
|
default:
|
|
showError('HLS Error: ' + data.details);
|
|
hls.destroy();
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
return true;
|
|
}
|
|
|
|
async function playWithMpegTS(url) {
|
|
log('Trying mpegts.js with: ' + url);
|
|
showLoading('Loading MPEG-TS stream...');
|
|
|
|
if (!mpegts.isSupported()) {
|
|
return false;
|
|
}
|
|
|
|
const player = mpegts.createPlayer({
|
|
type: 'mpegts',
|
|
isLive: true,
|
|
url: url,
|
|
}, {
|
|
enableWorker: true,
|
|
enableStashBuffer: true,
|
|
stashInitialSize: 384 * 1024,
|
|
autoCleanupSourceBuffer: true,
|
|
});
|
|
|
|
player.attachMediaElement(video);
|
|
player.load();
|
|
|
|
video.addEventListener('canplay', () => {
|
|
log('MPEG-TS stream ready');
|
|
hideLoading();
|
|
video.play().catch(e => log('Autoplay prevented: ' + e));
|
|
});
|
|
|
|
video.addEventListener('error', (e) => {
|
|
showError('Video error: ' + (video.error?.message || 'Unknown error'));
|
|
});
|
|
|
|
player.on(mpegts.Events.ERROR, (errType, errDetail, errInfo) => {
|
|
log('mpegts error: ' + errType + ' - ' + errDetail);
|
|
showError('Stream error: ' + errDetail);
|
|
});
|
|
|
|
return true;
|
|
}
|
|
|
|
async function playDirect(url) {
|
|
log('Trying direct playback: ' + url);
|
|
showLoading('Loading stream directly...');
|
|
|
|
video.src = url;
|
|
video.addEventListener('canplay', () => {
|
|
hideLoading();
|
|
video.play().catch(e => log('Autoplay prevented: ' + e));
|
|
});
|
|
video.addEventListener('error', () => {
|
|
showError('Direct playback error');
|
|
});
|
|
}
|
|
|
|
async function initPlayer() {
|
|
if (!streamUrl) {
|
|
showError('No stream URL provided');
|
|
return;
|
|
}
|
|
|
|
log('Stream URL: ' + streamUrl.substring(0, 80) + '...');
|
|
|
|
// Determine stream type and try appropriate player
|
|
const lowerUrl = streamUrl.toLowerCase();
|
|
|
|
// Check for standard video files that should be played directly
|
|
if (lowerUrl.includes('.mp4') || lowerUrl.includes('.mkv') ||
|
|
lowerUrl.includes('.avi') || lowerUrl.includes('.webm') ||
|
|
lowerUrl.includes('.mov')) {
|
|
log('Detected direct video file, playing directly');
|
|
await playDirect(streamUrl);
|
|
}
|
|
// HLS streams
|
|
else if (lowerUrl.includes('.m3u8')) {
|
|
await playWithHLS(streamUrl);
|
|
}
|
|
// MPEG-TS streams
|
|
else if (lowerUrl.includes('.ts')) {
|
|
const success = await playWithMpegTS(streamUrl);
|
|
if (!success) {
|
|
await playDirect(streamUrl);
|
|
}
|
|
}
|
|
// Unknown format - try HLS first (for FFmpeg generated streams)
|
|
else {
|
|
await playWithHLS(streamUrl);
|
|
}
|
|
}
|
|
|
|
initPlayer();
|
|
</script>
|
|
</body>
|
|
|
|
</html> |