Skip to Content
Welcome to Diffusion Studio Core v4.0 - Now Available! šŸŽ‰

Events

In Diffusion Studio, the Composition emits various events related to playback control and composition state changes:

const composition = new core.Composition(); // Playback events composition.on('playback:start', () => { console.log('Playback started'); }); composition.on('playback:end', () => { console.log('Playback ended'); }); composition.on('playback:time', (time: number | undefined) => { console.log('Current playback time:', time); }); // Layer events composition.on('layer:add', () => { console.log('Layer added'); }); composition.on('layer:remove', () => { console.log('Layer removed'); }); // Composition events composition.on('resize', () => { console.log('Composition resized'); }); composition.on('restored', () => { console.log('Composition restored'); });

Event Types

The Composition emits the following events:

EventPayload TypeDescription
playback:startundefinedEmitted when playback starts
playback:endundefinedEmitted when playback ends
playback:timenumber | undefinedEmitted during playback with the current time
layer:addundefinedEmitted when a layer is added to the composition
layer:removeundefinedEmitted when a layer is removed from the composition
resizeundefinedEmitted when the composition is resized
restoredundefinedEmitted when the composition state is restored

Unsubscribing from Events

The on method returns an event ID, which you can use to unsubscribe from events when they are no longer needed:

const playbackTimeEvt = composition.on('playback:time', (time) => { console.log('Time:', time); }); composition.off(playbackTimeEvt);

Alternatively you can call the return value to unsubscribe from the event:

const unsubscribe = composition.on('playback:start', () => { console.log('Playback started'); }); unsubscribe();

Which allows this pattern in react:

useEffect(() => { return composition.on('playback:end', (time) => { setPlaying(false); }); }, []);
Last updated on