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