@@ -22,7 +22,6 @@ goog.require('shaka.text.TextEngine');
2222goog.require('shaka.util.CmcdManager');
2323goog.require('shaka.util.Error');
2424goog.require('shaka.util.Functional');
25- goog.require('shaka.util.Iterables');
2625goog.require('shaka.util.LanguageUtils');
2726goog.require('shaka.util.ManifestParserUtils');
2827goog.require('shaka.util.MimeUtils');
@@ -104,7 +103,7 @@ shaka.dash.DashParser = class {
104103
105104 /**
106105 * Period IDs seen in previous manifest.
107- * @private {!Array.<number >}
106+ * @private {!Array.<string >}
108107 */
109108 this.lastManifestUpdatePeriodIds_ = [];
110109
@@ -556,23 +555,22 @@ shaka.dash.DashParser = class {
556555 const periods = [];
557556 let prevEnd = 0;
558557 const periodNodes = XmlUtils.findChildren(mpd, 'Period');
559- // This uses a for-loop rather than a for-of loop because this needs to look
560- // ahead to the next element.
561- const enumerate = (it) => shaka.util.Iterables.enumerate(it);
562- for (const {i, item: elem, next} of enumerate(periodNodes)) {
558+ for (let i = 0; i < periodNodes.length; i++) {
559+ const elem = periodNodes[i];
563560 const start = /** @type {number} */ (
564561 XmlUtils.parseAttr(elem, 'start', XmlUtils.parseDuration, prevEnd));
565562 const periodId = elem.id;
566563 const givenDuration =
567564 XmlUtils.parseAttr(elem, 'duration', XmlUtils.parseDuration);
568565
569566 let periodDuration = null;
570- if (next) {
567+ if (i + 1 < periodNodes.length) {
568+ const nextPeriod = periodNodes[i + 1];
571569 // "The difference between the start time of a Period and the start time
572570 // of the following Period is the duration of the media content
573571 // represented by this Period."
574572 const nextStart =
575- XmlUtils.parseAttr(next , 'start', XmlUtils.parseDuration);
573+ XmlUtils.parseAttr(nextPeriod , 'start', XmlUtils.parseDuration);
576574 if (nextStart != null) {
577575 periodDuration = nextStart - start;
578576 }
@@ -637,7 +635,7 @@ shaka.dash.DashParser = class {
637635 start: start,
638636 duration: periodDuration,
639637 node: elem,
640- isLastPeriod: periodDuration == null || !next ,
638+ isLastPeriod: periodDuration == null || (i + 1 == periodNodes.length) ,
641639 };
642640 const period = this.parsePeriod_(context, baseUris, info);
643641 periods.push(period);
@@ -647,12 +645,12 @@ shaka.dash.DashParser = class {
647645 }
648646
649647 if (periodDuration == null) {
650- if (next ) {
648+ if (i + 1 < periodNodes.length ) {
651649 // If the duration is still null and we aren't at the end, then we
652650 // will skip any remaining periods.
653651 shaka.log.warning(
654652 'Skipping Period', i + 1, 'and any subsequent Periods:', 'Period',
655- i + 1, 'does not have a valid start time.', next );
653+ i + 1, 'does not have a valid start time.', periodNodes[i + 1] );
656654 }
657655
658656 // The duration is unknown, so the end is unknown.
0 commit comments