이지선다: 재생기가 준비되기 전에 A→B를 누르면 준비된 뒤 A·B가 같이 나오던 것(A→A 멈춤도 A가 나옴) — 다른 카드를 누르거나 멈출 때 기다리던 불러오기를 취소. e2e에 준비 전 A→B·A→A 회귀(가짜 플레이어 준비 지연 mq:fakeInitMs)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-23 21:19:12 +09:00
parent a688557879
commit ced94614ca
3 changed files with 64 additions and 7 deletions

View File

@@ -26,6 +26,8 @@ interface Slot {
loaded: boolean;
/** Bumped by every command, so an older preload stops before pausing a song the player started meanwhile. */
tk: number;
/** A tap before the player was ready: the load waits for it (cancelled when another card is tapped or this one again). */
pending: boolean;
}
const slots = new Map<DuelSide, Slot>();
@@ -40,6 +42,7 @@ function make(): Slot {
gain: 1,
loaded: false,
tk: 0,
pending: false,
};
s.engine = cardEngine({
onError: (code) => {
@@ -89,6 +92,16 @@ async function preload(s: Slot): Promise<void> {
video: (side: DuelSide) => slots.get(side)?.videoId ?? null,
};
/** Stop this card: pause it and drop a load still waiting for the player to get ready. */
function halt(s: Slot): void {
if (s.pending) {
s.tk++;
s.pending = false;
s.loaded = false;
}
s.engine.pause();
}
const volumeOf = (s: Slot) => Math.round(usePlayer.getState().volume * s.gain);
usePlayer.subscribe((st, prev) => {
@@ -103,8 +116,8 @@ export const duelPlayer = {
key = k;
const old = new Map(slots);
for (const s of old.values()) {
halt(s);
s.tk++;
s.engine.pause();
}
useDuelPlayer.setState({ playing: null });
const next = new Map<DuelSide, Slot>();
@@ -133,11 +146,11 @@ export const duelPlayer = {
if (!s?.videoId) return;
const st = useDuelPlayer.getState();
if (st.playing === side) {
s.engine.pause();
halt(s);
useDuelPlayer.setState({ playing: null });
return;
}
for (const [other, o] of slots) if (other !== side) o.engine.pause();
for (const [other, o] of slots) if (other !== side) halt(o);
const tk = ++s.tk;
const e = s.engine;
const id = s.videoId;
@@ -146,7 +159,12 @@ export const duelPlayer = {
if (s.loaded) e.play();
else {
s.loaded = true;
void s.ready.then(() => tk === s.tk && e.load(id, s.startSec));
s.pending = true;
void s.ready.then(() => {
if (tk !== s.tk) return;
s.pending = false;
e.load(id, s.startSec);
});
}
useDuelPlayer.setState({ playing: side });
},
@@ -154,8 +172,8 @@ export const duelPlayer = {
stop(): void {
key = '';
for (const s of slots.values()) {
halt(s);
s.tk++;
s.engine.pause();
}
useDuelPlayer.setState({ playing: null });
},

View File

@@ -249,7 +249,11 @@ function fakeEngine(l: Listener): Engine {
(window as unknown as { mqFake: typeof fake }).mqFake = fake;
const time = () => (state === 1 ? base + (performance.now() - since) / 1000 : base);
return {
init: () => Promise.resolve(),
// e2e: localStorage mq:fakeInitMs makes the player get ready late (taps before it is ready)
init: () => {
const ms = Number(localStorage.getItem('mq:fakeInitMs') ?? 0);
return ms > 0 ? new Promise<void>((r) => setTimeout(r, ms)) : Promise.resolve();
},
unlock: () => {},
load(id, startSec) {
current = id;