Skip to content

Commit c8f6c33

Browse files
committed
fix: 修正 mp4-loader fmp4 sidx fallback
1 parent de6499b commit c8f6c33

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

packages/xgplayer-mp4-loader/src/loader.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,23 @@ export class MP4Loader extends EventEmitter {
278278
let segments = moovToSegments(parsedMoov, this._config)
279279
let parsedSidx
280280
if (!isSegmentsOk(segments)) {
281-
const moof = MP4Parser.findBox(this.buffer, ['moof'])[0]
282-
const sidx = MP4Parser.findBox(this.buffer, ['sidx'])[0]
283-
if (moof && moof.size <= moof.data.length && sidx) {
284-
const parsedMoof = MP4Parser.moof(moof)
285-
281+
const getCompletedBox = async (data, name) => {
282+
const box = MP4Parser.findBox(data, [name])[0]
283+
if (!box) return
284+
if (box.size > box.data.length) {
285+
const boxRes = await this.loadData([box.start, box.start + box.size - 1], cache, config)
286+
if (boxRes) {
287+
responses.push(boxRes)
288+
return MP4Parser.findBox(boxRes.data, [name], box.start)[0]
289+
}
290+
}
291+
return box
292+
}
293+
const sidx = await getCompletedBox(responses[0]?.data, 'sidx')
294+
if (sidx) {
286295
parsedSidx = MP4Parser.sidx(sidx)
287-
if (parsedMoof && parsedSidx) {
288-
segments = sidxToSegments(parsedMoov, parsedSidx, parsedMoof)
296+
if (parsedSidx) {
297+
segments = sidxToSegments(parsedMoov, parsedSidx)
289298
}
290299
}
291300
}

0 commit comments

Comments
 (0)