mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 23:58:15 +01:00
bwa
This commit is contained in:
parent
e4c3aab9ee
commit
5a1555f93e
1 changed files with 36 additions and 12 deletions
|
@ -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,6 +684,7 @@ background-color: #0000;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<% if(dm) { %>
|
<% if(dm) { %>
|
||||||
|
|
Loading…
Reference in a new issue