Skip to content

🎥 Make videos programmatically with React

Merge pull request #5739 from remotion-dev/copilot/fix-adc9df7d-d800-4546-a37e-c445a45586a4

Jonny Burger4fb86bc9b68e
diff --cc packages/media/src/video/media-player.ts
index a4fb6daceb,6aec1ebe1d..0b0b52594d
--- a/packages/media/src/video/media-player.ts
+++ b/packages/media/src/video/media-player.ts
@@@ -75,9 -75,9 +75,9 @@@ export class MediaPlayer
logLevel: LogLevel;
sharedAudioContext: AudioContext;
}) {
- this.canvas = canvas;
+ this.canvas = canvas ?? null;
this.src = src;
- this.logLevel = logLevel ?? 'info';
+ this.logLevel = logLevel ?? window.remotion_logLevel;
this.sharedAudioContext = sharedAudioContext;
this.playbackRate = 1;
@@@ -296,32 -300,16 +300,32 @@@
node.onended = () => this.queuedAudioNodes.delete(node);
}
- public onBufferingChange(callback: (isBuffering: boolean) => void): void {
+ public onBufferingChange(
+ callback: (isBuffering: boolean) => void,
+ ): () => void {
this.onBufferingChangeCallback = callback;
+
+ return () => {
+ if (this.onBufferingChangeCallback === callback) {
+ this.onBufferingChangeCallback = undefined;
+ }
+ };
}
- public onVideoFrame(callback: (frame: CanvasImageSource) => void): void {
+ public onVideoFrame(
+ callback: (frame: CanvasImageSource) => void,
+ ): () => void {
this.onVideoFrameCallback = callback;
- if (this.initialized && callback) {
+ if (this.initialized && callback && this.canvas) {
callback(this.canvas);
}
+
+ return () => {
+ if (this.onVideoFrameCallback === callback) {
+ this.onVideoFrameCallback = undefined;
+ }
+ };
}
private canRenderVideo(): boolean {