diff --git a/src/js/player.js b/src/js/player.js index 32f393336..2294e7fdf 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -1528,20 +1528,20 @@ class Player extends Component { // if the `sourceset` `src` was an empty string // wait for a `loadstart` to update the cache to `currentSrc`. // If a sourceset happens before a `loadstart`, we reset the state - // as this function will be called again. if (!event.src) { - const updateCache = (e) => { - if (e.type !== 'sourceset') { - const techSrc = this.techGet('currentSrc'); - - this.lastSource_.tech = techSrc; - this.updateSourceCaches_(techSrc); + this.tech_.any(['sourceset', 'loadstart'], (e) => { + // if a sourceset happens before a `loadstart` there + // is nothing to do as this `handleTechSourceset_` + // will be called again and this will be handled there. + if (e.type === 'sourceset') { + return; } - this.tech_.off(['sourceset', 'loadstart'], updateCache); - }; + const techSrc = this.techGet('currentSrc'); - this.tech_.one(['sourceset', 'loadstart'], updateCache); + this.lastSource_.tech = techSrc; + this.updateSourceCaches_(techSrc); + }); } } this.lastSource_ = {player: this.currentSource().src, tech: event.src}; diff --git a/src/js/tracks/text-track.js b/src/js/tracks/text-track.js index 7624281fb..41984bdb4 100644 --- a/src/js/tracks/text-track.js +++ b/src/js/tracks/text-track.js @@ -93,19 +93,13 @@ const loadTrack = function(src, track) { if (track.tech_) { // to prevent use before define eslint error, we define loadHandler // as a let here - let loadHandler; - const errorHandler = () => { - log.error(`vttjs failed to load, stopping trying to process ${track.src}`); - track.tech_.off('vttjsloaded', loadHandler); - }; - - loadHandler = () => { - track.tech_.off('vttjserror', errorHandler); + track.tech_.any(['vttjsloaded', 'vttjserror'], (event) => { + if (event.type === 'vttjserror') { + log.error(`vttjs failed to load, stopping trying to process ${track.src}`); + return; + } return parseCues(responseBody, track); - }; - - track.tech_.one('vttjsloaded', loadHandler); - track.tech_.one('vttjserror', errorHandler); + }); } } else { parseCues(responseBody, track); diff --git a/test/unit/tracks/text-track.test.js b/test/unit/tracks/text-track.test.js index b27d67a40..169d90631 100644 --- a/test/unit/tracks/text-track.test.js +++ b/test/unit/tracks/text-track.test.js @@ -503,7 +503,6 @@ QUnit.test('stops processing if vttjs loading errored out', function(assert) { const errorSpy = sinon.spy(); const oldVTT = window.WebVTT; const oldLogError = log.error; - const parserCreated = false; const reqs = []; window.xhr.onCreate = function(req) { @@ -529,20 +528,14 @@ QUnit.test('stops processing if vttjs loading errored out', function(assert) { reqs.pop().respond(200, null, 'WEBVTT\n'); - assert.ok(!parserCreated, 'WebVTT is not loaded, do not try to parse yet'); + testTech.trigger('vttjserror'); + + assert.equal(errorSpy.callCount, 1, 'vttjs failed to load, so log.error was called'); testTech.trigger('vttjserror'); - const offSpyCall = testTech.off.getCall(0); - assert.ok(errorSpy.called, 'vttjs failed to load, so log.error was called'); - if (errorSpy.called) { - assert.ok( - /^vttjs failed to load, stopping trying to process/.test(errorSpy.getCall(0).args[0]), - 'log.error was called with the expected message' - ); - } - assert.ok(!parserCreated, 'WebVTT is not loaded, do not try to parse yet'); - assert.ok(offSpyCall, 'tech.off was called'); + // vttjserror not called again + assert.equal(errorSpy.callCount, 1, 'vttjserror handler not called again'); clock.restore(); window.WebVTT = oldVTT;