Disable pause - Twitch-style live mode (always seek to live edge)

This commit is contained in:
Sebastjan 2026-04-25 09:04:46 +02:00
parent df416506bd
commit 34fa2d6d41

View File

@ -466,7 +466,9 @@
</div>
<div class="player-frame" id="playerFrame">
<video id="v" autoplay muted playsinline></video>
<video id="v" autoplay muted playsinline tabindex="-1"
disablepictureinpicture
controlsList="nodownload nofullscreen noremoteplayback noplaybackrate"></video>
<div class="player-msg visible" id="msg">
<div class="spinner"></div>
@ -654,8 +656,61 @@
lastT = video.currentTime;
}, 5000);
video.addEventListener('pause', () => setTimeout(() => video.play().catch(() => {}), 100));
document.addEventListener('visibilitychange', () => { if (!document.hidden) video.play().catch(() => {}); });
// Live-only mode (Twitch style) — pause is disabled.
// If anything pauses the video, resume immediately AND seek to the live edge.
function seekToLive() {
try {
if (hls && hls.liveSyncPosition) {
video.currentTime = hls.liveSyncPosition;
} else if (video.seekable && video.seekable.length > 0) {
video.currentTime = video.seekable.end(video.seekable.length - 1);
}
} catch (e) {}
}
video.addEventListener('pause', () => {
setTimeout(() => {
seekToLive();
video.play().catch(() => {});
}, 80);
});
// If user seeks back (e.g. via keyboard or scrubber), force forward to live
video.addEventListener('seeked', () => {
if (!hls) return;
if (hls.liveSyncPosition && video.currentTime < hls.liveSyncPosition - 10) {
video.currentTime = hls.liveSyncPosition;
}
});
// Block right-click context menu (hides "Pause", "Save video as", etc.)
video.addEventListener('contextmenu', (e) => e.preventDefault());
// Block Picture-in-Picture (its UI exposes pause)
video.disablePictureInPicture = true;
video.setAttribute('disablePictureInPicture', 'true');
// Block remote playback (AirPlay/Cast — can pause unexpectedly)
try { video.disableRemotePlayback = true; } catch (e) {}
// Block keyboard shortcuts that could pause: spacebar, K, Media keys
document.addEventListener('keydown', (e) => {
// Only intercept if focus is on body or video (not in input fields)
const tag = (e.target && e.target.tagName) || '';
if (tag === 'INPUT' || tag === 'TEXTAREA') return;
if (e.key === ' ' || e.key === 'Spacebar' || e.code === 'Space' ||
e.key === 'k' || e.key === 'K' ||
e.key === 'MediaPlayPause' || e.key === 'MediaPause') {
e.preventDefault();
// Make sure we keep playing
if (video.paused) {
seekToLive();
video.play().catch(() => {});
}
}
});
document.addEventListener('visibilitychange', () => {
if (!document.hidden) {
seekToLive();
video.play().catch(() => {});
}
});
// Audio toggle
function updateAudio() {