mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 02:19:01 +01:00
stuff stuff stuff
This commit is contained in:
parent
87eeac58a3
commit
890aec6a30
1 changed files with 28 additions and 16 deletions
|
@ -625,10 +625,6 @@ background-color: #0000;
|
|||
if (qua !== "medium") {
|
||||
const audio = document.getElementById('aud');
|
||||
|
||||
const syncAudioWithVideo = () => {
|
||||
|
||||
};
|
||||
|
||||
// Sync volume between audio and video
|
||||
const syncVolume = () => {
|
||||
audio.volume = video.volume();
|
||||
|
@ -644,6 +640,12 @@ background-color: #0000;
|
|||
return audio.currentTime <= bufferedEnd;
|
||||
};
|
||||
|
||||
const isVideoBuffered = () => {
|
||||
// Check if video has enough buffered data
|
||||
const buffered = video.buffered();
|
||||
return buffered.length > 0 && buffered.end(buffered.length - 1) >= video.currentTime();
|
||||
};
|
||||
|
||||
const handleSeek = () => {
|
||||
// Pause video and audio when seeking
|
||||
video.pause();
|
||||
|
@ -654,19 +656,23 @@ background-color: #0000;
|
|||
audio.currentTime = video.currentTime();
|
||||
}
|
||||
|
||||
// Wait for audio to be buffered sufficiently
|
||||
if (!checkAudioBuffer()) {
|
||||
// Resume playback when buffering is sufficient
|
||||
audio.addEventListener('canplay', () => {
|
||||
if (video.paused) {
|
||||
if (video.paused && isVideoBuffered()) {
|
||||
video.play();
|
||||
audio.play();
|
||||
}
|
||||
}, { once: true });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
video.on('play', () => {
|
||||
if (isVideoBuffered()) {
|
||||
audio.play();
|
||||
} else {
|
||||
video.pause();
|
||||
}
|
||||
});
|
||||
|
||||
video.on('pause', () => {
|
||||
|
@ -674,15 +680,19 @@ background-color: #0000;
|
|||
});
|
||||
|
||||
video.on('timeupdate', () => {
|
||||
syncAudioWithVideo();
|
||||
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
|
||||
audio.pause(); // Pause audio if it's not in sync
|
||||
audio.currentTime = video.currentTime();
|
||||
}
|
||||
});
|
||||
|
||||
video.on('seeking', handleSeek);
|
||||
|
||||
video.on('seeked', () => {
|
||||
if (video.paused && checkAudioBuffer()) {
|
||||
if (isVideoBuffered()) {
|
||||
video.play();
|
||||
}
|
||||
audio.play(); // Ensure audio is playing after seek
|
||||
});
|
||||
|
||||
video.on('volumechange', syncVolume);
|
||||
|
@ -691,10 +701,12 @@ background-color: #0000;
|
|||
document.addEventListener('fullscreenchange', () => {
|
||||
if (!document.fullscreenElement) {
|
||||
video.pause();
|
||||
audio.pause();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<% if(dm) { %>
|
||||
|
|
Loading…
Reference in a new issue