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> </style>
<script> <script>
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
const video = videojs('video', { const video = videojs('video', {
controls: true, controls: true,
autoplay: false, autoplay: false,
preload: 'auto', preload: 'auto',
}); });
const qua = new URLSearchParams(window.location.search).get("quality") || ""; const qua = new URLSearchParams(window.location.search).get("quality") || "";
@ -676,10 +675,28 @@ background-color: #0000;
}; };
video.on('play', () => { 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(); audio.play();
} else { } else {
video.pause(); 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(); audio.pause();
}); });
video.on('seeking', handleSeek); video.on('seeking', handleSeek);
video.on('seeked', () => { video.on('seeked', () => {
@ -711,6 +726,7 @@ background-color: #0000;
video.pause(); video.pause();
audio.pause(); audio.pause();
}); });
document.addEventListener('fullscreenchange', () => { document.addEventListener('fullscreenchange', () => {
if (!document.fullscreenElement) { if (!document.fullscreenElement) {
video.pause(); video.pause();
@ -718,7 +734,8 @@ background-color: #0000;
} }
}); });
} }
}); });
</script> </script>