stuff stuff stuff

This commit is contained in:
ashley 2024-08-03 18:22:48 +00:00
parent 87eeac58a3
commit 890aec6a30

View file

@ -625,10 +625,6 @@ background-color: #0000;
if (qua !== "medium") {
const audio = document.getElementById('aud');
const syncAudioWithVideo = () => {
};
// Sync volume between audio and video
const syncVolume = () => {
audio.volume = video.volume();
@ -644,6 +640,12 @@ background-color: #0000;
return audio.currentTime <= bufferedEnd;
};
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();
@ -654,19 +656,23 @@ background-color: #0000;
audio.currentTime = video.currentTime();
}
// Wait for audio to be buffered sufficiently
if (!checkAudioBuffer()) {
// Resume playback when buffering is sufficient
audio.addEventListener('canplay', () => {
if (video.paused) {
if (video.paused && isVideoBuffered()) {
video.play();
audio.play();
}
}, { once: true });
}
};
video.on('play', () => {
if (isVideoBuffered()) {
audio.play();
} else {
video.pause();
}
});
video.on('pause', () => {
@ -674,15 +680,19 @@ background-color: #0000;
});
video.on('timeupdate', () => {
syncAudioWithVideo();
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
audio.pause(); // Pause audio if it's not in sync
audio.currentTime = video.currentTime();
}
});
video.on('seeking', handleSeek);
video.on('seeked', () => {
if (video.paused && checkAudioBuffer()) {
if (isVideoBuffered()) {
video.play();
}
audio.play(); // Ensure audio is playing after seek
});
video.on('volumechange', syncVolume);
@ -691,10 +701,12 @@ background-color: #0000;
document.addEventListener('fullscreenchange', () => {
if (!document.fullscreenElement) {
video.pause();
audio.pause();
}
});
}
});
</script>
<% if(dm) { %>