Die Marken einer Fassung gehen als data-markers an das Video der Programm- und der Artikelseite, nur an Konten, die den Film streamen dürfen. player/member.js baut daraus Kapitelliste, den Schalter „Automatische Stopps“ (je Gerät gemerkt) und die Halt-Karte mit „Weiter“ und „Szene erneut“; das Anhalten nutzt dasselbe autostop.js wie die Vorschau der Redaktion. Das Vollbild geht bei Filmen mit Marken auf den Container, damit die Karte sichtbar bleibt; im nativen Videovollbild (Safari, iPhone) verlässt der Stopp das Vollbild. Verhaltensänderung: Der Altwert decision_seconds wurde nie ausgeliefert, hält Filme jetzt aber als Stoppmarke „Entscheidung“ an. CoursePlayerTest behält die Prüfung auf die entfallene Schaltfläche und belegt zusätzlich die gelieferte Marke. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
233 lines
7.5 KiB
JavaScript
233 lines
7.5 KiB
JavaScript
/*
|
|
* Mitglieder-Player: Marken, Kapitelliste, Autostopp und Vollbild über dem nativen <video controls>.
|
|
*
|
|
* Der Server liefert die Marken nur an Konten, die den Film streamen dürfen, als `data-markers` am Video (leere Liste:
|
|
* kein Attribut). Alle Texte der Marken gehen über textContent in die Seite, nie als HTML.
|
|
*
|
|
* Aufbau je Film: Halt-Karte über dem Bild (nur bei einem Stopp sichtbar), Knopf „Vollbild beenden“ (nur im Vollbild),
|
|
* darunter die Kapitelliste und der Schalter „Automatische Stopps“. Der Schalter gilt je Gerät für alle Filme.
|
|
* Logik ohne DOM steht in member-model.js, das Anhalten selbst in autostop.js (dieselbe Umsetzung wie in der Vorschau).
|
|
*/
|
|
import { bindAutostop } from './autostop.js';
|
|
import { canFullscreenContainer, exitFullscreen, isFullscreen } from './fullscreen.js';
|
|
import { currentIndex } from './markers.js';
|
|
import { chapterItems, clockLabel, jumpTo, previousStart, readAutoStop, readMarkers, writeAutoStop } from './member-model.js';
|
|
|
|
let counter = 0;
|
|
|
|
/** Alle eingebauten Player dieser Seite, damit der Schalter bei allen Filmen gleich steht. */
|
|
const players = new Set();
|
|
|
|
function storage() {
|
|
try {
|
|
return window.localStorage;
|
|
} catch (error) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function element(tag, className, text) {
|
|
const node = document.createElement(tag);
|
|
|
|
if (className) {
|
|
node.className = className;
|
|
}
|
|
|
|
if (text !== undefined) {
|
|
node.textContent = text;
|
|
}
|
|
|
|
return node;
|
|
}
|
|
|
|
function button(label, className, onClick) {
|
|
const node = element('button', className, label);
|
|
|
|
node.type = 'button';
|
|
node.addEventListener('click', onClick);
|
|
|
|
return node;
|
|
}
|
|
|
|
export function mountMemberPlayer(video) {
|
|
if (!(video instanceof HTMLVideoElement) || video.dataset.markersReady === '1') {
|
|
return null;
|
|
}
|
|
|
|
const markers = readMarkers(video.dataset.markers);
|
|
|
|
if (markers.length === 0) {
|
|
return null;
|
|
}
|
|
|
|
video.dataset.markersReady = '1';
|
|
counter += 1;
|
|
|
|
const box = video.closest('.mb-player') ?? video.parentElement;
|
|
const hasStops = markers.some((marker) => marker.stop);
|
|
const id = `mb-film-${counter}`;
|
|
|
|
// ---- Halt-Karte ----
|
|
const halt = element('div', 'mb-halt');
|
|
const kicker = element('p', 'mb-halt-kicker');
|
|
const title = element('h3', 'mb-halt-title');
|
|
const prompt = element('p', 'mb-halt-prompt');
|
|
const next = button('Weiter', 'button', () => player.autostop.resume());
|
|
const again = button('Szene erneut', 'button button-secondary', () => {
|
|
const stopped = player.autostop.stopped;
|
|
|
|
if (stopped !== null) {
|
|
jumpTo(video, previousStart(markers, stopped));
|
|
}
|
|
});
|
|
|
|
halt.hidden = true;
|
|
halt.id = `${id}-halt`;
|
|
halt.setAttribute('role', 'group');
|
|
halt.setAttribute('aria-labelledby', `${id}-halt-title`);
|
|
title.id = `${id}-halt-title`;
|
|
halt.append(kicker, title, prompt, element('div', 'mb-halt-actions'));
|
|
halt.lastChild.append(next, again);
|
|
box.append(halt);
|
|
|
|
// ---- Vollbild beenden (nur im Vollbild des Containers sichtbar) ----
|
|
const exit = button('Vollbild beenden', 'mb-player-exit', () => {
|
|
const active = document.fullscreenElement ?? document.webkitFullscreenElement;
|
|
|
|
if (active) {
|
|
(document.exitFullscreen ?? document.webkitExitFullscreen)?.call(document);
|
|
}
|
|
});
|
|
|
|
box.append(exit);
|
|
|
|
// Wo der Container ins Vollbild kann, führt der Player dorthin; das Vollbild des Videos selbst würde die Karte verdecken.
|
|
if (canFullscreenContainer(video)) {
|
|
video.setAttribute('controlslist', 'nofullscreen');
|
|
}
|
|
|
|
// ---- Kapitel und Schalter ----
|
|
const tools = element('section', 'mb-marken');
|
|
const list = element('ol', 'mb-kapitel');
|
|
const heading = element('h3', 'mb-marken-title', 'Kapitel');
|
|
let items = [];
|
|
|
|
tools.setAttribute('aria-labelledby', `${id}-kapitel`);
|
|
heading.id = `${id}-kapitel`;
|
|
tools.append(heading, list);
|
|
|
|
function renderChapters(duration) {
|
|
list.replaceChildren();
|
|
items = chapterItems(markers, { duration }).map((item) => {
|
|
const row = element('li', 'mb-kapitel-zeile');
|
|
const go = button('', 'mb-kapitel-link', () => jumpTo(video, item.t));
|
|
|
|
go.append(element('span', 'mb-kapitel-zeit', item.clock), element('span', 'mb-kapitel-name', item.label));
|
|
|
|
if (item.stop) {
|
|
go.append(element('span', 'mb-kapitel-stopp', 'Stopp'));
|
|
}
|
|
|
|
row.append(go);
|
|
list.append(row);
|
|
|
|
return { ...item, row, go };
|
|
});
|
|
markCurrent(true);
|
|
}
|
|
|
|
let shown = null;
|
|
|
|
function markCurrent(force = false) {
|
|
const index = currentIndex(markers, video.currentTime || 0);
|
|
|
|
if (!force && index === shown) {
|
|
return;
|
|
}
|
|
|
|
shown = index;
|
|
items.forEach((item) => {
|
|
if (item.index === index) {
|
|
item.go.setAttribute('aria-current', 'true');
|
|
} else {
|
|
item.go.removeAttribute('aria-current');
|
|
}
|
|
});
|
|
}
|
|
|
|
let toggle = null;
|
|
|
|
if (hasStops) {
|
|
const label = element('label', 'mb-marken-schalter');
|
|
|
|
toggle = element('input');
|
|
toggle.type = 'checkbox';
|
|
toggle.checked = readAutoStop(storage());
|
|
toggle.addEventListener('change', () => {
|
|
writeAutoStop(storage(), toggle.checked);
|
|
players.forEach((entry) => entry.sync(toggle.checked));
|
|
});
|
|
label.append(toggle, element('span', '', 'Automatische Stopps'));
|
|
tools.append(label, element('p', 'mb-hint mb-marken-hinweis', 'Der Film hält an den gekennzeichneten Stellen an. Mit „Weiter“ läuft er von dort.'));
|
|
}
|
|
|
|
box.insertAdjacentElement('afterend', tools);
|
|
|
|
// ---- Anhalten ----
|
|
const autostop = bindAutostop(video, markers, {
|
|
autoStop: toggle ? toggle.checked : true,
|
|
onStop(hit) {
|
|
kicker.textContent = `Angehalten bei ${clockLabel(hit.t)}`;
|
|
title.textContent = hit.label;
|
|
prompt.textContent = hit.prompt;
|
|
prompt.hidden = hit.prompt === '';
|
|
halt.hidden = false;
|
|
|
|
// Im nativen Videovollbild (Safari, iPhone) ist die Karte unsichtbar: heraus, damit sie erscheint.
|
|
if (isFullscreen(video)) {
|
|
exitFullscreen(video);
|
|
}
|
|
|
|
next.focus({ preventScroll: true });
|
|
},
|
|
onResume() {
|
|
const hadFocus = halt.contains(document.activeElement);
|
|
|
|
halt.hidden = true;
|
|
|
|
if (hadFocus) {
|
|
video.focus({ preventScroll: true });
|
|
}
|
|
},
|
|
});
|
|
|
|
const player = {
|
|
autostop,
|
|
sync(value) {
|
|
if (toggle) {
|
|
toggle.checked = value;
|
|
}
|
|
|
|
autostop.setAutoStop(value);
|
|
},
|
|
};
|
|
|
|
players.add(player);
|
|
renderChapters(null);
|
|
|
|
video.addEventListener('timeupdate', () => markCurrent());
|
|
video.addEventListener('seeked', () => markCurrent());
|
|
|
|
// Nur neu zeichnen, wenn sich die Liste ändert: Ein Neuzeichnen nähme dem Kapitelknopf mit Fokus den Fokus.
|
|
const refreshDuration = () => {
|
|
if (Number.isFinite(video.duration) && chapterItems(markers, { duration: video.duration }).length !== items.length) {
|
|
renderChapters(video.duration);
|
|
}
|
|
};
|
|
|
|
video.addEventListener('loadedmetadata', refreshDuration);
|
|
video.addEventListener('durationchange', refreshDuration);
|
|
|
|
return player;
|
|
}
|