66 lines
1.3 KiB
JavaScript
66 lines
1.3 KiB
JavaScript
import Hls from 'hls.js';
|
|
|
|
document.querySelectorAll('video[data-hls]').forEach((video) => {
|
|
const source = video.dataset.hls;
|
|
|
|
if (!source) {
|
|
return;
|
|
}
|
|
|
|
if (Hls.isSupported()) {
|
|
const playback = new Hls();
|
|
playback.loadSource(source);
|
|
playback.attachMedia(video);
|
|
|
|
return;
|
|
}
|
|
|
|
if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
|
video.src = source;
|
|
}
|
|
});
|
|
|
|
document.addEventListener('click', (event) => {
|
|
const fullscreen = event.target.closest('[data-fullscreen]');
|
|
|
|
if (fullscreen) {
|
|
const media = fullscreen.closest('.player')?.querySelector('video, audio');
|
|
|
|
if (media?.requestFullscreen) {
|
|
media.requestFullscreen();
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
const decision = event.target.closest('[data-course-decision]');
|
|
const restart = event.target.closest('[data-course-restart]');
|
|
const button = decision || restart;
|
|
|
|
if (!button) {
|
|
return;
|
|
}
|
|
|
|
const video = button.closest('li')?.querySelector('video');
|
|
|
|
if (!video) {
|
|
return;
|
|
}
|
|
|
|
if (restart) {
|
|
video.currentTime = 0;
|
|
video.play();
|
|
|
|
return;
|
|
}
|
|
|
|
const at = Number(video.dataset.decision);
|
|
|
|
if (Number.isNaN(at)) {
|
|
return;
|
|
}
|
|
|
|
video.currentTime = at;
|
|
video.pause();
|
|
});
|