diff --git a/src/reload-source-on-error.js b/src/reload-source-on-error.js index 6d81bb2e0..bb8b78e7a 100644 --- a/src/reload-source-on-error.js +++ b/src/reload-source-on-error.js @@ -4,7 +4,7 @@ const defaultOptions = { errorInterval: 30, getSource(next) { const tech = this.tech({ IWillNotUseThisInPlugins: true }); - const sourceObj = tech.currentSource_; + const sourceObj = tech.currentSource_ || this.currentSource(); return next(sourceObj); } diff --git a/test/reload-source-on-error.test.js b/test/reload-source-on-error.test.js index 16840bcaf..f930b2308 100644 --- a/test/reload-source-on-error.test.js +++ b/test/reload-source-on-error.test.js @@ -78,8 +78,35 @@ QUnit.test('triggers on player error', function(assert) { assert.deepEqual( this.player.src.calledWith[0], this.tech.currentSource_, + 'player.src was called with tech.currentSource_' + ); +}); + +QUnit.test('triggers on player error, uses player.currentSource() if tech.currentSource_ is not set', function(assert) { + const oldsrc = this.tech.currentSource_; + const src = { + src: 'thisisanothersource.m3u8', + type: 'video/mp4' + }; + + this.tech.currentSource_ = null; + this.player.currentSource = () => src; + + this.player.reloadSourceOnError(); + this.player.trigger('error', -2); + + assert.equal(this.player.src.calledWith.length, 1, 'player.src was only called once'); + assert.deepEqual( + this.player.src.calledWith[0], + src, 'player.src was called with player.currentSource' ); + + assert.notDeepEqual( + this.player.src.calledWith[0], + oldsrc, + 'player.src was called with player.currentSource() and not tech.currentSource_' + ); }); QUnit.test('seeks to currentTime in VOD', function(assert) {