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
@@ -213,6 +213,51 @@ describe('VideoLibrary driven players (#404)', () => {
|
||||
expect(videos.showsAsked(key)).toBe(true);
|
||||
});
|
||||
|
||||
it('holds a driven player quiet as soon as its wearer is gone, as an ended composition item', async () => {
|
||||
vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval', 'performance'] });
|
||||
const events = new Map<string, () => void>();
|
||||
let frames: (() => void)[] = [];
|
||||
const element = {
|
||||
...fakeVideo(),
|
||||
ended: false,
|
||||
duration: 10,
|
||||
playbackRate: 1,
|
||||
seeking: false,
|
||||
readyState: 4,
|
||||
videoWidth: 320,
|
||||
videoHeight: 180,
|
||||
play() {
|
||||
this.paused = false;
|
||||
return Promise.resolve();
|
||||
},
|
||||
pause() {
|
||||
this.paused = true;
|
||||
},
|
||||
addEventListener: (type: string, listener: () => void) => events.set(type, listener),
|
||||
requestVideoFrameCallback: (callback: () => void) => frames.push(callback),
|
||||
};
|
||||
vi.stubGlobal('document', { hidden: false, addEventListener: () => {}, createElement: () => element });
|
||||
const { soundLibrary } = await import('../../src/viewport/SoundLibrary');
|
||||
vi.spyOn(soundLibrary, 'mediaInput').mockReturnValue(null);
|
||||
const videos = await freshLibrary();
|
||||
const props = { videoClock: 'driven', videoTime: 0 };
|
||||
videos.wear(REF, props, 'view1:a', 'game');
|
||||
events.get('loadeddata')!();
|
||||
[frames] = [[], ...frames.map((frame) => frame())];
|
||||
// Worn at 1x for a second, heard.
|
||||
for (let ms = 0; ms <= 1000; ms += 1000 / 60) {
|
||||
element.currentTime = ms / 1000;
|
||||
videos.wear(REF, { ...props, videoTime: ms / 1000 }, 'view1:a', 'game');
|
||||
vi.advanceTimersByTime(1000 / 60);
|
||||
}
|
||||
expect([element.paused, element.muted]).toEqual([false, false]);
|
||||
// The item ends: nothing wears the player any more. Let go only after 2 s, it played on heard.
|
||||
vi.advanceTimersByTime(200);
|
||||
expect([element.paused, element.muted]).toEqual([true, true]);
|
||||
expect(videos.debugInfo()).toHaveLength(1);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('tells a view whether one of its driven players still waits for its first picture', async () => {
|
||||
const videos = await freshLibrary();
|
||||
videos.get(KEY);
|
||||
|
||||
Reference in new issue
Block a user