1
0
Fork 0
mirror of https://codeberg.org/ashley/poke.git synced 2024-11-17 01:34:43 -05:00

stuff stuff

This commit is contained in:
ashley 2024-09-28 13:19:14 +00:00
parent b4d566f41f
commit f5f88fe072

View file

@ -26,34 +26,35 @@ document.addEventListener("DOMContentLoaded", () => {
};
const isVideoBuffered = () => {
// Check if video has enough buffered data
const buffered = video.buffered();
return buffered.length > 0 && buffered.end(buffered.length - 1) >= video.currentTime();
};
const handleSeek = () => {
// Pause video and audio when seeking
video.pause();
audio.pause();
// Sync audio with video during seeking
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
audio.currentTime = video.currentTime();
}
// Wait for audio to be buffered sufficiently
if (!checkAudioBuffer()) {
audio.addEventListener('canplay', () => {
if (video.paused && isVideoBuffered()) {
video.play();
audio.play();
}
}, {
once: true
});
}, { once: true });
}
};
const handleBufferingComplete = () => {
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
audio.currentTime = video.currentTime();
}
};
// Sync when playback starts
video.on('play', () => {
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
audio.currentTime = video.currentTime();
@ -74,12 +75,16 @@ document.addEventListener("DOMContentLoaded", () => {
if (isVideoBuffered()) {
video.play();
}
audio.play(); // audio is playing after seek
audio.play();
});
video.on('volumechange', syncVolume);
audio.addEventListener('volumechange', syncVolumeWithVideo);
// Detect when video or audio finishes buffering
video.on('canplaythrough', handleBufferingComplete);
audio.addEventListener('canplaythrough', handleBufferingComplete);
// Listen for media control events
document.addEventListener('play', (e) => {
if (e.target === video) {