@@ -44,16 +44,18 @@ class SeekBar extends Slider {
44
44
// Avoid mutating the prototype's `children` array by creating a copy
45
45
options . children = [ ...options . children ] ;
46
46
47
- const shouldDisableSeekWhileScrubbingOnMobile = player . options_ . disableSeekWhileScrubbingOnMobile && ( IS_IOS || IS_ANDROID ) ;
47
+ const shouldDisableSeekWhileScrubbing =
48
+ ( player . options_ . disableSeekWhileScrubbingOnMobile && ( IS_IOS || IS_ANDROID ) ) ||
49
+ ( player . options_ . disableSeekWhileScrubbingOnSTV ) ;
48
50
49
51
// Add the TimeTooltip as a child if we are on desktop, or on mobile with `disableSeekWhileScrubbingOnMobile: true`
50
- if ( ( ! IS_IOS && ! IS_ANDROID ) || shouldDisableSeekWhileScrubbingOnMobile ) {
52
+ if ( ( ! IS_IOS && ! IS_ANDROID ) || shouldDisableSeekWhileScrubbing ) {
51
53
options . children . splice ( 1 , 0 , 'mouseTimeDisplay' ) ;
52
54
}
53
55
54
56
super ( player , options ) ;
55
57
56
- this . shouldDisableSeekWhileScrubbingOnMobile_ = shouldDisableSeekWhileScrubbingOnMobile ;
58
+ this . shouldDisableSeekWhileScrubbing_ = shouldDisableSeekWhileScrubbing ;
57
59
this . pendingSeekTime_ = null ;
58
60
59
61
this . setEventHandlers_ ( ) ;
@@ -196,7 +198,7 @@ class SeekBar extends Slider {
196
198
197
199
// update the progress bar time tooltip with the current time
198
200
if ( this . bar ) {
199
- this . bar . update ( Dom . getBoundingClientRect ( this . el ( ) ) , this . getProgress ( ) ) ;
201
+ this . bar . update ( Dom . getBoundingClientRect ( this . el ( ) ) , this . getProgress ( ) , event ) ;
200
202
}
201
203
} ) ;
202
204
@@ -233,6 +235,26 @@ class SeekBar extends Slider {
233
235
this . player_ . currentTime ( ) ;
234
236
}
235
237
238
+ /**
239
+ * Getter and setter for pendingSeekTime.
240
+ * Ensures the value is clamped between 0 and duration.
241
+ *
242
+ * @param {number|null } [time] - Optional. The new pending seek time, can be a number or null.
243
+ * @return {number|null } - The current pending seek time.
244
+ */
245
+ pendingSeekTime ( time ) {
246
+ if ( time !== undefined ) {
247
+ if ( time !== null ) {
248
+ const duration = this . player_ . duration ( ) ;
249
+
250
+ this . pendingSeekTime_ = Math . max ( 0 , Math . min ( time , duration ) ) ;
251
+ } else {
252
+ this . pendingSeekTime_ = null ;
253
+ }
254
+ }
255
+ return this . pendingSeekTime_ ;
256
+ }
257
+
236
258
/**
237
259
* Get the percentage of media played so far.
238
260
*
@@ -242,8 +264,8 @@ class SeekBar extends Slider {
242
264
getPercent ( ) {
243
265
// If we have a pending seek time, we are scrubbing on mobile and should set the slider percent
244
266
// to reflect the current scrub location.
245
- if ( this . pendingSeekTime_ ) {
246
- return this . pendingSeekTime_ / this . player_ . duration ( ) ;
267
+ if ( this . pendingSeekTime ( ) !== null ) {
268
+ return this . pendingSeekTime ( ) / this . player_ . duration ( ) ;
247
269
}
248
270
249
271
const currentTime = this . getCurrentTime_ ( ) ;
@@ -284,7 +306,7 @@ class SeekBar extends Slider {
284
306
285
307
// Don't pause if we are on mobile and `disableSeekWhileScrubbingOnMobile: true`.
286
308
// In that case, playback should continue while the player scrubs to a new location.
287
- if ( ! this . shouldDisableSeekWhileScrubbingOnMobile_ ) {
309
+ if ( ! this . shouldDisableSeekWhileScrubbing_ ) {
288
310
this . player_ . pause ( ) ;
289
311
}
290
312
@@ -351,8 +373,8 @@ class SeekBar extends Slider {
351
373
}
352
374
353
375
// if on mobile and `disableSeekWhileScrubbingOnMobile: true`, keep track of the desired seek point but we won't initiate the seek until 'touchend'
354
- if ( this . shouldDisableSeekWhileScrubbingOnMobile_ ) {
355
- this . pendingSeekTime_ = newTime ;
376
+ if ( this . shouldDisableSeekWhileScrubbing_ ) {
377
+ this . pendingSeekTime ( newTime ) ;
356
378
} else {
357
379
this . userSeek_ ( newTime ) ;
358
380
}
@@ -402,10 +424,10 @@ class SeekBar extends Slider {
402
424
this . player_ . scrubbing ( false ) ;
403
425
404
426
// If we have a pending seek time, then we have finished scrubbing on mobile and should initiate a seek.
405
- if ( this . pendingSeekTime_ ) {
406
- this . userSeek_ ( this . pendingSeekTime_ ) ;
427
+ if ( this . pendingSeekTime ( ) !== null ) {
428
+ this . userSeek_ ( this . pendingSeekTime ( ) ) ;
407
429
408
- this . pendingSeekTime_ = null ;
430
+ this . pendingSeekTime ( null ) ;
409
431
}
410
432
411
433
/**
@@ -425,18 +447,46 @@ class SeekBar extends Slider {
425
447
}
426
448
}
427
449
450
+ /**
451
+ * Handles pending seek time when `disableSeekWhileScrubbingOnSTV` is enabled.
452
+ *
453
+ * @param {number } stepAmount - The number of seconds to step (positive for forward, negative for backward).
454
+ */
455
+ handlePendingSeek_ ( stepAmount ) {
456
+ if ( ! this . player_ . paused ( ) ) {
457
+ this . player_ . pause ( ) ;
458
+ }
459
+
460
+ const currentPos = this . pendingSeekTime ( ) !== null ?
461
+ this . pendingSeekTime ( ) :
462
+ this . player_ . currentTime ( ) ;
463
+
464
+ this . pendingSeekTime ( currentPos + stepAmount ) ;
465
+ this . player_ . trigger ( { type : 'timeupdate' , target : this , manuallyTriggered : true } ) ;
466
+ }
467
+
428
468
/**
429
469
* Move more quickly fast forward for keyboard-only users
430
470
*/
431
471
stepForward ( ) {
432
- this . userSeek_ ( this . player_ . currentTime ( ) + this . options ( ) . stepSeconds ) ;
472
+ // if `disableSeekWhileScrubbingOnSTV: true`, keep track of the desired seek point but we won't initiate the seek
473
+ if ( this . shouldDisableSeekWhileScrubbing_ ) {
474
+ this . handlePendingSeek_ ( this . options ( ) . stepSeconds ) ;
475
+ } else {
476
+ this . userSeek_ ( this . player_ . currentTime ( ) + this . options ( ) . stepSeconds ) ;
477
+ }
433
478
}
434
479
435
480
/**
436
481
* Move more quickly rewind for keyboard-only users
437
482
*/
438
483
stepBack ( ) {
439
- this . userSeek_ ( this . player_ . currentTime ( ) - this . options ( ) . stepSeconds ) ;
484
+ // if `disableSeekWhileScrubbingOnSTV: true`, keep track of the desired seek point but we won't initiate the seek
485
+ if ( this . shouldDisableSeekWhileScrubbing_ ) {
486
+ this . handlePendingSeek_ ( - this . options ( ) . stepSeconds ) ;
487
+ } else {
488
+ this . userSeek_ ( this . player_ . currentTime ( ) - this . options ( ) . stepSeconds ) ;
489
+ }
440
490
}
441
491
442
492
/**
@@ -448,6 +498,10 @@ class SeekBar extends Slider {
448
498
*
449
499
*/
450
500
handleAction ( event ) {
501
+ if ( this . pendingSeekTime ( ) !== null ) {
502
+ this . userSeek_ ( this . pendingSeekTime ( ) ) ;
503
+ this . pendingSeekTime ( null ) ;
504
+ }
451
505
if ( this . player_ . paused ( ) ) {
452
506
this . player_ . play ( ) ;
453
507
} else {
0 commit comments