diff --git a/lib/util/periods.js b/lib/util/periods.js index 4a4fd1fc20..2472d1f1d9 100644 --- a/lib/util/periods.js +++ b/lib/util/periods.js @@ -573,7 +573,7 @@ shaka.util.PeriodCombiner = class { // We need to create all the per-period segment indexes and append them to // the output's MetaSegmentIndex. - await Promise.all(matches.map((match) => match.createSegmentIndex())); + await shaka.util.PeriodCombiner.createSegmentIndexes_(matches); // Assure the compiler that matches didn't become null during the async // operation above. @@ -585,6 +585,25 @@ shaka.util.PeriodCombiner = class { return true; } + /** + * Creates all segment indexes for an array of streams. Returns once every + * segment index is created. + * + * @param {!Array.} streams + * @return {!Promise} + * @private + */ + static createSegmentIndexes_(streams) { + const operations = []; + for (const stream of streams) { + operations.push(stream.createSegmentIndex()); + if (stream.trickModeVideo && !stream.trickModeVideo.segmentIndex) { + operations.push(stream.trickModeVideo.createSegmentIndex()); + } + } + return Promise.all(operations); + } + /** * Create a new output Stream based on a particular input Stream. Locates * matching Streams in all other periods and combines them into an output @@ -627,7 +646,7 @@ shaka.util.PeriodCombiner = class { if (outputStream.createSegmentIndex) { // For T == Stream, we need to create all the per-period segment indexes // in advance. concat() will add them to the output's MetaSegmentIndex. - await Promise.all(matches.map((match) => match.createSegmentIndex())); + await shaka.util.PeriodCombiner.createSegmentIndexes_(matches); } // Assure the compiler that matches didn't become null during the async