Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to avoid duplicate chapters by building a new list each time #3354

Closed
wants to merge 9 commits into from
20 changes: 13 additions & 7 deletions src/js/control-bar/text-track-controls/chapters-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ class ChaptersButton extends TextTrackButton {
createMenu() {
let tracks = this.player_.textTracks() || [];
let chaptersTrack;
let items = this.items = [];
let items = this.items || [];

for (let i = 0, length = tracks.length; i < length; i++) {
for (let i = tracks.length - 1; i >= 0; i--) {

// We will always choose the last track as our chaptersTrack
let track = tracks[i];

if (track['kind'] === this.kind_) {
Expand All @@ -97,6 +99,12 @@ class ChaptersButton extends TextTrackButton {
});
menu.children_.unshift(title);
Dom.insertElFirst(title, menu.contentEl());
} else {
// We will empty out the menu children each time because we want a
// fresh new menu child list each time
items.forEach(item => menu.removeChild(item));
// Empty out the ChaptersButton menu items because we no longer need them
items = [];
}

if (chaptersTrack && chaptersTrack.cues == null) {
Expand Down Expand Up @@ -124,17 +132,15 @@ class ChaptersButton extends TextTrackButton {

menu.addChild(mi);
}

this.addChild(menu);
}

if (this.items.length > 0) {
if (items.length > 0) {
this.show();
}

// Assigning the value of items back to this.items for next iteration
this.items = items;
return menu;
}

}

ChaptersButton.prototype.kind_ = 'chapters';
Expand Down