@@ -94,14 +94,14 @@ export function removeCuesInRange(
94
94
}
95
95
}
96
96
97
- // Find first cue starting after given time.
97
+ // Find first cue starting at or after given time.
98
98
// Modified version of binary search O(log(n)).
99
- function getFirstCueIndexAfterTime (
99
+ function getFirstCueIndexFromTime (
100
100
cues : TextTrackCueList | TextTrackCue [ ] ,
101
101
time : number ,
102
102
) : number {
103
- // If first cue starts after time, start there
104
- if ( time < cues [ 0 ] . startTime ) {
103
+ // If first cue starts at or after time, start there
104
+ if ( time <= cues [ 0 ] . startTime ) {
105
105
return 0 ;
106
106
}
107
107
// If the last cue ends before time there is no overlap
@@ -112,9 +112,9 @@ function getFirstCueIndexAfterTime(
112
112
113
113
let left = 0 ;
114
114
let right = len ;
115
-
115
+ let mid ;
116
116
while ( left <= right ) {
117
- const mid = Math . floor ( ( right + left ) / 2 ) ;
117
+ mid = Math . floor ( ( right + left ) / 2 ) ;
118
118
119
119
if ( time < cues [ mid ] . startTime ) {
120
120
right = mid - 1 ;
@@ -138,7 +138,7 @@ export function getCuesInRange(
138
138
end : number ,
139
139
) : TextTrackCue [ ] {
140
140
const cuesFound : TextTrackCue [ ] = [ ] ;
141
- const firstCueInRange = getFirstCueIndexAfterTime ( cues , start ) ;
141
+ const firstCueInRange = getFirstCueIndexFromTime ( cues , start ) ;
142
142
if ( firstCueInRange > - 1 ) {
143
143
for ( let i = firstCueInRange , len = cues . length ; i < len ; i ++ ) {
144
144
const cue = cues [ i ] ;
0 commit comments