This commit is contained in:
ashley 2024-08-03 19:28:32 +00:00
parent fa6a64c5f3
commit 1d0d76832d

View file

@ -667,34 +667,32 @@ background-color: #0000;
} }
}; };
const syncPlayPause = () => { video.on('play', () => {
if (video.paused) { if (isVideoBuffered()) {
audio.pause(); audio.play();
} else { } else {
audio.play().catch(() => {
video.pause(); video.pause();
});
} }
}; });
video.on('play', syncPlayPause); video.on('pause', () => {
video.on('pause', syncPlayPause); audio.pause();
});
video.on('timeupdate', () => { video.on('timeupdate', () => {
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) { if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
audio.pause(); // Pause audio if it's not in sync audio.pause(); // Pause audio if it's not in sync
audio.currentTime = video.currentTime(); audio.currentTime = video.currentTime();
audio.play();
} }
}); });
video.on('seeking', handleSeek); video.on('seeking', handleSeek);
video.on('seeked', () => { video.on('seeked', () => {
if (isVideoBuffered() && checkAudioBuffer()) { if (isVideoBuffered()) {
video.play(); video.play();
audio.play();
} }
audio.play(); // Ensure audio is playing after seek
}); });
video.on('volumechange', syncVolume); video.on('volumechange', syncVolume);
@ -706,28 +704,9 @@ background-color: #0000;
audio.pause(); audio.pause();
} }
}); });
// Ensure audio and video are both ready before playing
let videoReady = false;
let audioReady = false;
video.on('canplay', () => {
videoReady = true;
if (videoReady && audioReady) {
video.play();
audio.play();
} }
}); });
audio.addEventListener('canplay', () => {
audioReady = true;
if (videoReady && audioReady) {
video.play();
audio.play();
}
});
}
});
</script> </script>
<% if(dm) { %> <% if(dm) { %>