Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(video): synchronize live component playback settings

yhh76163be49821
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c0f104d73..7b49b5d9a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Video component playback settings update live streams.** Changing volume, mute, loop, or playback rate updates the current stream without reopening the decoder. Unchanged settings avoid repeated backend calls across frames; source changes still create a stream with the current settings.
+
- **Video plugin cleanup releases only the selected App.** Shared plugin instances retain separate video backends and stream maps for each App, so closing a preview cannot stop another App's video or leave its own backend behind. Cleanup detaches the world subscription and disables its old update system. Stopping component streams also retires them from the video service instead of pumping stopped handles.
- **Video components switch streams when their source changes.** Changing a live component's source releases its previous stream and opens the new source. Unchanged sources keep their stream across frames; clearing the source or removing the entity still releases the current stream.
diff --git a/sdk/src/video/VideoPlugin.ts b/sdk/src/video/VideoPlugin.ts
index b9b6c6cbf..4455b232e 100644
--- a/sdk/src/video/VideoPlugin.ts
+++ b/sdk/src/video/VideoPlugin.ts
@@ -66,6 +66,8 @@ interface VideoPluginState {
released: boolean;
}
+type StreamSettings = Pick<VideoData, 'source' | 'volume' | 'muted' | 'loop' | 'playbackRate'>;
+
export class VideoPlugin implements Plugin {
name = 'video';
private readonly states_ = new WeakMap<App, VideoPluginState>();
@@ -87,7 +89,7 @@ export class VideoPlugin implements Plugin {
app.insertResource(VideoPlayer, video);
const handles = new Map<number, VideoStreamHandle>();
- const sources = new WeakMap<VideoStreamHandle, string>();
+ const settings = new WeakMap<VideoStreamHandle, StreamSettings>();
const warnedNoSprite = new Set<number>();
const live = new Set<number>();
@@ -124,7 +126,8 @@ export class VideoPlugin implements Plugin {
const id = entity as number;
live.add(id);
const previous = handles.get(id);
- if (!previous || sources.get(previous) !== v.source) {
+ const applied = previous ? settings.get(previous) : undefined;
+ if (!previous || !applied || applied.source !== v.source) {
if (previous) videoAPI.stop(previous);
const handle = videoAPI.play(v.source, {
autoplay: v.autoplay,
@@ -134,7 +137,15 @@ export class VideoPlugin implements Plugin {
playbackRate: v.playbackRate,
});
handles.set(id, handle);
- sources.set(handle, v.source);
+ settings.set(handle, { source: v.source, volume: v.volume, muted: v.muted,
+ loop: v.loop, playbackRate: v.playbackRate });
+ } else {
+ if (applied.volume !== v.volume) { previous.setVolume(v.volume); applied.volume = v.volume; }
+ if (applied.muted !== v.muted) { previous.setMuted(v.muted); applied.muted = v.muted; }
+ if (applied.loop !== v.loop) { previous.setLoop(v.loop); applied.loop = v.loop; }
+ if (applied.playbackRate !== v.playbackRate) {
+ previous.setPlaybackRate(v.playbackRate); applied.playbackRate = v.playbackRate;
+ }
}
}
diff --git a/sdk/tests/video-source-switch.test.ts b/sdk/tests/video-source-switch.test.ts
index 4a9d4f93a..5cd0a2c36 100644
--- a/sdk/tests/video-source-switch.test.ts
+++ b/sdk/tests/video-source-switch.test.ts
@@ -14,6 +14,29 @@ vi.mock('../src/platform/base', async original => ({
const apps: App[] = [];
afterEach(() => { for (const app of apps.splice(0)) app.quit(); vi.clearAllMocks(); });
+it('applies changed playback settings once without recreating the stream', async () => {
+ backend.createStream.mockImplementation((_url, options) => {
+ const handle = new NullVideoBackend().createStream('', options);
+ for (const key of ['stop', 'setVolume', 'setMuted', 'setLoop', 'setPlaybackRate'] as const) vi.spyOn(handle, key);
+ return handle;
+ });
+ const app = App.new(); apps.push(app); app.addPlugin(new VideoPlugin());
+ const entity = app.world.spawn(); app.world.insert(entity, Video, { source: 'clip.mp4' });
+ await app.tick(1 / 60);
+ const handle = backend.createStream.mock.results[0].value;
+ app.world.update(entity, Video, value => {
+ value.volume = 0.25; value.muted = false; value.loop = false; value.playbackRate = 2;
+ });
+ await app.tick(1 / 60);
+ expect(handle.setVolume).toHaveBeenCalledWith(0.25);
+ expect(handle.setMuted).toHaveBeenCalledWith(false);
+ expect(handle.setLoop).toHaveBeenCalledWith(false);
+ expect(handle.setPlaybackRate).toHaveBeenCalledWith(2);
+ for (let i = 0; i < 100; i++) await app.tick(1 / 60);
+ for (const key of ['setVolume', 'setMuted', 'setLoop', 'setPlaybackRate'] as const) expect(handle[key]).toHaveBeenCalledOnce();
+ expect(backend.createStream).toHaveBeenCalledOnce(); expect(handle.stop).not.toHaveBeenCalled();
+});
+
it('switches a live source without restarting unchanged streams and releases retired handles', async () => {
const handles: ReturnType<NullVideoBackend['createStream']>[] = [];
backend.createStream.mockImplementation((_url, options) => {
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 911612ce7..83c39c6e4 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(video): synchronize live component playback settings':
+ { note: 'Video component playback settings update live streams.' },
'fix(video): isolate plugin cleanup and stream ownership per app':
{ note: 'Video plugin cleanup releases only the selected App.' },
'fix(video): replace live streams when component sources change':