Silence a composition video as soon as its item ends
A video in a composition plays on a driven player that the item tells where to stand every frame. When the item ended, its object was gone and stopped asking, but the player ran on with its sound until it was let go for being unused. That took 2 to 4 seconds, and in a pause it never happened at all. The same held for the composition preview. - A driven player nobody asked for in 100 ms is now paused and muted. When its wearer comes back it carries on where it should be, as before. It is still let go after 2 to 4 seconds. - A player still without its first picture keeps playing, without sound, because it only gets that picture by playing. - Leaving the animation or composition tab now silences their video preview at once instead of after 2 to 4 seconds. - Free videos (Video clock free) keep the old behaviour. A sprite destroyed by a behavior is still heard for 2 to 4 seconds. Tests: - Unit video-library: 10 green (1 new). Without the new timer the new test is red. - e2e 68: ALL PASSED, 11 checks (68g new). An item of 0.5 s with a 2 s video plays audibly while it is there, and the player is paused and muted in every frame from about 200 ms after it ends. - Gate on melektaus-atx: green, 305 files, 4737 tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
126a5a3a62
commit
65d7bf6a1f
4 files changed
+111
-2
No files matched your search
@@ -37,6 +37,12 @@ export function videoFileUrl(file: string): string {
|
||||
const END_SLACK = 1 / 60;
|
||||
/** A player nothing has asked for in this long is let go: no sprite wears it any more. */
|
||||
const IDLE_MS = 2000;
|
||||
/**
|
||||
* A driven player (#404) nothing has asked for in this long is held and quiet: its wearer is gone,
|
||||
* like the sprite of a composition item that has ended, or no longer drawn. It runs on by itself
|
||||
* otherwise, heard, until it is let go.
|
||||
*/
|
||||
const HUSH_MS = 100;
|
||||
|
||||
/**
|
||||
* When the frame being drawn began, in milliseconds like `performance.now()`. The ticker moves every
|
||||
@@ -85,6 +91,7 @@ export class VideoLibrary {
|
||||
private heard = false;
|
||||
private paused = false;
|
||||
private sweeper: ReturnType<typeof setInterval> | null = null;
|
||||
private husher: ReturnType<typeof setInterval> | null = null;
|
||||
/** When the page was last shown, by `performance.now()`; see `sweep`. */
|
||||
private shown = 0;
|
||||
|
||||
@@ -230,9 +237,24 @@ export class VideoLibrary {
|
||||
if (this.players.size === 0) this.stopSweeping();
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds and quiets the driven players nobody asked for lately, see `HUSH_MS`. One still without
|
||||
* its first picture plays on, without sound: it only gets one by playing (see `openVideo`).
|
||||
*/
|
||||
private hush(): void {
|
||||
const now = performance.now();
|
||||
for (const player of this.players.values()) {
|
||||
if (!player.drive || !player.texture || now - player.asked <= HUSH_MS) continue;
|
||||
player.element.muted = true;
|
||||
if (!player.element.paused) player.element.pause();
|
||||
}
|
||||
}
|
||||
|
||||
private stopSweeping(): void {
|
||||
if (this.sweeper !== null) clearInterval(this.sweeper);
|
||||
if (this.husher !== null) clearInterval(this.husher);
|
||||
this.sweeper = null;
|
||||
this.husher = null;
|
||||
}
|
||||
|
||||
/** What each player is doing (test hook). */
|
||||
@@ -288,6 +310,7 @@ export class VideoLibrary {
|
||||
};
|
||||
this.players.set(key, player);
|
||||
this.sweeper ??= setInterval(() => this.sweep(), IDLE_MS);
|
||||
if (drive) this.husher ??= setInterval(() => this.hush(), HUSH_MS);
|
||||
if (drive)
|
||||
chaseSeeks(
|
||||
player.element,
|
||||
|
||||
Reference in new issue
Block a user