mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 22:37:56 +01:00
ehe
This commit is contained in:
parent
eda2b4f887
commit
c7b01a6af3
1 changed files with 57 additions and 55 deletions
|
@ -612,79 +612,81 @@ 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") || "";
|
||||||
|
localStorage.setItem(`progress-${new URLSearchParams(window.location.search).get('v')}`, 0);
|
||||||
|
|
||||||
if (qua !== "medium") {
|
if (qua !== "medium") {
|
||||||
const audio = document.getElementById('aud');
|
const audio = document.getElementById('aud');
|
||||||
|
|
||||||
// Sync audio with video
|
const syncAudioWithVideo = () => {
|
||||||
const syncAudioWithVideo = () => {
|
|
||||||
if (Math.abs(video.currentTime() - audio.currentTime) > 0.3) {
|
};
|
||||||
audio.currentTime = video.currentTime();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Sync volume between audio and video
|
// Sync volume between audio and video
|
||||||
const syncVolume = () => {
|
const syncVolume = () => {
|
||||||
audio.volume = video.volume();
|
audio.volume = video.volume();
|
||||||
};
|
};
|
||||||
|
|
||||||
const syncVolumeWithVideo = () => {
|
const syncVolumeWithVideo = () => {
|
||||||
video.volume(audio.volume);
|
video.volume(audio.volume);
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkAudioBuffer = () => {
|
const checkAudioBuffer = () => {
|
||||||
// Check if audio buffered enough
|
const buffered = audio.buffered;
|
||||||
const buffered = audio.buffered;
|
const bufferedEnd = buffered.length > 0 ? buffered.end(buffered.length - 1) : 0;
|
||||||
const bufferedEnd = buffered.length > 0 ? buffered.end(buffered.length - 1) : 0;
|
return audio.currentTime <= bufferedEnd;
|
||||||
return audio.currentTime <= bufferedEnd;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
const handleSeek = () => {
|
const handleSeek = () => {
|
||||||
if (!checkAudioBuffer()) {
|
// Pause video and audio when seeking
|
||||||
video.pause();
|
video.pause();
|
||||||
}
|
audio.pause();
|
||||||
audio.addEventListener('canplay', () => {
|
if (!checkAudioBuffer()) {
|
||||||
if (video.paused) {
|
// Resume playback when buffering is sufficient
|
||||||
|
audio.addEventListener('canplay', () => {
|
||||||
|
if (video.paused) {
|
||||||
|
video.play();
|
||||||
|
}
|
||||||
|
}, { once: true });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
video.on('play', () => {
|
||||||
|
audio.play();
|
||||||
|
});
|
||||||
|
|
||||||
|
video.on('pause', () => {
|
||||||
|
audio.pause();
|
||||||
|
});
|
||||||
|
|
||||||
|
video.on('timeupdate', () => {
|
||||||
|
syncAudioWithVideo();
|
||||||
|
});
|
||||||
|
|
||||||
|
video.on('seeking', handleSeek);
|
||||||
|
|
||||||
|
video.on('seeked', () => {
|
||||||
|
if (video.paused && checkAudioBuffer()) {
|
||||||
video.play();
|
video.play();
|
||||||
}
|
}
|
||||||
}, { once: true });
|
});
|
||||||
};
|
|
||||||
|
|
||||||
video.on('play', () => {
|
video.on('volumechange', syncVolume);
|
||||||
audio.play();
|
audio.addEventListener('volumechange', syncVolumeWithVideo);
|
||||||
});
|
|
||||||
|
|
||||||
video.on('pause', () => {
|
document.addEventListener('fullscreenchange', () => {
|
||||||
audio.pause();
|
if (!document.fullscreenElement) {
|
||||||
});
|
video.pause();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
video.on('seeking', handleSeek);
|
|
||||||
|
|
||||||
video.on('seeked', () => {
|
|
||||||
if (video.paused && checkAudioBuffer()) {
|
|
||||||
video.play();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
video.on('volumechange', syncVolume);
|
|
||||||
audio.addEventListener('volumechange', syncVolumeWithVideo);
|
|
||||||
|
|
||||||
document.addEventListener('fullscreenchange', () => {
|
|
||||||
if (!document.fullscreenElement) {
|
|
||||||
video.pause();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue