@@ -77,6 +77,9 @@ module.exports = function(videojs) {
7777 this . _requestCustomData = options . requestCustomDataFn || function ( ) { /* noop */ } ;
7878 // See `currentTime` function
7979 this . _initialStartTime = options . startTime || 0 ;
80+ this . _isScrubbing = false ;
81+ this . _isSeeking = false ;
82+ this . _scrubbingTime = this . _initialStartTime ;
8083
8184 this . _playSource ( options . source , this . _initialStartTime ) ;
8285 this . ready ( function ( ) {
@@ -239,21 +242,50 @@ module.exports = function(videojs) {
239242 * @see {@link http://docs.videojs.com/Tech.html#setCurrentTime }
240243 */
241244 setCurrentTime ( time ) {
242- var duration = this . duration ( ) ;
245+ if ( this . scrubbing ( ) ) {
246+ this . _scrubbingTime = time ;
247+ return false ;
248+ }
249+ const duration = this . duration ( ) ;
243250
244251 if ( time > duration || ! this . _remotePlayer . canSeek ) {
245252 return ;
246253 }
247- // Seeking to any place within (approximately) 1 second of the end of the item
248- // causes the Video.js player to get stuck in a BUFFERING state. To work around
249- // this, we only allow seeking to within 1 second of the end of an item.
250- this . _remotePlayer . currentTime = Math . min ( duration - 1 , time ) ;
251- this . _remotePlayerController . seek ( ) ;
254+
255+ // We need to delay the actual seeking, because when you
256+ // scrub, videojs does pause() -> setCurrentTime() -> play()
257+ // and that triggers a weird bug where the chromecast stops sending
258+ // time_changed events.
259+ this . _isSeeking = true ;
260+ setTimeout ( ( ) => {
261+ // Seeking to any place within (approximately) 1 second of the end of the item
262+ // causes the Video.js player to get stuck in a BUFFERING state. To work
263+ // around this, we only allow seeking to within 1 second
264+ // of the end of an item.
265+ this . _remotePlayer . currentTime = Math . min ( duration - 1 , time ) ;
266+ this . _remotePlayerController . seek ( ) ;
267+ this . _isSeeking = false ;
268+ } , 500 ) ;
269+
252270 this . _triggerTimeUpdateEvent ( ) ;
253271 }
254272
255273 seeking ( ) {
256- return false ;
274+ return this . _isSeeking ;
275+ }
276+
277+ scrubbing ( ) {
278+ return this . _isScrubbing ;
279+ }
280+
281+ setScrubbing ( newValue ) {
282+ if ( newValue === true ) {
283+ this . _scrubbingTime = this . currentTime ( ) ;
284+ this . _isScrubbing = true ;
285+ } else {
286+ this . _isScrubbing = false ;
287+ this . setCurrentTime ( this . _scrubbingTime ) ;
288+ }
257289 }
258290
259291 /**
@@ -274,6 +306,11 @@ module.exports = function(videojs) {
274306 if ( ! this . _hasPlayedAnyItem ) {
275307 return this . _initialStartTime ;
276308 }
309+
310+ if ( this . scrubbing ( ) || this . seeking ( ) ) {
311+ return this . _scrubbingTime ;
312+ }
313+
277314 return this . _remotePlayer . currentTime ;
278315 }
279316
0 commit comments