@@ -131,12 +131,9 @@ export default class GapController {
131
131
const maxStartGapJump = isLive
132
132
? level ! . details ! . targetduration * 2
133
133
: MAX_START_GAP_JUMP ;
134
- if (
135
- startJump > 0 &&
136
- ( startJump <= maxStartGapJump ||
137
- this . fragmentTracker . getPartialFragment ( 0 ) )
138
- ) {
139
- this . _trySkipBufferHole ( null ) ;
134
+ const partialOrGap = this . fragmentTracker . getPartialFragment ( currentTime ) ;
135
+ if ( startJump > 0 && ( startJump <= maxStartGapJump || partialOrGap ) ) {
136
+ this . _trySkipBufferHole ( partialOrGap ) ;
140
137
return ;
141
138
}
142
139
}
@@ -187,7 +184,7 @@ export default class GapController {
187
184
// This method isn't limited by the size of the gap between buffered ranges
188
185
const targetTime = this . _trySkipBufferHole ( partial ) ;
189
186
// we return here in this case, meaning
190
- // the branch below only executes when we don 't handle a partial fragment
187
+ // the branch below only executes when we haven 't seeked to a new position
191
188
if ( targetTime || ! this . media ) {
192
189
return ;
193
190
}
@@ -248,27 +245,28 @@ export default class GapController {
248
245
if ( media === null ) {
249
246
return 0 ;
250
247
}
251
- const currentTime = media . currentTime ;
252
- let lastEndTime = 0 ;
248
+
253
249
// Check if currentTime is between unbuffered regions of partial fragments
254
- const buffered = BufferHelper . getBuffered ( media ) ;
255
- for ( let i = 0 ; i < buffered . length ; i ++ ) {
256
- const startTime = buffered . start ( i ) ;
257
- if (
258
- currentTime + config . maxBufferHole >= lastEndTime &&
259
- currentTime < startTime
260
- ) {
250
+ const currentTime = media . currentTime ;
251
+ const bufferInfo = BufferHelper . bufferInfo ( media , currentTime , 0 ) ;
252
+ const startTime =
253
+ currentTime < bufferInfo . start ? bufferInfo . start : bufferInfo . nextStart ;
254
+ if ( startTime ) {
255
+ const bufferStarved = bufferInfo . len <= config . maxBufferHole ;
256
+ const waiting =
257
+ bufferInfo . len > 0 && bufferInfo . len < 1 && media . readyState < 3 ;
258
+ if ( currentTime < startTime && ( bufferStarved || waiting ) ) {
261
259
const targetTime = Math . max (
262
260
startTime + SKIP_BUFFER_RANGE_START ,
263
- media . currentTime + SKIP_BUFFER_HOLE_STEP_SECONDS
261
+ currentTime + SKIP_BUFFER_HOLE_STEP_SECONDS
264
262
) ;
265
263
logger . warn (
266
264
`skipping hole, adjusting currentTime from ${ currentTime } to ${ targetTime } `
267
265
) ;
268
266
this . moved = true ;
269
267
this . stalled = null ;
270
268
media . currentTime = targetTime ;
271
- if ( partial ) {
269
+ if ( partial && ! partial . gap ) {
272
270
const error = new Error (
273
271
`fragment loaded with buffer holes, seeking from ${ currentTime } to ${ targetTime } `
274
272
) ;
@@ -283,7 +281,6 @@ export default class GapController {
283
281
}
284
282
return targetTime ;
285
283
}
286
- lastEndTime = buffered . end ( i ) ;
287
284
}
288
285
return 0 ;
289
286
}
0 commit comments