diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index eec0db5d9b..e18bbe8937 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -928,13 +928,12 @@ shaka.hls.HlsParser = class { if (!playlist.segments.length) { return defaultBasicInfo; } - const middleSegmentIdx = Math.trunc((playlist.segments.length - 1) / 2); - const middleSegment = playlist.segments[middleSegmentIdx]; - const middleSegmentUris = shaka.hls.Utils.constructSegmentUris( + const firstSegment = playlist.segments[0]; + const firstSegmentUris = shaka.hls.Utils.constructSegmentUris( getUris(), - playlist.segments[0].verbatimSegmentUri); - const middleSegmentUri = middleSegmentUris[0]; - const parsedUri = new goog.Uri(middleSegmentUri); + firstSegment.verbatimSegmentUri); + const firstSegmentUri = firstSegmentUris[0]; + const parsedUri = new goog.Uri(firstSegmentUri); const extension = parsedUri.getPath().split('.').pop(); const rawMimeType = HlsParser.RAW_FORMATS_TO_MIME_TYPES_[extension]; if (rawMimeType) { @@ -946,7 +945,7 @@ shaka.hls.HlsParser = class { let initData = null; const initSegmentRef = this.getInitSegmentReference_( - playlist, middleSegment.tags, getUris); + playlist, firstSegment.tags, getUris); this.mapTagToInitSegmentRefMap_.clear(); if (initSegmentRef) { const initSegmentRequest = shaka.util.Networking.createSegmentRequest( @@ -961,8 +960,17 @@ shaka.hls.HlsParser = class { initData = initResponse.data; } - const segmentRequest = shaka.net.NetworkingEngine.makeRequest( - middleSegmentUris, this.config_.retryParameters); + let startByte = 0; + let endByte = null; + const byterangeTag = shaka.hls.Utils.getFirstTagWithName( + firstSegment.tags, 'EXT-X-BYTERANGE'); + if (byterangeTag) { + [startByte, endByte] = this.parseByteRange_( + /* previousReference= */ null, byterangeTag.value); + } + + const segmentRequest = shaka.util.Networking.createSegmentRequest( + firstSegmentUris, startByte, endByte, this.config_.retryParameters); const type = shaka.net.NetworkingEngine.AdvancedRequestType.MEDIA_SEGMENT; const response = await this.makeNetworkRequest_( segmentRequest, requestType, {type});