mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-15 06:48:43 +01:00
test 1
This commit is contained in:
parent
00a7738a1d
commit
adc02ed151
1 changed files with 93 additions and 93 deletions
|
@ -7,112 +7,112 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
|
||||||
const qua = new URLSearchParams(window.location.search).get("quality") || "";
|
const qua = new URLSearchParams(window.location.search).get("quality") || "";
|
||||||
localStorage.setItem(`progress-${new URLSearchParams(window.location.search).get('v')}`, 0);
|
localStorage.setItem(`progress-${new URLSearchParams(window.location.search).get('v')}`, 0);
|
||||||
|
if (qua !== "medium") {
|
||||||
|
const audio = document.getElementById('aud');
|
||||||
|
|
||||||
if (qua !== "medium") {
|
const syncVolume = () => {
|
||||||
const audio = document.getElementById('aud');
|
audio.volume = video.volume();
|
||||||
|
};
|
||||||
|
|
||||||
const syncVolume = () => {
|
const syncVolumeWithVideo = () => {
|
||||||
audio.volume = video.volume();
|
video.volume(audio.volume);
|
||||||
};
|
};
|
||||||
|
|
||||||
const syncVolumeWithVideo = () => {
|
const checkAudioBuffer = () => {
|
||||||
video.volume(audio.volume);
|
const buffered = audio.buffered;
|
||||||
};
|
const bufferedEnd = buffered.length > 0 ? buffered.end(buffered.length - 1) : 0;
|
||||||
|
return audio.currentTime <= bufferedEnd;
|
||||||
|
};
|
||||||
|
|
||||||
const checkAudioBuffer = () => {
|
const isVideoBuffered = () => {
|
||||||
const buffered = audio.buffered;
|
// Check if video has enough buffered data
|
||||||
const bufferedEnd = buffered.length > 0 ? buffered.end(buffered.length - 1) : 0;
|
const buffered = video.buffered();
|
||||||
return audio.currentTime <= bufferedEnd;
|
return buffered.length > 0 && buffered.end(buffered.length - 1) >= video.currentTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
const isVideoBuffered = () => {
|
const handleSeek = () => {
|
||||||
// Check if video has enough buffered data
|
// Pause video and audio when seeking
|
||||||
const buffered = video.buffered();
|
video.pause();
|
||||||
return buffered.length > 0 && buffered.end(buffered.length - 1) >= video.currentTime();
|
audio.pause();
|
||||||
};
|
|
||||||
|
|
||||||
const handleSeek = () => {
|
// Sync audio with video during seeking
|
||||||
// Pause video and audio when seeking
|
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
|
||||||
video.pause();
|
audio.currentTime = video.currentTime();
|
||||||
audio.pause();
|
}
|
||||||
|
|
||||||
// Sync audio with video during seeking
|
// Wait for audio to be buffered sufficiently
|
||||||
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
|
if (!checkAudioBuffer()) {
|
||||||
audio.currentTime = video.currentTime();
|
audio.addEventListener('canplay', () => {
|
||||||
}
|
if (video.paused && isVideoBuffered()) {
|
||||||
|
video.play();
|
||||||
|
audio.play();
|
||||||
|
}
|
||||||
|
}, { once: true });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Wait for audio to be buffered sufficiently
|
const playBothIfBuffered = () => {
|
||||||
if (!checkAudioBuffer()) {
|
if (isVideoBuffered() && checkAudioBuffer()) {
|
||||||
audio.addEventListener('canplay', () => {
|
|
||||||
if (video.paused && isVideoBuffered()) {
|
|
||||||
video.play();
|
|
||||||
audio.play();
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
once: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
video.on('play', () => {
|
|
||||||
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
|
|
||||||
audio.currentTime = video.currentTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isVideoBuffered()) {
|
|
||||||
audio.play();
|
|
||||||
} else {
|
|
||||||
video.pause();
|
|
||||||
audio.pause();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
video.on('pause', () => {
|
|
||||||
audio.pause();
|
|
||||||
});
|
|
||||||
|
|
||||||
video.on('waiting', () => {
|
|
||||||
video.pause();
|
|
||||||
audio.pause();
|
|
||||||
});
|
|
||||||
|
|
||||||
video.on('canplaythrough', () => {
|
|
||||||
if (!video.paused()) {
|
|
||||||
video.play();
|
|
||||||
audio.play();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
video.on('seeking', handleSeek);
|
|
||||||
|
|
||||||
video.on('seeked', () => {
|
|
||||||
if (isVideoBuffered()) {
|
|
||||||
video.play();
|
|
||||||
}
|
|
||||||
audio.play(); // Ensure audio is playing after seek
|
|
||||||
});
|
|
||||||
|
|
||||||
video.on('volumechange', syncVolume);
|
|
||||||
audio.addEventListener('volumechange', syncVolumeWithVideo);
|
|
||||||
|
|
||||||
// Listen for media control events
|
|
||||||
document.addEventListener('play', () => {
|
|
||||||
video.play();
|
video.play();
|
||||||
audio.play();
|
audio.play();
|
||||||
});
|
}
|
||||||
|
};
|
||||||
|
|
||||||
document.addEventListener('pause', () => {
|
video.on('play', () => {
|
||||||
|
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
|
||||||
|
audio.currentTime = video.currentTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isVideoBuffered()) {
|
||||||
|
audio.play();
|
||||||
|
} else {
|
||||||
video.pause();
|
video.pause();
|
||||||
audio.pause();
|
audio.pause();
|
||||||
});
|
}
|
||||||
document.addEventListener('fullscreenchange', () => {
|
});
|
||||||
if (!document.fullscreenElement) {
|
|
||||||
video.pause();
|
video.on('pause', () => {
|
||||||
audio.pause();
|
audio.pause();
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
video.on('waiting', () => {
|
||||||
});
|
video.pause();
|
||||||
|
audio.pause();
|
||||||
|
|
||||||
|
// Add event listener to resume when buffering is done
|
||||||
|
video.on('canplaythrough', playBothIfBuffered);
|
||||||
|
});
|
||||||
|
|
||||||
|
video.on('canplaythrough', playBothIfBuffered);
|
||||||
|
|
||||||
|
video.on('seeking', handleSeek);
|
||||||
|
|
||||||
|
video.on('seeked', () => {
|
||||||
|
playBothIfBuffered();
|
||||||
|
});
|
||||||
|
|
||||||
|
video.on('volumechange', syncVolume);
|
||||||
|
audio.addEventListener('volumechange', syncVolumeWithVideo);
|
||||||
|
|
||||||
|
// Listen for media control events
|
||||||
|
document.addEventListener('play', () => {
|
||||||
|
video.play();
|
||||||
|
audio.play();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('pause', () => {
|
||||||
|
video.pause();
|
||||||
|
audio.pause();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('fullscreenchange', () => {
|
||||||
|
if (!document.fullscreenElement) {
|
||||||
|
video.pause();
|
||||||
|
audio.pause();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
window.pokePlayer = {
|
window.pokePlayer = {
|
||||||
ver:`16-vjs-${videojs.VERSION}`,
|
ver:`16-vjs-${videojs.VERSION}`,
|
||||||
|
|
Loading…
Reference in a new issue