@@ -14,6 +14,7 @@ interface OffsetOptions {
14
14
}
15
15
16
16
interface VideoReplayerOptions {
17
+ duration : number ;
17
18
onBuffer : ( isBuffering : boolean ) => void ;
18
19
onFinished : ( ) => void ;
19
20
onLoaded : ( event : any ) => void ;
@@ -56,6 +57,7 @@ export class VideoReplayer {
56
57
private _videos : Map < any , HTMLVideoElement > ;
57
58
private _videoApiPrefix : string ;
58
59
private _clipDuration : number | undefined ;
60
+ private _duration : number ;
59
61
public config : VideoReplayerConfig = {
60
62
skipInactive : false ,
61
63
speed : 1.0 ,
@@ -73,6 +75,7 @@ export class VideoReplayer {
73
75
onFinished,
74
76
onLoaded,
75
77
clipWindow,
78
+ duration,
76
79
} : VideoReplayerOptions
77
80
) {
78
81
this . _attachments = attachments ;
@@ -86,6 +89,7 @@ export class VideoReplayer {
86
89
} ;
87
90
this . _videos = new Map < any , HTMLVideoElement > ( ) ;
88
91
this . _clipDuration = undefined ;
92
+ this . _duration = duration ;
89
93
90
94
this . wrapper = document . createElement ( 'div' ) ;
91
95
if ( root ) {
@@ -297,7 +301,12 @@ export class VideoReplayer {
297
301
298
302
// No more segments
299
303
if ( nextIndex >= this . _attachments . length ) {
300
- this . stopReplay ( ) ;
304
+ // If we're at the end of a segment, but there's a gap
305
+ // at the end, force the replay to play until the end duration
306
+ // rather than stopping right away.
307
+ this . _timer . addNotificationAtTime ( this . _duration , ( ) => {
308
+ this . stopReplay ( ) ;
309
+ } ) ;
301
310
return ;
302
311
}
303
312
@@ -598,8 +607,13 @@ export class VideoReplayer {
598
607
const loadedSegmentIndex = await this . loadSegmentAtTime ( videoOffsetMs ) ;
599
608
600
609
if ( loadedSegmentIndex === undefined ) {
601
- // TODO: this shouldn't happen, loadSegment should load the previous
602
- // segment until it's time to start the next segment
610
+ // If we end up here, we seeked into a gap
611
+ // at the end of the replay.
612
+ // This tells the timer to stop at the specified duration
613
+ // and prevents the timer from running infinitely.
614
+ this . _timer . addNotificationAtTime ( this . _duration , ( ) => {
615
+ this . stopReplay ( ) ;
616
+ } ) ;
603
617
return Promise . resolve ( ) ;
604
618
}
605
619
0 commit comments