1
0
Fork 0
mirror of https://codeberg.org/ashley/poke.git synced 2024-11-17 04:14:39 -05:00
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,
preload: 'auto'
});
const qua = new URLSearchParams(window.location.search).get("qua") || "";
if (qua !== "medium") {
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 = () => {
audio.volume = video.volume();
};
@ -632,6 +639,24 @@ background-color: #0000;
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', () => {
audio.play();
});
@ -640,16 +665,14 @@ background-color: #0000;
audio.pause();
});
video.on('timeupdate', () => {
syncAudioWithVideo();
});
video.on('seeking', () => {
audio.currentTime = video.currentTime();
});
video.on('seeking', handleSeek);
video.on('seeked', () => {
audio.currentTime = video.currentTime();
if (video.paused && checkAudioBuffer()) {
video.play();
}
});
video.on('volumechange', syncVolume);
@ -661,6 +684,7 @@ background-color: #0000;
}
});
});
}
</script>
<% if(dm) { %>