From 9c15c92927346dcb6088e13f022b71e052aad707 Mon Sep 17 00:00:00 2001 From: Alvaro Velad Date: Tue, 3 May 2022 13:26:48 +0200 Subject: [PATCH] feat: Add Id to chapters --- externs/shaka/player.js | 3 +++ lib/player.js | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/externs/shaka/player.js b/externs/shaka/player.js index ca73947a39..2a1e8bcd8e 100644 --- a/externs/shaka/player.js +++ b/externs/shaka/player.js @@ -1253,11 +1253,14 @@ shaka.extern.Thumbnail; /** * @typedef {{ + * id: string, * title: string, * startTime: number, * endTime: number * }} * + * @property {string} id + * The id of the chapter. * @property {string} title * The title of the chapter. * @property {number} startTime diff --git a/lib/player.js b/lib/player.js index 21db088360..3d177c67d8 100644 --- a/lib/player.js +++ b/lib/player.js @@ -4056,8 +4056,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget { for (const chaptersTrack of chaptersTracksWithLanguage) { if (chaptersTrack && chaptersTrack.cues) { for (const cue of chaptersTrack.cues) { + let id = cue.id; + if (!id || id == '') { + id = cue.startTime + '-' + cue.endTime + '-' + cue.text; + } /** @type {shaka.extern.Chapter} */ const chapter = { + id: id, title: cue.text, startTime: cue.startTime, endTime: cue.endTime,