@@ -302,45 +302,30 @@ export default class StreamController
302
302
} else if ( this . backtrackFragment && bufferInfo . len ) {
303
303
this . backtrackFragment = null ;
304
304
}
305
- if ( frag ) {
306
- // Avoid loop loading by using nextLoadPosition set for backtracking and skipping consecutive GAP tags
307
- const trackerState = this . fragmentTracker . getState ( frag ) ;
308
- if (
309
- ( trackerState === FragmentState . OK ||
310
- ( trackerState === FragmentState . PARTIAL && frag . gap ) ) &&
311
- this . nextLoadPosition > targetBufferTime
312
- ) {
313
- const gapStart = frag . gap ;
314
- if ( ! gapStart ) {
315
- // Cleanup the fragment tracker before trying to find the next unbuffered fragment
316
- const type =
317
- this . audioOnly && ! this . altAudio
318
- ? ElementaryStreamTypes . AUDIO
319
- : ElementaryStreamTypes . VIDEO ;
320
- const mediaBuffer =
321
- ( type === ElementaryStreamTypes . VIDEO
322
- ? this . videoBuffer
323
- : this . mediaBuffer ) || this . media ;
324
- if ( mediaBuffer ) {
325
- this . afterBufferFlushed ( mediaBuffer , type , PlaylistLevelType . MAIN ) ;
326
- }
327
- }
328
- frag = this . getNextFragment ( this . nextLoadPosition , levelDetails ) ;
329
- if ( gapStart && frag && ! frag . gap && bufferInfo . nextStart ) {
330
- // Media buffered after GAP tags should not make the next buffer timerange exceed forward buffer length
331
- const nextbufferInfo = this . getFwdBufferInfoAtPos (
332
- this . mediaBuffer ? this . mediaBuffer : this . media ,
333
- bufferInfo . nextStart ,
334
- PlaylistLevelType . MAIN
335
- ) ;
336
- if (
337
- nextbufferInfo !== null &&
338
- bufferLen + nextbufferInfo . len >= maxBufLen
339
- ) {
340
- return ;
341
- }
305
+ // Avoid loop loading by using nextLoadPosition set for backtracking and skipping consecutive GAP tags
306
+ if ( frag && this . isLoopLoading ( frag , targetBufferTime ) ) {
307
+ const gapStart = frag . gap ;
308
+ if ( ! gapStart ) {
309
+ // Cleanup the fragment tracker before trying to find the next unbuffered fragment
310
+ const type =
311
+ this . audioOnly && ! this . altAudio
312
+ ? ElementaryStreamTypes . AUDIO
313
+ : ElementaryStreamTypes . VIDEO ;
314
+ const mediaBuffer =
315
+ ( type === ElementaryStreamTypes . VIDEO
316
+ ? this . videoBuffer
317
+ : this . mediaBuffer ) || this . media ;
318
+ if ( mediaBuffer ) {
319
+ this . afterBufferFlushed ( mediaBuffer , type , PlaylistLevelType . MAIN ) ;
342
320
}
343
321
}
322
+ frag = this . getNextFragmentLoopLoading (
323
+ frag ,
324
+ levelDetails ,
325
+ bufferInfo ,
326
+ PlaylistLevelType . MAIN ,
327
+ maxBufLen
328
+ ) ;
344
329
}
345
330
if ( ! frag ) {
346
331
return ;
0 commit comments