@ -173,6 +173,148 @@ QUnit.test('seek to live point if we fall off the end of a live playlist', funct
assert . equal ( seeks [ 0 ] , 45 , 'player seeked to live point' ) ;
} ) ;
QUnit . test ( 'seeks to current time when stuck inside buffered region' , function ( assert ) {
// set an arbitrary live source
this . player . src ( {
src : 'liveStart30sBefore.m3u8' ,
type : 'application/vnd.apple.mpegurl'
} ) ;
// start playback normally
this . player . tech_ . triggerReady ( ) ;
this . clock . tick ( 1 ) ;
standardXHRResponse ( this . requests . shift ( ) ) ;
openMediaSource ( this . player , this . clock ) ;
this . player . tech_ . trigger ( 'play' ) ;
this . player . tech_ . trigger ( 'playing' ) ;
this . clock . tick ( 1 ) ;
this . player . currentTime ( 10 ) ;
let seeks = [ ] ;
this . player . tech_ . setCurrentTime = ( time ) => {
seeks . push ( time ) ;
} ;
this . player . tech_ . seeking = ( ) => false ;
this . player . tech_ . buffered = ( ) => videojs . createTimeRanges ( [ [ 0 , 30 ] ] ) ;
this . player . tech_ . seekable = ( ) => videojs . createTimeRanges ( [ [ 0 , 30 ] ] ) ;
this . player . tech_ . paused = ( ) => false ;
// Playback watcher loop runs on a 250ms clock
this . clock . tick ( 250 ) ;
// Loop has run through once, `lastRecordedTime` should have been recorded
// and `consecutiveUpdates` set to 0 to begin count
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . lastRecordedTime , 10 ,
'Playback Watcher stored current time' ) ;
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . consecutiveUpdates , 0 ,
'consecutiveUpdates set to 0' ) ;
// Playback watcher loop runs on a 250ms clock
this . clock . tick ( 250 ) ;
// Loop should increment consecutive updates until it is >= 5
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . consecutiveUpdates , 1 ,
'consecutiveUpdates incremented' ) ;
// Playback watcher loop runs on a 250ms clock
this . clock . tick ( 250 ) ;
// Loop should increment consecutive updates until it is >= 5
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . consecutiveUpdates , 2 ,
'consecutiveUpdates incremented' ) ;
// Playback watcher loop runs on a 250ms clock
this . clock . tick ( 250 ) ;
// Loop should increment consecutive updates until it is >= 5
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . consecutiveUpdates , 3 ,
'consecutiveUpdates incremented' ) ;
// Playback watcher loop runs on a 250ms clock
this . clock . tick ( 250 ) ;
// Loop should increment consecutive updates until it is >= 5
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . consecutiveUpdates , 4 ,
'consecutiveUpdates incremented' ) ;
// Playback watcher loop runs on a 250ms clock
this . clock . tick ( 250 ) ;
// Loop should increment consecutive updates until it is >= 5
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . consecutiveUpdates , 5 ,
'consecutiveUpdates incremented' ) ;
// Playback watcher loop runs on a 250ms clock
this . clock . tick ( 250 ) ;
// Loop should see consecutive updates >= 5, call `waiting_`
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . consecutiveUpdates , 0 ,
'consecutiveUpdates reset' ) ;
// Playback watcher seeked to currentTime in `waiting_` to correct the `unknownwaiting`
assert . equal ( seeks . length , 1 , 'one seek' ) ;
assert . equal ( seeks [ 0 ] , 10 , 'player seeked to currentTime' ) ;
} ) ;
QUnit . test ( 'does not seek to current time when stuck near edge of buffered region' ,
function ( assert ) {
// set an arbitrary live source
this . player . src ( {
src : 'liveStart30sBefore.m3u8' ,
type : 'application/vnd.apple.mpegurl'
} ) ;
// start playback normally
this . player . tech_ . triggerReady ( ) ;
this . clock . tick ( 1 ) ;
standardXHRResponse ( this . requests . shift ( ) ) ;
openMediaSource ( this . player , this . clock ) ;
this . player . tech_ . trigger ( 'play' ) ;
this . player . tech_ . trigger ( 'playing' ) ;
this . clock . tick ( 1 ) ;
this . player . currentTime ( 29.98 ) ;
let seeks = [ ] ;
this . player . tech_ . setCurrentTime = ( time ) => {
seeks . push ( time ) ;
} ;
this . player . tech_ . seeking = ( ) => false ;
this . player . tech_ . buffered = ( ) => videojs . createTimeRanges ( [ [ 0 , 30 ] ] ) ;
this . player . tech_ . seekable = ( ) => videojs . createTimeRanges ( [ [ 0 , 30 ] ] ) ;
this . player . tech_ . paused = ( ) => false ;
// Playback watcher loop runs on a 250ms clock
this . clock . tick ( 250 ) ;
// Loop has run through once, `lastRecordedTime` should have been recorded
// and `consecutiveUpdates` set to 0 to begin count
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . lastRecordedTime , 29.98 ,
'Playback Watcher stored current time' ) ;
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . consecutiveUpdates , 0 ,
'consecutiveUpdates set to 0' ) ;
// Playback watcher loop runs on a 250ms clock
this . clock . tick ( 250 ) ;
// Loop has run through a second time, should detect that currentTime hasn't made
// progress while at the end of the buffer. Since the currentTime is at the end of the
// buffer, `consecutiveUpdates` should not be incremented
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . lastRecordedTime , 29.98 ,
'Playback Watcher stored current time' ) ;
assert . equal ( this . player . tech_ . hls . playbackWatcher_ . consecutiveUpdates , 0 ,
'consecutiveUpdates should still be 0' ) ;
// no corrective seek
assert . equal ( seeks . length , 0 , 'no seek' ) ;
} ) ;
QUnit . test ( 'fires notifications when activated' , function ( assert ) {
let buffered = [ [ ] ] ;
let seekable = [ [ ] ] ;