🎥 Make videos programmatically with React
- not just draw the first frame, but also buffer correctly
Igor Samokhovetsd76bc00dd072
diff --git a/packages/video/src/media-player.ts b/packages/video/src/media-player.tsindex 9b6da59bfa..59e820bd14 100644--- a/packages/video/src/media-player.ts+++ b/packages/video/src/media-player.ts@@ -129,33 +129,18 @@ export class MediaPlayer {this.initialized = true;- if (!this.canvasSink) {- throw new Error('No canvas sink found');- }-- try {- const tempIterator = this.canvasSink.canvases(startTime);- const firstFrame = (await tempIterator.next()).value;-- if (firstFrame) {- this.context.drawImage(firstFrame.canvas, 0, 0);- Log.trace(- this.logLevel,- `[MediaPlayer] Drew initial frame at timestamp ${firstFrame.timestamp.toFixed(3)}s`,- );- }+ await this.startVideoIterator(startTime);- await tempIterator.return();- } catch (error) {- Log.error(- '[MediaPlayer] Failed to draw initial frame during initialization',- error,- );+ if (this.audioSink) {+ this.audioBufferIterator = this.audioSink.buffers(startTime);+ this.runAudioIterator();}+ this.startRenderLoop();+Log.trace(this.logLevel,- `[MediaPlayer] Initialized successfully, duration: ${this.totalDuration}s`,+ `[MediaPlayer] Initialized successfully with iterators started, duration: ${this.totalDuration}s`,);} catch (error) {Log.error('[MediaPlayer] Failed to initialize', error);