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

View file

@ -612,7 +612,7 @@ background-color: #0000;
</style>
<script>
document.addEventListener("DOMContentLoaded", () => {
document.addEventListener("DOMContentLoaded", () => {
const video = videojs('video', {
controls: true,
autoplay: false,
@ -667,34 +667,32 @@ background-color: #0000;
}
};
const syncPlayPause = () => {
if (video.paused) {
audio.pause();
video.on('play', () => {
if (isVideoBuffered()) {
audio.play();
} else {
audio.play().catch(() => {
video.pause();
});
video.pause();
}
};
});
video.on('play', syncPlayPause);
video.on('pause', syncPlayPause);
video.on('pause', () => {
audio.pause();
});
video.on('timeupdate', () => {
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
audio.pause(); // Pause audio if it's not in sync
audio.currentTime = video.currentTime();
audio.play();
}
});
video.on('seeking', handleSeek);
video.on('seeked', () => {
if (isVideoBuffered() && checkAudioBuffer()) {
if (isVideoBuffered()) {
video.play();
audio.play();
}
audio.play(); // Ensure audio is playing after seek
});
video.on('volumechange', syncVolume);
@ -706,28 +704,9 @@ background-color: #0000;
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>
<% if(dm) { %>