mirror of
https://codeberg.org/ashley/poke
synced 2025-05-30 02:59:43 +00:00
Update css/player-base.js
This commit is contained in:
parent
daae5abff1
commit
26558507db
@ -19,8 +19,8 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
const vidSrcObj = video.src();
|
const vidSrcObj = video.src();
|
||||||
const videoSrc = Array.isArray(vidSrcObj) ? vidSrcObj[0].src : vidSrcObj;
|
const videoSrc = Array.isArray(vidSrcObj) ? vidSrcObj[0].src : vidSrcObj;
|
||||||
|
|
||||||
// flags to know which loaded first
|
|
||||||
let audioReady = false, videoReady = false;
|
let audioReady = false, videoReady = false;
|
||||||
|
let audioRetried = false, videoRetried = false;
|
||||||
let syncInterval = null;
|
let syncInterval = null;
|
||||||
|
|
||||||
// pauses and syncs the video when the seek is finished :3
|
// pauses and syncs the video when the seek is finished :3
|
||||||
@ -68,60 +68,23 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// retry loader for an HTMLMediaElement
|
// simple one-time retry on error
|
||||||
function loadWithRetryMedia(elm, src, onLoad, onError, maxRetries = Infinity, delay = 1000) {
|
function attachRetry(elm, src, markReady) {
|
||||||
let attempts = 0;
|
elm.addEventListener('loadeddata', () => {
|
||||||
function attempt() {
|
markReady();
|
||||||
attempts++;
|
tryStart();
|
||||||
elm.src = src;
|
}, { once: true });
|
||||||
elm.load();
|
|
||||||
|
|
||||||
function cleanup() {
|
elm.addEventListener('error', () => {
|
||||||
elm.removeEventListener('loadeddata', handleLoad);
|
// only retry once, and only if we have a valid src
|
||||||
elm.removeEventListener('error', handleError);
|
if (!elm._didRetry && src) {
|
||||||
|
elm._didRetry = true;
|
||||||
|
elm.src = src;
|
||||||
|
elm.load();
|
||||||
|
} else {
|
||||||
|
console.error(`${elm.tagName} failed to load.`);
|
||||||
}
|
}
|
||||||
function handleLoad() {
|
}, { once: true });
|
||||||
cleanup();
|
|
||||||
onLoad();
|
|
||||||
}
|
|
||||||
function handleError() {
|
|
||||||
cleanup();
|
|
||||||
if (attempts < maxRetries) setTimeout(attempt, delay);
|
|
||||||
else onError();
|
|
||||||
}
|
|
||||||
|
|
||||||
elm.addEventListener('loadeddata', handleLoad, { once: true });
|
|
||||||
elm.addEventListener('error', handleError, { once: true });
|
|
||||||
}
|
|
||||||
attempt();
|
|
||||||
}
|
|
||||||
|
|
||||||
// retry loader for Video.js player
|
|
||||||
function loadWithRetryVideoJS(player, src, onLoad, onError, maxRetries = Infinity, delay = 1000) {
|
|
||||||
let attempts = 0;
|
|
||||||
function attempt() {
|
|
||||||
attempts++;
|
|
||||||
player.src({ src, type: 'video/mp4' });
|
|
||||||
player.load();
|
|
||||||
|
|
||||||
function cleanup() {
|
|
||||||
player.off('loadeddata', handleLoad);
|
|
||||||
player.off('error', handleError);
|
|
||||||
}
|
|
||||||
function handleLoad() {
|
|
||||||
cleanup();
|
|
||||||
onLoad();
|
|
||||||
}
|
|
||||||
function handleError() {
|
|
||||||
cleanup();
|
|
||||||
if (attempts < maxRetries) setTimeout(attempt, delay);
|
|
||||||
else onError();
|
|
||||||
}
|
|
||||||
|
|
||||||
player.one('loadeddata', handleLoad);
|
|
||||||
player.one('error', handleError);
|
|
||||||
}
|
|
||||||
attempt();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// le volume :3
|
// le volume :3
|
||||||
@ -145,12 +108,12 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
navigator.mediaSession.setActionHandler('seekbackward', (details) => {
|
navigator.mediaSession.setActionHandler('seekbackward', (details) => {
|
||||||
const skip = details.seekOffset || 10;
|
const skip = details.seekOffset || 10;
|
||||||
video.currentTime(video.currentTime() - skip);
|
video.currentTime(video.currentTime() - skip);
|
||||||
audio.currentTime = audio.currentTime - skip;
|
audio.currentTime -= skip;
|
||||||
});
|
});
|
||||||
navigator.mediaSession.setActionHandler('seekforward', (details) => {
|
navigator.mediaSession.setActionHandler('seekforward', (details) => {
|
||||||
const skip = details.seekOffset || 10;
|
const skip = details.seekOffset || 10;
|
||||||
video.currentTime(video.currentTime() + skip);
|
video.currentTime(video.currentTime() + skip);
|
||||||
audio.currentTime = audio.currentTime + skip;
|
audio.currentTime += skip;
|
||||||
});
|
});
|
||||||
navigator.mediaSession.setActionHandler('seekto', (details) => {
|
navigator.mediaSession.setActionHandler('seekto', (details) => {
|
||||||
if (details.fastSeek && 'fastSeek' in audio) {
|
if (details.fastSeek && 'fastSeek' in audio) {
|
||||||
@ -171,19 +134,9 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (qua !== "medium") {
|
if (qua !== "medium") {
|
||||||
// 1) load audio with retry
|
// attach retry & ready markers
|
||||||
loadWithRetryMedia(
|
attachRetry(audio, audioSrc, () => { audioReady = true; });
|
||||||
audio, audioSrc,
|
attachRetry(video.el(), videoSrc, () => { videoReady = true; }); // video.el() gives the HTMLVideoElement
|
||||||
() => { audioReady = true; tryStart(); },
|
|
||||||
() => console.error("Audio failed to load after retries.")
|
|
||||||
);
|
|
||||||
|
|
||||||
// 2) load video with retry
|
|
||||||
loadWithRetryVideoJS(
|
|
||||||
video, videoSrc,
|
|
||||||
() => { videoReady = true; tryStart(); },
|
|
||||||
() => console.error("Video failed to load after retries.")
|
|
||||||
);
|
|
||||||
|
|
||||||
// Sync when playback starts
|
// Sync when playback starts
|
||||||
video.on('play', () => {
|
video.on('play', () => {
|
||||||
@ -244,8 +197,6 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// hai!! if ur asking why are they here - its for smth in the future!!!!!!
|
// hai!! if ur asking why are they here - its for smth in the future!!!!!!
|
||||||
|
|
||||||
const FORMATS = {
|
const FORMATS = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user