diff --git a/src/js/tracks/audio-track-list.js b/src/js/tracks/audio-track-list.js index 0a058497c0..0a64d94777 100644 --- a/src/js/tracks/audio-track-list.js +++ b/src/js/tracks/audio-track-list.js @@ -72,33 +72,32 @@ class AudioTrackList extends TrackList { return; } - if (!this.enabledChange_) { - this.enabledChange_ = () => { - // when we are disabling other tracks (since we don't support - // more than one track at a time) we will set changing_ - // to true so that we don't trigger additional change events - if (this.changing_) { - return; - } - this.changing_ = true; - disableOthers(this, track); - this.changing_ = false; - this.trigger('change'); - }; - } + track.enabledChange_ = () => { + // when we are disabling other tracks (since we don't support + // more than one track at a time) we will set changing_ + // to true so that we don't trigger additional change events + if (this.changing_) { + return; + } + this.changing_ = true; + disableOthers(this, track); + this.changing_ = false; + this.trigger('change'); + }; /** * @listens AudioTrack#enabledchange * @fires TrackList#change */ - track.addEventListener('enabledchange', this.enabledChange_); + track.addEventListener('enabledchange', track.enabledChange_); } removeTrack(rtrack) { super.removeTrack(rtrack); - if (rtrack.removeEventListener && this.enabledChange_) { - rtrack.removeEventListener('enabledchange', this.enabledChange_); + if (rtrack.removeEventListener && rtrack.enabledChange_) { + rtrack.removeEventListener('enabledchange', rtrack.enabledChange_); + rtrack.enabledChange_ = null; } } } diff --git a/src/js/tracks/video-track-list.js b/src/js/tracks/video-track-list.js index cd5c17adba..4240ab6d7d 100644 --- a/src/js/tracks/video-track-list.js +++ b/src/js/tracks/video-track-list.js @@ -87,30 +87,29 @@ class VideoTrackList extends TrackList { return; } - if (!this.selectedChange_) { - this.selectedChange_ = () => { - if (this.changing_) { - return; - } - this.changing_ = true; - disableOthers(this, track); - this.changing_ = false; - this.trigger('change'); - }; - } + track.selectedChange_ = () => { + if (this.changing_) { + return; + } + this.changing_ = true; + disableOthers(this, track); + this.changing_ = false; + this.trigger('change'); + }; /** * @listens VideoTrack#selectedchange * @fires TrackList#change */ - track.addEventListener('selectedchange', this.selectedChange_); + track.addEventListener('selectedchange', track.selectedChange_); } removeTrack(rtrack) { super.removeTrack(rtrack); - if (rtrack.removeEventListener && this.selectedChange_) { - rtrack.removeEventListener('selectedchange', this.selectedChange_); + if (rtrack.removeEventListener && rtrack.selectedChange_) { + rtrack.removeEventListener('selectedchange', rtrack.selectedChange_); + rtrack.selectedChange_ = null; } } } diff --git a/test/unit/tracks/audio-track-list.test.js b/test/unit/tracks/audio-track-list.test.js index 0b77df7602..d559cb29f0 100644 --- a/test/unit/tracks/audio-track-list.test.js +++ b/test/unit/tracks/audio-track-list.test.js @@ -48,14 +48,14 @@ QUnit.test('only one track is ever enabled', function(assert) { assert.equal(track2.enabled, false, 'track2 is disabled'); assert.equal(track3.enabled, true, 'track3 is enabled'); - track.enabled = true; - assert.equal(track.enabled, true, 'track is disabled'); - assert.equal(track2.enabled, false, 'track2 is disabled'); + track2.enabled = true; + assert.equal(track.enabled, false, 'track is disabled'); + assert.equal(track2.enabled, true, 'track2 is enabled'); assert.equal(track3.enabled, false, 'track3 is disabled'); list.addTrack(track4); - assert.equal(track.enabled, true, 'track is enabled'); - assert.equal(track2.enabled, false, 'track2 is disabled'); + assert.equal(track.enabled, false, 'track is disabled'); + assert.equal(track2.enabled, true, 'track2 is enabled'); assert.equal(track3.enabled, false, 'track3 is disabled'); assert.equal(track4.enabled, false, 'track4 is disabled'); diff --git a/test/unit/tracks/video-track-list.test.js b/test/unit/tracks/video-track-list.test.js index 87d3f2ffd7..611ec1eaf1 100644 --- a/test/unit/tracks/video-track-list.test.js +++ b/test/unit/tracks/video-track-list.test.js @@ -48,14 +48,14 @@ QUnit.test('only one track is ever selected', function(assert) { assert.equal(track2.selected, false, 'track2 is unselected'); assert.equal(track3.selected, true, 'track3 is selected'); - track.selected = true; - assert.equal(track.selected, true, 'track is unselected'); - assert.equal(track2.selected, false, 'track2 is unselected'); + track2.selected = true; + assert.equal(track.selected, false, 'track is unselected'); + assert.equal(track2.selected, true, 'track2 is selected'); assert.equal(track3.selected, false, 'track3 is unselected'); list.addTrack(track4); - assert.equal(track.selected, true, 'track is selected'); - assert.equal(track2.selected, false, 'track2 is unselected'); + assert.equal(track.selected, false, 'track is unselected'); + assert.equal(track2.selected, true, 'track2 is selected'); assert.equal(track3.selected, false, 'track3 is unselected'); assert.equal(track4.selected, false, 'track4 is unselected');