fix(player): a step onto an unplayable video carries on the way it went
Previous onto an embed-blocked or removed video skipped forward again (the auto-advance direction), straight back to the item just left. The player now remembers the direction of the step that reached the item and the videos YouTube refused this session: an error carries on that way, Previous / Next pass over known-dead items without loading them, and go dark when only those are left. A step of your own skips with auto-advance off too.
This commit is contained in:
@@ -28,3 +28,25 @@ export function afterRemoval(
|
||||
const next = rest[Math.min(Math.max(index, 0), rest.length - 1)]!;
|
||||
return { queue: rest, playingId: next.id };
|
||||
}
|
||||
|
||||
/** The nearest item from `index` going `dir` that is not known to be unplayable, or -1 when there is
|
||||
* none that way. `wrap` goes round the ends (Loop "All"), never back onto `index` itself.
|
||||
*
|
||||
* A video YouTube refused to play (embed-blocked, removed) is remembered for the player session, so
|
||||
* Previous / Next pass over it instead of loading it again only to be bounced off it. */
|
||||
export function stepIndex(
|
||||
queue: readonly Video[],
|
||||
index: number,
|
||||
dir: 1 | -1,
|
||||
dead: ReadonlySet<string>,
|
||||
wrap = false,
|
||||
): number {
|
||||
const n = queue.length;
|
||||
for (let k = 1; k < n; k++) {
|
||||
const raw = index + dir * k;
|
||||
if (!wrap && (raw < 0 || raw >= n)) return -1;
|
||||
const j = ((raw % n) + n) % n;
|
||||
if (!dead.has(queue[j]!.id)) return j;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user