Skip to content

Commit

Permalink
fix(chapters): removed duplicate chapters by id (shaka-project#4810)
Browse files Browse the repository at this point in the history
fixes shaka-project#4750

Solved by creating a `Set` for filtering out deplicate elements.

Need confirmation, Shouldn't we add an `assert` for `language` argument
passed to
https://github.com/shaka-project/shaka-player/blob/76f96b9fee2dc43b03f6803dd80c51fdc5b73a9e/lib/player.js#L4340-L4342
  • Loading branch information
WINOFFRG committed Dec 10, 2022
1 parent 76f96b9 commit 151bdda
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -68,6 +68,7 @@ Prakash <duggaraju@gmail.com>
Robert Colantuoni <rgc@colantuoni.com>
Robert Galluccio <robertnw5@gmail.com>
Rodolphe Breton <robloche@gmail.com>
Rohan Gupta <rohangupta1528@gmail.com>
Roi Lipman <roilipman@gmail.com>
Roksolana Ivanyshyn <roksolana.ivanyshyn.pub@gmail.com>
Rostislav Hejduk <Ross-cz@users.noreply.github.com>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -100,6 +100,7 @@ Robert Colantuoni <rgc@colantuoni.com>
Robert Galluccio <robertnw5@gmail.com>
Rodolphe Breton <robloche@gmail.com>
Rohit Makasana <rohitbm@google.com>
Rohan Gupta <rohangupta1528@gmail.com>
Roi Lipman <roilipman@gmail.com>
Roksolana Ivanyshyn <roksolana.ivanyshyn.pub@gmail.com>
Rostislav Hejduk <Ross-cz@users.noreply.github.com>
Expand Down
6 changes: 5 additions & 1 deletion lib/player.js
Expand Up @@ -4347,6 +4347,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
return [];
}
const chapters = [];
const uniqueChapters = new Set();
for (const chaptersTrack of chaptersTracksWithLanguage) {
if (chaptersTrack && chaptersTrack.cues) {
for (const cue of chaptersTrack.cues) {
Expand All @@ -4361,7 +4362,10 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
startTime: cue.startTime,
endTime: cue.endTime,
};
chapters.push(chapter);
if (!uniqueChapters.has(id)) {
chapters.push(chapter);
uniqueChapters.add(id);
}
}
}
}
Expand Down

0 comments on commit 151bdda

Please sign in to comment.