diff --git a/css/player-base-new.js b/css/player-base-new.js index 66df2ece..c38a1eab 100644 --- a/css/player-base-new.js +++ b/css/player-base-new.js @@ -4,9 +4,8 @@ var _yt_player = videojs; var versionclient = "youtube.player.web_20250917_22_RC00" - document.addEventListener("DOMContentLoaded", () => { - const player = videojs('video', { + const player = videojs('video', { controls: true, autoplay: false, preload: 'auto', @@ -16,12 +15,11 @@ document.addEventListener("DOMContentLoaded", () => { const videoEl = document.getElementById('video'); const audioEl = document.getElementById('aud'); - const qs = new URLSearchParams(location.search); + const qs = new URLSearchParams(location.search); const qua = qs.get("quality") || ""; const vidKey = qs.get('v') || ''; try { if (vidKey) localStorage.setItem(`progress-${vidKey}`, 0); } catch {} - // --- Source helpers -------------------------------------------------------- const initialSrcObj = player.src(); const initialVideoSrc = Array.isArray(initialSrcObj) ? (initialSrcObj[0]?.src || null) : (initialSrcObj || null); const initialVideoType = Array.isArray(initialSrcObj) ? (initialSrcObj[0]?.type || undefined) : undefined; @@ -47,18 +45,15 @@ document.addEventListener("DOMContentLoaded", () => { return Array.isArray(s) ? (s[0]?.type || undefined) : undefined; } - // --- State ----------------------------------------------------------------- let audioReady = false, videoReady = false; let syncInterval = null; let mediaSessionReady = false; - // Thresholds const BIG_DRIFT = 0.5; // hard snap const MICRO_DRIFT = 0.05; // rate nudge const SYNC_INTERVAL_MS = 250; const EPS = 0.15; - // --- Buffer/ready checks --------------------------------------------------- function timeInBuffered(media, t) { try { const br = media.buffered; @@ -84,8 +79,10 @@ document.addEventListener("DOMContentLoaded", () => { function safeSetCT(media, t) { try { if (isFinite(t) && t >= 0) media.currentTime = t; } catch {} } + function isActuallyPlaying(el) { + try { return !el.paused && !el.ended && (el.readyState || 0) >= 3; } catch { return false; } + } - // --- Sync loop (micro-drift) ---------------------------------------------- function clearSyncLoop() { if (syncInterval) { clearInterval(syncInterval); @@ -115,20 +112,14 @@ document.addEventListener("DOMContentLoaded", () => { }, SYNC_INTERVAL_MS); } - // --- Retry glue for raw media --------------------------------------------- - function attachRetry(elm, resolveSrc, markReady) { - const onLoaded = () => { - try { elm._didRetry = false; } catch {} - try { markReady && markReady(); } catch {} - tryStart(); - }; + function attachReady(elm, resolveSrc, markReady) { + const onLoaded = () => { try { markReady && markReady(); } catch {} tryStart(); }; elm.addEventListener('loadeddata', onLoaded, { once: true }); elm.addEventListener('loadedmetadata', onLoaded, { once: true }); elm.addEventListener('error', () => { const retryURL = resolveSrc?.(); - if (!elm._didRetry && retryURL) { - elm._didRetry = true; + if (retryURL) { try { elm.removeAttribute('src'); [...elm.querySelectorAll('source')].forEach(n => n.remove()); @@ -139,7 +130,6 @@ document.addEventListener("DOMContentLoaded", () => { }, { once: true }); } - // --- Volume & mute mirroring (both directions, loop-safe) ----------------- let volSyncGuard = false; function clamp01(v) { return Math.max(0, Math.min(1, Number(v))); } @@ -149,10 +139,8 @@ document.addEventListener("DOMContentLoaded", () => { try { const vMuted = !!player.muted(); const vVol = clamp01(player.volume()); - // Apply to audio audioEl.muted = vMuted; - audioEl.volume = vMuted ? audioEl.volume : vVol; // keep volume value but mute controls audibility - // Also ensure