diff --git a/src/js/tech/tech.js b/src/js/tech/tech.js index bda7ca952d..b2b3a8a882 100644 --- a/src/js/tech/tech.js +++ b/src/js/tech/tech.js @@ -218,27 +218,25 @@ class Tech extends Component { return; } - let textTracksChanges = function() { - let updateDisplay = Fn.bind(this, function() { - this.trigger('texttrackchange'); - }); + let textTracksChanges = Fn.bind(this, function() { + let updateDisplay = () => this.trigger('texttrackchange'); - this.trigger('texttrackchange'); + updateDisplay(); - for (let i = 0; i < this.length; i++) { - let track = this[i]; + for (let i = 0; i < tracks.length; i++) { + let track = tracks[i]; track.removeEventListener('cuechange', updateDisplay); if (track.mode === 'showing') { track.addEventListener('cuechange', updateDisplay); } } - }; + }); tracks.addEventListener('change', textTracksChanges); - this.on('dispose', Fn.bind(this, function() { + this.on('dispose', function() { tracks.removeEventListener('change', textTracksChanges); - })); + }); } /** diff --git a/src/js/tracks/text-track-display.js b/src/js/tracks/text-track-display.js index deba42bf5e..9e64237647 100644 --- a/src/js/tracks/text-track-display.js +++ b/src/js/tracks/text-track-display.js @@ -32,7 +32,7 @@ class TextTrackDisplay extends Component { super(player, options, ready); player.on('loadstart', Fn.bind(this, this.toggleDisplay)); - player.on('texttrackchange', Fn.bind(this, this.toggleDisplay)); + player.on('texttrackchange', Fn.bind(this, this.updateDisplay)); // This used to be called during player init, but was causing an error // if a track should show by default and the display hadn't loaded yet.