Update html/poketube.ejs

This commit is contained in:
ashley 2024-08-19 22:05:55 +00:00
parent 18785ff8c7
commit db151c1ec2

View file

@ -619,12 +619,11 @@ background-color: #0000;
</style>
<script>
document.addEventListener("DOMContentLoaded", () => {
document.addEventListener("DOMContentLoaded", () => {
const video = videojs('video', {
controls: true,
autoplay: false,
preload: 'auto',
});
const qua = new URLSearchParams(window.location.search).get("quality") || "";
@ -676,10 +675,28 @@ background-color: #0000;
};
video.on('play', () => {
if (isVideoBuffered()) {
// Sync audio with video before playing
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
audio.currentTime = video.currentTime();
}
// Wait for both video and audio to be buffered sufficiently
if (isVideoBuffered() && checkAudioBuffer()) {
video.play();
audio.play();
} else {
video.pause();
audio.pause();
const bufferListener = () => {
if (isVideoBuffered() && checkAudioBuffer()) {
video.play();
audio.play();
audio.removeEventListener('canplay', bufferListener);
}
};
audio.addEventListener('canplay', bufferListener);
}
});
@ -687,8 +704,6 @@ background-color: #0000;
audio.pause();
});
video.on('seeking', handleSeek);
video.on('seeked', () => {
@ -711,6 +726,7 @@ background-color: #0000;
video.pause();
audio.pause();
});
document.addEventListener('fullscreenchange', () => {
if (!document.fullscreenElement) {
video.pause();
@ -718,7 +734,8 @@ background-color: #0000;
}
});
}
});
});
</script>