@@ -14,7 +14,7 @@ import { replaceKeyframes } from '../clip/clip.utils';
1414import { ValidationError } from '../../errors' ;
1515import { Clip } from '../clip' ;
1616
17- import type { CaptionPresetStrategy , Track } from '../../tracks' ;
17+ import type { CaptionPresetStrategy , CaptionTrack , Track } from '../../tracks' ;
1818import type { float , frame } from '../../types' ;
1919import type { MediaClipProps } from './media.interfaces' ;
2020
@@ -145,7 +145,7 @@ export class MediaClip<Props extends MediaClipProps = MediaClipProps> extends As
145145 }
146146
147147 public async connect ( track : Track < MediaClip > ) : Promise < void > {
148- if ( [ 'LOADING' , 'IDLE' ] . includes ( this . state ) ) {
148+ if ( [ 'LOADING' , 'IDLE' ] . includes ( this . state ) && this . element ) {
149149 await new Promise ( this . resolve ( 'load' ) ) ;
150150 } ;
151151
@@ -277,23 +277,23 @@ export class MediaClip<Props extends MediaClipProps = MediaClipProps> extends As
277277
278278 /**
279279 * Generates a new caption track for the current clip using the specified captioning strategy.
280- * @param preset An optional CaptionPresetStrategy to define how captions should be generated.
280+ * @param strategy An optional CaptionPresetStrategy to define how captions should be generated.
281281 * @returns {Promise<void> } A promise that resolves when the caption track has been successfully created.
282282 */
283- public async generateCaptions ( preset ?: CaptionPresetStrategy ) : Promise < this > {
283+ public async generateCaptions ( strategy ?: CaptionPresetStrategy | ( new ( ) => CaptionPresetStrategy ) ) : Promise < CaptionTrack > {
284284 if ( ! this . track ?. composition ) {
285285 throw new ValidationError ( {
286286 i18n : 'compositionNotDefined' ,
287287 message : 'Captions can only be generated after the clip has been added to the composition' ,
288288 } ) ;
289289 }
290290
291- await this . track . composition
291+ const track = await this . track . composition
292292 . createTrack ( 'caption' )
293293 . from ( this )
294- . create ( preset ) ;
294+ . generate ( strategy ) ;
295295
296- return this ;
296+ return track ;
297297 }
298298
299299 public set ( props ?: Props ) : this {
0 commit comments