@@ -12,7 +12,7 @@ import type { InFlightData } from './base-stream-controller';
12
12
import type { InFlightFragments } from '../hls' ;
13
13
import type Hls from '../hls' ;
14
14
import type { FragmentTracker } from './fragment-tracker' ;
15
- import type { Fragment } from '../loader/fragment' ;
15
+ import type { Fragment , MediaFragment } from '../loader/fragment' ;
16
16
import type { SourceBufferName } from '../types/buffer' ;
17
17
import type {
18
18
BufferAppendedData ,
@@ -503,7 +503,7 @@ export default class GapController extends TaskLoop {
503
503
* @param partial - The partial fragment found at the current time (where playback is stalling).
504
504
* @private
505
505
*/
506
- private _trySkipBufferHole ( partial : Fragment | null ) : number {
506
+ private _trySkipBufferHole ( partial : MediaFragment | null ) : number {
507
507
const { fragmentTracker, media } = this ;
508
508
const config = this . hls ?. config ;
509
509
if ( ! media || ! fragmentTracker || ! config ) {
@@ -515,7 +515,7 @@ export default class GapController extends TaskLoop {
515
515
const bufferInfo = BufferHelper . bufferInfo ( media , currentTime , 0 ) ;
516
516
const startTime =
517
517
currentTime < bufferInfo . start ? bufferInfo . start : bufferInfo . nextStart ;
518
- if ( startTime ) {
518
+ if ( startTime && this . hls ) {
519
519
const bufferStarved = bufferInfo . len <= config . maxBufferHole ;
520
520
const waiting =
521
521
bufferInfo . len > 0 && bufferInfo . len < 1 && media . readyState < 3 ;
@@ -541,6 +541,19 @@ export default class GapController extends TaskLoop {
541
541
PlaylistLevelType . MAIN ,
542
542
) ;
543
543
if ( startProvisioned ) {
544
+ // Do not seek when selected variant playlist is unloaded
545
+ if ( ! this . hls . loadLevelObj ?. details ) {
546
+ return 0 ;
547
+ }
548
+ // Do not seek when required fragments are inflight or appending
549
+ const inFlightDependency = getInFlightDependency (
550
+ this . hls . inFlightFragments ,
551
+ startTime ,
552
+ ) ;
553
+ if ( inFlightDependency ) {
554
+ return 0 ;
555
+ }
556
+ // Do not seek if we can't walk tracked fragments to end of gap
544
557
let moreToLoad = false ;
545
558
let pos = startProvisioned . end ;
546
559
while ( pos < startTime ) {
@@ -567,7 +580,7 @@ export default class GapController extends TaskLoop {
567
580
) ;
568
581
this . moved = true ;
569
582
media . currentTime = targetTime ;
570
- if ( ! partial ?. gap && this . hls ) {
583
+ if ( ! partial ?. gap ) {
571
584
const error = new Error (
572
585
`fragment loaded with buffer holes, seeking from ${ currentTime } to ${ targetTime } ` ,
573
586
) ;
0 commit comments