1
Fork 0
This commit is contained in:
ashley 2024-08-03 17:54:19 +00:00
parent eda2b4f887
commit c7b01a6af3

View file

@ -618,16 +618,15 @@ background-color: #0000;
autoplay: false,
preload: 'auto'
});
const qua = new URLSearchParams(window.location.search).get("quality") || "";
localStorage.setItem(`progress-${new URLSearchParams(window.location.search).get('v')}`, 0);
if (qua !== "medium") {
const audio = document.getElementById('aud');
// Sync audio with video
const syncAudioWithVideo = () => {
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
audio.currentTime = video.currentTime();
}
};
// Sync volume between audio and video
@ -640,21 +639,23 @@ background-color: #0000;
};
const checkAudioBuffer = () => {
// Check if audio buffered enough
const buffered = audio.buffered;
const bufferedEnd = buffered.length > 0 ? buffered.end(buffered.length - 1) : 0;
return audio.currentTime <= bufferedEnd;
};
const handleSeek = () => {
if (!checkAudioBuffer()) {
// Pause video and audio when seeking
video.pause();
}
audio.pause();
if (!checkAudioBuffer()) {
// Resume playback when buffering is sufficient
audio.addEventListener('canplay', () => {
if (video.paused) {
video.play();
}
}, { once: true });
}
};
video.on('play', () => {
@ -665,7 +666,9 @@ background-color: #0000;
audio.pause();
});
video.on('timeupdate', () => {
syncAudioWithVideo();
});
video.on('seeking', handleSeek);
@ -684,7 +687,6 @@ background-color: #0000;
}
});
}
});
</script>