This commit is contained in:
ashley 2024-08-03 17:46:18 +00:00
parent e4c3aab9ee
commit 5a1555f93e

View file

@ -618,12 +618,19 @@ background-color: #0000;
autoplay: false, autoplay: false,
preload: 'auto' preload: 'auto'
}); });
const qua = new URLSearchParams(window.location.search).get("qua") || "";
if (qua !== "medium") {
const audio = document.getElementById('aud'); const audio = document.getElementById('aud');
localStorage.setItem(`progress-${new URLSearchParams(window.location.search).get('v')}`, 0); // Sync audio with video
const syncAudioWithVideo = () => {
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
audio.currentTime = video.currentTime();
}
};
// Sync volume between audio and video
const syncVolume = () => { const syncVolume = () => {
audio.volume = video.volume(); audio.volume = video.volume();
}; };
@ -632,6 +639,24 @@ background-color: #0000;
video.volume(audio.volume); video.volume(audio.volume);
}; };
const checkAudioBuffer = () => {
// Check if audio buffered enough
const buffered = audio.buffered;
const bufferedEnd = buffered.length > 0 ? buffered.end(buffered.length - 1) : 0;
return audio.currentTime <= bufferedEnd;
};
const handleSeek = () => {
if (!checkAudioBuffer()) {
video.pause();
}
audio.addEventListener('canplay', () => {
if (video.paused) {
video.play();
}
}, { once: true });
};
video.on('play', () => { video.on('play', () => {
audio.play(); audio.play();
}); });
@ -640,16 +665,14 @@ background-color: #0000;
audio.pause(); audio.pause();
}); });
video.on('timeupdate', () => {
syncAudioWithVideo();
});
video.on('seeking', () => {
audio.currentTime = video.currentTime(); video.on('seeking', handleSeek);
});
video.on('seeked', () => { video.on('seeked', () => {
audio.currentTime = video.currentTime(); if (video.paused && checkAudioBuffer()) {
video.play();
}
}); });
video.on('volumechange', syncVolume); video.on('volumechange', syncVolume);
@ -661,7 +684,8 @@ background-color: #0000;
} }
}); });
}); });
</script> }
</script>
<% if(dm) { %> <% if(dm) { %>