1
Fork 0

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