mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-11 17:30:00 +02:00
406 lines
14 KiB
HTML
406 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>IPTV Player Lite</title>
|
|
<!-- HLS.js and mpegts.js for MPEG-TS support -->
|
|
<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;
|
|
}
|
|
|
|
html,
|
|
body {
|
|
background: #000;
|
|
width: 100%;
|
|
height: 100%;
|
|
overflow: hidden;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
#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;
|
|
font-family: Arial, sans-serif;
|
|
}
|
|
|
|
#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;
|
|
font-family: Arial, sans-serif;
|
|
}
|
|
|
|
.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);
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div id="player-container">
|
|
<!-- Native HTML5 controls enabled with 'controls' attribute -->
|
|
<video id="video" autoplay playsinline controls></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>
|
|
|
|
<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');
|
|
|
|
// 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 || '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';
|
|
}
|
|
|
|
// 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');
|
|
}
|
|
});
|
|
|
|
// Report position to parent for resume feature
|
|
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
|
|
}, '*');
|
|
}
|
|
}
|
|
}
|
|
setInterval(reportPosition, 5000);
|
|
|
|
// Report on pause and end
|
|
video.addEventListener('pause', () => {
|
|
window.parent.postMessage({
|
|
type: 'playback_position',
|
|
currentTime: video.currentTime,
|
|
duration: isFinite(video.duration) ? video.duration : 0
|
|
}, '*');
|
|
});
|
|
|
|
video.addEventListener('ended', () => {
|
|
window.parent.postMessage({
|
|
type: 'playback_ended',
|
|
duration: isFinite(video.duration) ? video.duration : 0
|
|
}, '*');
|
|
});
|
|
|
|
// Report user activity (mouse movement or touch) to parent for auto-hide controls
|
|
let lastActivityTime = 0;
|
|
function reportActivity() {
|
|
const now = Date.now();
|
|
if (now - lastActivityTime > 100) { // Throttle to 100ms
|
|
lastActivityTime = now;
|
|
window.parent.postMessage({
|
|
type: 'user_activity'
|
|
}, '*');
|
|
}
|
|
}
|
|
document.addEventListener('mousemove', reportActivity);
|
|
document.addEventListener('touchstart', reportActivity);
|
|
document.addEventListener('touchmove', reportActivity);
|
|
document.addEventListener('click', reportActivity);
|
|
document.addEventListener('touchend', reportActivity);
|
|
|
|
async function playWithHLS(url) {
|
|
log('Trying HLS.js with: ' + url);
|
|
showLoading('Loading HLS stream...');
|
|
|
|
if (!Hls.isSupported()) {
|
|
if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
|
video.src = url;
|
|
video.addEventListener('canplay', () => {
|
|
hideLoading();
|
|
video.play().catch(e => log('Autoplay prevented: ' + e));
|
|
});
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
const hls = new Hls({
|
|
maxBufferLength: 30,
|
|
maxMaxBufferLength: 60,
|
|
liveSyncDurationCount: 3,
|
|
liveMaxLatencyDurationCount: 6,
|
|
liveDurationInfinity: true,
|
|
enableWorker: true
|
|
});
|
|
|
|
window.hlsInstance = hls;
|
|
hls.loadSource(url);
|
|
hls.attachMedia(video);
|
|
|
|
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
|
log('HLS manifest parsed');
|
|
hideLoading();
|
|
video.play().catch(e => log('Autoplay prevented: ' + e));
|
|
});
|
|
|
|
hls.on(Hls.Events.ERROR, (event, data) => {
|
|
log('HLS Error: ' + data.type + ' - ' + data.details);
|
|
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);
|
|
hls.destroy();
|
|
}
|
|
}
|
|
});
|
|
|
|
return true;
|
|
}
|
|
|
|
async function playWithMpegTS(url, isLive = true) {
|
|
log('Trying mpegts.js with: ' + url + ' (isLive: ' + isLive + ')');
|
|
showLoading('Loading MPEG-TS stream...');
|
|
|
|
if (!mpegts.isSupported()) {
|
|
return false;
|
|
}
|
|
|
|
if (mpegts.getLoggingControl) {
|
|
mpegts.getLoggingControl().enableAll = false;
|
|
mpegts.getLoggingControl().enableError = true;
|
|
}
|
|
|
|
// Optimized configuration for stable Live TV playback
|
|
const playerConfig = {
|
|
enableWorker: true,
|
|
enableStashBuffer: true, // Enable buffering for stability
|
|
stashInitialSize: 1024 * 1024, // 1MB initial buffer
|
|
autoCleanupSourceBuffer: true,
|
|
autoCleanupMaxBackwardDuration: 60, // Keep 1 min of buffer
|
|
autoCleanupMinBackwardDuration: 30, // Cleanup after 30s
|
|
fixAudioTimestampGap: true, // Fix audio sync issues
|
|
liveBufferLatencyChasing: false, // Disable for stability (prevents skipping)
|
|
liveSync: false, // Don't auto-sync to edge
|
|
lazyLoad: false, // Load immediately
|
|
lazyLoadMaxDuration: 0,
|
|
lazyLoadRecoverDuration: 0,
|
|
};
|
|
|
|
const player = mpegts.createPlayer({
|
|
type: 'mpegts',
|
|
isLive: isLive,
|
|
url: url,
|
|
hasAudio: true,
|
|
hasVideo: true,
|
|
}, playerConfig);
|
|
|
|
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', () => {
|
|
showError('Video error: ' + (video.error?.message || 'Unknown error'));
|
|
});
|
|
|
|
player.on(mpegts.Events.ERROR, (errType, errDetail) => {
|
|
log('mpegts error: ' + errType + ' - ' + errDetail);
|
|
showError('Stream error: ' + errDetail);
|
|
});
|
|
|
|
return true;
|
|
}
|
|
|
|
async function playDirect(url) {
|
|
log('Trying direct playback: ' + url);
|
|
showLoading('Loading video...');
|
|
|
|
video.preload = 'auto';
|
|
let playStarted = false;
|
|
|
|
video.addEventListener('waiting', () => {
|
|
log('Buffering...');
|
|
showLoading('Buffering...');
|
|
});
|
|
|
|
video.addEventListener('playing', () => {
|
|
playStarted = true;
|
|
hideLoading();
|
|
});
|
|
|
|
const onCanPlay = () => {
|
|
playStarted = true;
|
|
hideLoading();
|
|
// FORCE AUDIO SETTINGS
|
|
video.muted = false;
|
|
video.volume = 1.0;
|
|
|
|
video.play().catch(e => {
|
|
log('Autoplay prevented: ' + e);
|
|
// If autoplay prevents sound/video, we should show a UI to user but native controls are there
|
|
// Try playing muted if failed
|
|
video.muted = true;
|
|
video.play().then(() => {
|
|
log('Autoplay started muted');
|
|
showError('Click to unmute'); // User can verify context
|
|
}).catch(e2 => log('Autoplay failed completely: ' + e2));
|
|
});
|
|
};
|
|
|
|
const onError = async () => {
|
|
if (!playStarted) {
|
|
log('Direct playback failed, trying fallbacks...');
|
|
video.removeEventListener('canplay', onCanPlay);
|
|
video.removeEventListener('error', onError);
|
|
|
|
// Fallback 1: HLS (common for streams)
|
|
log('Trying HLS fallback...');
|
|
if (await playWithHLS(url)) return;
|
|
|
|
// Fallback 2: MpegTS (for TS streams)
|
|
log('Comparing HLS failed, trying MpegTS fallback...');
|
|
if (await playWithMpegTS(url)) return;
|
|
|
|
showError('Format not supported. Try Standard player mode.');
|
|
}
|
|
};
|
|
|
|
video.addEventListener('canplay', onCanPlay, { once: true });
|
|
video.addEventListener('error', onError, { once: true });
|
|
|
|
video.src = url;
|
|
video.load();
|
|
return true;
|
|
}
|
|
|
|
async function initPlayer() {
|
|
if (!streamUrl) {
|
|
showError('No stream URL provided');
|
|
return;
|
|
}
|
|
|
|
log('Stream URL: ' + streamUrl);
|
|
log('Stream type: ' + streamType);
|
|
const lowerUrl = streamUrl.toLowerCase();
|
|
|
|
// LIVE TV: Direct MPEG-TS playback with mpegts.js
|
|
if (streamType === 'live') {
|
|
log('Live TV mode - using mpegts.js direct');
|
|
showLoading('Connecting to live stream...');
|
|
await playWithMpegTS(streamUrl, true);
|
|
return;
|
|
}
|
|
|
|
// VOD: Direct HTML5 playback with proxy
|
|
if (streamType === 'vod') {
|
|
log('VOD mode: Using direct playback');
|
|
showLoading('Loading video...');
|
|
await playDirect(streamUrl);
|
|
return;
|
|
}
|
|
|
|
// Fallback: detect from URL pattern
|
|
if (lowerUrl.includes('.m3u8') || lowerUrl.includes('/hls/')) {
|
|
await playWithHLS(streamUrl);
|
|
} else if (lowerUrl.includes('.mp4') || lowerUrl.includes('.mkv') ||
|
|
lowerUrl.includes('/movie/') || lowerUrl.includes('/series/')) {
|
|
await playDirect(streamUrl);
|
|
} else if (lowerUrl.includes('.ts') || lowerUrl.includes('/live/')) {
|
|
await playWithMpegTS(streamUrl, true);
|
|
} else {
|
|
await playDirect(streamUrl);
|
|
}
|
|
}
|
|
|
|
// Start player
|
|
initPlayer();
|
|
</script>
|
|
</body>
|
|
|
|
</html> |