@@ -67,7 +67,7 @@ import {
67
67
} from './models/ai-highlighter.models' ;
68
68
import { HighlighterViews } from './highlighter-views' ;
69
69
import { startRendering } from './rendering/start-rendering' ;
70
- import { cutHighlightClips } from './cut-highlight-clips' ;
70
+ import { cutHighlightClips , getVideoDuration } from './cut-highlight-clips' ;
71
71
import { reduce } from 'lodash' ;
72
72
import { extractDateTimeFromPath , fileExists } from './file-utils' ;
73
73
import { addVerticalFilterToExportOptions } from './vertical-export' ;
@@ -449,12 +449,28 @@ export class HighlighterService extends PersistentStatefulService<IHighlighterSt
449
449
} ) ;
450
450
451
451
this . streamingService . latestRecordingPath . subscribe ( path => {
452
+ // Check if recording is immediately available
453
+ getVideoDuration ( path )
454
+ . then ( duration => {
455
+ if ( isNaN ( duration ) ) {
456
+ duration = - 1 ;
457
+ }
458
+ this . usageStatisticsService . recordAnalyticsEvent ( 'AIHighlighter' , {
459
+ type : 'FinishRecording' ,
460
+ duration,
461
+ } ) ;
462
+ console . log ( 'Successfully got duration' , duration ) ;
463
+ } )
464
+ . catch ( error => {
465
+ console . error ( 'Failed getting duration right after the recoding.' , error ) ;
466
+ } ) ;
467
+
452
468
if ( ! aiRecordingInProgress ) {
453
469
return ;
454
470
}
455
471
456
472
aiRecordingInProgress = false ;
457
- this . detectAndClipAiHighlights ( path , streamInfo ) ;
473
+ this . detectAndClipAiHighlights ( path , streamInfo , true ) ;
458
474
459
475
this . navigationService . actions . navigate (
460
476
'Highlighter' ,
@@ -1186,6 +1202,7 @@ export class HighlighterService extends PersistentStatefulService<IHighlighterSt
1186
1202
async detectAndClipAiHighlights (
1187
1203
filePath : string ,
1188
1204
streamInfo : IStreamInfoForAiHighlighter ,
1205
+ delayStart = false ,
1189
1206
) : Promise < void > {
1190
1207
if ( this . aiHighlighterFeatureEnabled === false ) {
1191
1208
console . log ( 'HighlighterService: Not enabled' ) ;
@@ -1246,6 +1263,10 @@ export class HighlighterService extends PersistentStatefulService<IHighlighterSt
1246
1263
1247
1264
console . log ( '🔄 HighlighterData' ) ;
1248
1265
try {
1266
+ if ( delayStart ) {
1267
+ await this . wait ( 5000 ) ;
1268
+ }
1269
+
1249
1270
const highlighterResponse = await getHighlightClips (
1250
1271
filePath ,
1251
1272
this . userService . getLocalUserId ( ) ,
@@ -1492,4 +1513,13 @@ export class HighlighterService extends PersistentStatefulService<IHighlighterSt
1492
1513
1493
1514
return id ;
1494
1515
}
1516
+
1517
+ /**
1518
+ * Utility function that returns a promise that resolves after a specified delay
1519
+ * @param ms Delay in milliseconds
1520
+ * @returns Promise that resolves after the delay
1521
+ */
1522
+ wait ( ms : number ) : Promise < void > {
1523
+ return new Promise < void > ( resolve => setTimeout ( resolve , ms ) ) ;
1524
+ }
1495
1525
}
0 commit comments