From 32fbfceb3e0a03faa58bcc69fc60c5118193bd0a Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Thu, 4 Mar 2021 13:56:09 -0500 Subject: [PATCH] test fixes with m3u8-parser update --- src/playlist-loader.js | 4 ++++ src/segment-loader.js | 21 +++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/playlist-loader.js b/src/playlist-loader.js index 617889cbc..c0140d1dd 100644 --- a/src/playlist-loader.js +++ b/src/playlist-loader.js @@ -28,6 +28,10 @@ const { mergeOptions, EventTarget } = videojs; * @return {Object} the merged segment */ export const updateSegment = (a, b) => { + if (!a) { + return b; + } + const result = mergeOptions(a, b); // only the old segment has parts diff --git a/src/segment-loader.js b/src/segment-loader.js index 77c7fd74d..78cf972f6 100644 --- a/src/segment-loader.js +++ b/src/segment-loader.js @@ -1002,15 +1002,20 @@ export default class SegmentLoader extends videojs.EventTarget { if (segmentInfo) { segmentInfo.mediaIndex -= mediaSequenceDiff; - // we need to update the referenced segment so that timing information is - // saved for the new playlist's segment, however, if the segment fell off the - // playlist, we can leave the old reference and just lose the timing info - if (segmentInfo.mediaIndex >= 0) { - segmentInfo.segment = newPlaylist.segments[segmentInfo.mediaIndex]; - } + if (segmentInfo.mediaIndex < 0) { + segmentInfo.mediaIndex = null; + segmentInfo.partIndex = null; + } else { + // we need to update the referenced segment so that timing information is + // saved for the new playlist's segment, however, if the segment fell off the + // playlist, we can leave the old reference and just lose the timing info + if (segmentInfo.mediaIndex >= 0) { + segmentInfo.segment = newPlaylist.segments[segmentInfo.mediaIndex]; + } - if (segmentInfo.partIndex >= 0 && segmentInfo.segment.parts) { - segmentInfo.part = segmentInfo.segment.parts[segmentInfo.partIndex]; + if (segmentInfo.partIndex >= 0 && segmentInfo.segment.parts) { + segmentInfo.part = segmentInfo.segment.parts[segmentInfo.partIndex]; + } } }