diff --git a/lib/util/periods.js b/lib/util/periods.js index 7945c899d5..3d75ad10c9 100644 --- a/lib/util/periods.js +++ b/lib/util/periods.js @@ -890,26 +890,33 @@ shaka.util.PeriodCombiner = class { // Create a fresh output stream for trick-mode playback. output.trickModeVideo = shaka.util.PeriodCombiner.cloneStream_( input.trickModeVideo); - // TODO: fix the createSegmentIndex function for trickModeVideo. - // The trick-mode tracks in multi-period content should have trick-mode - // segment indexes whenever available, rather than only regular-mode - // segment indexes. + output.trickModeVideo.matchedStreams = []; output.trickModeVideo.createSegmentIndex = () => { - // Satisfy the compiler about the type. - goog.asserts.assert( - output.segmentIndex instanceof shaka.media.MetaSegmentIndex, - 'The stream should have a MetaSegmentIndex.'); - output.trickModeVideo.segmentIndex = output.segmentIndex.clone(); + if (output.trickModeVideo.segmentIndex) { + return Promise.resolve(); + } + const segmentIndex = new shaka.media.MetaSegmentIndex(); + goog.asserts.assert(output.trickModeVideo.matchedStreams, + 'trickmode matched streams should exist'); + for (const stream of output.trickModeVideo.matchedStreams) { + goog.asserts.assert(stream.segmentIndex, + 'trickmode segment index should exist'); + segmentIndex.appendSegmentIndex(stream.segmentIndex); + } + output.trickModeVideo.segmentIndex = segmentIndex; + return Promise.resolve(); }; } // Concatenate the trick mode input onto the trick mode output. + output.trickModeVideo.matchedStreams.push(input.trickModeVideo); shaka.util.PeriodCombiner.concatenateStreams_( output.trickModeVideo, input.trickModeVideo); } else if (output.trickModeVideo) { // We have a trick mode output, but no input from this Period. Fill it in // from the standard input Stream. + output.trickModeVideo.matchedStreams.push(input); shaka.util.PeriodCombiner.concatenateStreams_( output.trickModeVideo, input); }