xgplayer-mp4-loader 3.0.9-alpha.2 → 3.0.9-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es/config.js CHANGED
@@ -1,11 +1,15 @@
1
1
  import { objectSpread2 as _objectSpread2 } from "./_virtual/_rollupPluginBabelHelpers.js";
2
2
  function getConfig(cfg) {
3
+ if (typeof cfg.fixEditListOffset !== "boolean") {
4
+ delete cfg.fixEditListOffset;
5
+ }
3
6
  return _objectSpread2({
4
7
  vid: "",
5
8
  moovEnd: 8e4,
6
9
  segmentDuration: 2,
7
10
  maxDownloadInfoSize: 30,
8
11
  responseType: "arraybuffer",
12
+ fixEditListOffset: true,
9
13
  cache: null
10
14
  }, cfg);
11
15
  }
package/es/loader.d.ts CHANGED
@@ -20,8 +20,8 @@ export class MP4Loader {
20
20
  isSegmentLoading(segIndex: any): boolean;
21
21
  changeUrl(url: any, vid: any, moovEnd: any, notCancelLoader: any): Promise<void>;
22
22
  getOrLoadMeta(cache: any): Promise<{}>;
23
- loadMetaProcess(cache: any, [moovStart, moovEnd]: [any, any], onProgress: any, config: any): Promise<void>;
24
- loadMeta(cache: any, moovEnd: any, config: any): Promise<{
23
+ loadMetaProcess(cache: any, [moovStart, moovEnd]: [any, any], onProgress: any, config?: {}): Promise<void>;
24
+ loadMeta(cache: any, moovEnd: any, config?: {}): Promise<{
25
25
  meta: {};
26
26
  videoSegments: any[];
27
27
  audioSegments: any[];
@@ -39,7 +39,7 @@ export class MP4Loader {
39
39
  reset(notCancelLoader?: boolean): Promise<void>;
40
40
  destroy(): Promise<void>;
41
41
  _loadSegment(video: any, audio: any, cache: any, changeCurrent: any, config: any): Promise<any>;
42
- loadData(range: any, cache: any, config: any): Promise<any>;
42
+ loadData(range: any, cache: any, config?: {}): Promise<any>;
43
43
  _transformError: (error: any) => any;
44
44
  _getCacheKey(range: any): string;
45
45
  }
package/es/loader.js CHANGED
@@ -4,7 +4,7 @@ import { MP4Parser } from "xgplayer-transmuxer";
4
4
  import { getConfig } from "./config.js";
5
5
  import { MediaError } from "./error.js";
6
6
  import { Cache } from "./cache.js";
7
- import { isNumber, moovToSegments, moovToMeta } from "./utils.js";
7
+ import { isNumber, moovToSegments, moovToMeta, isSegmentsOk } from "./utils.js";
8
8
  import EventEmitter from "eventemitter3";
9
9
  var _excluded = ["vid", "cache"];
10
10
  var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
@@ -132,14 +132,15 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
132
132
  }, {
133
133
  key: "loadMetaProcess",
134
134
  value: function() {
135
- var _loadMetaProcess = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee4(cache, _ref, onProgress, config) {
135
+ var _loadMetaProcess = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee4(cache, _ref, onProgress) {
136
136
  var _this2 = this;
137
- var _ref2, moovStart, moovEnd, OnProgressHandle;
137
+ var _ref2, moovStart, moovEnd, config, OnProgressHandle, _args4 = arguments;
138
138
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
139
139
  while (1)
140
140
  switch (_context4.prev = _context4.next) {
141
141
  case 0:
142
142
  _ref2 = _slicedToArray(_ref, 2), moovStart = _ref2[0], moovEnd = _ref2[1];
143
+ config = _args4.length > 3 && _args4[3] !== void 0 ? _args4[3] : {};
143
144
  this._error = false;
144
145
  this.logger.debug("[loadMetaProcess start], range,", [moovStart, moovEnd]);
145
146
  OnProgressHandle = /* @__PURE__ */ function() {
@@ -185,9 +186,7 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
185
186
  break;
186
187
  }
187
188
  _this2._error = true;
188
- onProgress(null, state, options, {
189
- err: "cannot find moov or mdat box"
190
- }, response);
189
+ onProgress(null, state, options, new MediaError("cannot find moov or mdat box"), response);
191
190
  return _context3.abrupt("return");
192
191
  case 18:
193
192
  _moovStart = mdat.start + mdat.size;
@@ -217,20 +216,16 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
217
216
  break;
218
217
  }
219
218
  _this2._error = true;
220
- onProgress(null, state, options, {
221
- err: "cannot parse moov box"
222
- }, response);
219
+ onProgress(null, state, options, new MediaError("cannot parse moov box"), response);
223
220
  return _context3.abrupt("return");
224
221
  case 33:
225
- segments = moovToSegments(parsedMoov, _this2._config.segmentDuration);
226
- if (segments) {
222
+ segments = moovToSegments(parsedMoov, _this2._config);
223
+ if (isSegmentsOk(segments)) {
227
224
  _context3.next = 38;
228
225
  break;
229
226
  }
230
227
  _this2._error = true;
231
- onProgress(null, state, options, {
232
- err: "cannot parse segments"
233
- }, response);
228
+ onProgress(null, state, options, new MediaError("cannot parse segments"), response);
234
229
  return _context3.abrupt("return");
235
230
  case 38:
236
231
  _this2.meta = moovToMeta(parsedMoov);
@@ -251,21 +246,21 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
251
246
  }
252
247
  }, _callee3);
253
248
  }));
254
- return function OnProgressHandle2(_x7, _x8, _x9, _x10) {
249
+ return function OnProgressHandle2(_x6, _x7, _x8, _x9) {
255
250
  return _ref3.apply(this, arguments);
256
251
  };
257
252
  }();
258
- _context4.next = 6;
253
+ _context4.next = 7;
259
254
  return this.loadData([moovStart, moovEnd || this._config.moovEnd], cache, _objectSpread2({
260
255
  onProgress: OnProgressHandle
261
256
  }, config));
262
- case 6:
257
+ case 7:
263
258
  case "end":
264
259
  return _context4.stop();
265
260
  }
266
261
  }, _callee4, this);
267
262
  }));
268
- function loadMetaProcess(_x3, _x4, _x5, _x6) {
263
+ function loadMetaProcess(_x3, _x4, _x5) {
269
264
  return _loadMetaProcess.apply(this, arguments);
270
265
  }
271
266
  return loadMetaProcess;
@@ -273,87 +268,88 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
273
268
  }, {
274
269
  key: "loadMeta",
275
270
  value: function() {
276
- var _loadMeta = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee5(cache, moovEnd, config) {
277
- var responses, res, moov, mdat, moovStart, parsedMoov, segments, videoSegments, audioSegments;
271
+ var _loadMeta = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee5(cache, moovEnd) {
272
+ var config, responses, res, moov, mdat, moovStart, parsedMoov, segments, videoSegments, audioSegments, _args5 = arguments;
278
273
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
279
274
  while (1)
280
275
  switch (_context5.prev = _context5.next) {
281
276
  case 0:
277
+ config = _args5.length > 2 && _args5[2] !== void 0 ? _args5[2] : {};
282
278
  responses = [];
283
279
  this.logger.debug("[loadMeta start]");
284
- _context5.next = 4;
280
+ _context5.next = 5;
285
281
  return this.loadData([0, moovEnd || this._config.moovEnd], cache, config);
286
- case 4:
282
+ case 5:
287
283
  res = _context5.sent;
288
284
  if (res) {
289
- _context5.next = 7;
285
+ _context5.next = 8;
290
286
  break;
291
287
  }
292
288
  return _context5.abrupt("return");
293
- case 7:
289
+ case 8:
294
290
  responses.push(res);
295
291
  moov = MP4Parser.findBox(res.data, ["moov"])[0];
296
292
  if (moov) {
297
- _context5.next = 23;
293
+ _context5.next = 24;
298
294
  break;
299
295
  }
300
296
  mdat = MP4Parser.findBox(res.data, ["mdat"])[0];
301
297
  if (mdat) {
302
- _context5.next = 13;
298
+ _context5.next = 14;
303
299
  break;
304
300
  }
305
301
  throw new MediaError("cannot find moov or mdat box", res.data);
306
- case 13:
302
+ case 14:
307
303
  moovStart = mdat.start + mdat.size;
308
- _context5.next = 16;
304
+ _context5.next = 17;
309
305
  return this.loadData([moovStart], cache, config);
310
- case 16:
306
+ case 17:
311
307
  res = _context5.sent;
312
308
  if (res) {
313
- _context5.next = 19;
309
+ _context5.next = 20;
314
310
  break;
315
311
  }
316
312
  return _context5.abrupt("return");
317
- case 19:
313
+ case 20:
318
314
  responses.push(res);
319
315
  moov = MP4Parser.findBox(res.data, ["moov"], moovStart)[0];
320
316
  if (moov) {
321
- _context5.next = 23;
317
+ _context5.next = 24;
322
318
  break;
323
319
  }
324
320
  throw new MediaError("cannot find moov box", res.data);
325
- case 23:
321
+ case 24:
326
322
  if (!(moov.size > moov.data.length)) {
327
- _context5.next = 31;
323
+ _context5.next = 32;
328
324
  break;
329
325
  }
330
- _context5.next = 26;
326
+ _context5.next = 27;
331
327
  return this.loadData([res.data.length, moov.start + moov.size - 1], cache, config);
332
- case 26:
328
+ case 27:
333
329
  res = _context5.sent;
334
330
  if (res) {
335
- _context5.next = 29;
331
+ _context5.next = 30;
336
332
  break;
337
333
  }
338
334
  return _context5.abrupt("return");
339
- case 29:
335
+ case 30:
340
336
  responses.push(res);
341
337
  moov.data = concatUint8Array(moov.data, res.data);
342
- case 31:
338
+ case 32:
343
339
  parsedMoov = MP4Parser.moov(moov);
344
340
  if (parsedMoov) {
345
- _context5.next = 34;
341
+ _context5.next = 35;
346
342
  break;
347
343
  }
348
344
  throw new MediaError("cannot parse moov box", moov.data);
349
- case 34:
350
- segments = moovToSegments(parsedMoov, this._config.segmentDuration);
351
- if (segments) {
352
- _context5.next = 37;
345
+ case 35:
346
+ segments = moovToSegments(parsedMoov, this._config);
347
+ if (isSegmentsOk(segments)) {
348
+ _context5.next = 38;
353
349
  break;
354
350
  }
355
351
  throw new MediaError("cannot parse segments", moov.data);
356
- case 37:
352
+ case 38:
357
353
  this.meta = moovToMeta(parsedMoov);
358
354
  videoSegments = segments.videoSegments, audioSegments = segments.audioSegments;
359
355
  this.videoSegments = videoSegments;
@@ -365,13 +361,13 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
365
361
  audioSegments,
366
362
  responses
367
363
  });
368
- case 43:
364
+ case 44:
369
365
  case "end":
370
366
  return _context5.stop();
371
367
  }
372
368
  }, _callee5, this);
373
369
  }));
374
- function loadMeta(_x11, _x12, _x13) {
370
+ function loadMeta(_x10, _x11) {
375
371
  return _loadMeta.apply(this, arguments);
376
372
  }
377
373
  return loadMeta;
@@ -380,7 +376,7 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
380
376
  key: "loadCacheMeta",
381
377
  value: function loadCacheMeta(meta, segmentIndex) {
382
378
  var moov = meta.moov;
383
- var segments = moovToSegments(moov, this._config.segmentDuration);
379
+ var segments = moovToSegments(moov, this._config);
384
380
  var videoSegments = segments.videoSegments, audioSegments = segments.audioSegments;
385
381
  this.videoSegments = videoSegments;
386
382
  this.audioSegments = audioSegments;
@@ -435,7 +431,7 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
435
431
  }
436
432
  }, _callee6, this);
437
433
  }));
438
- function loadSegmentByTime(_x14, _x15) {
434
+ function loadSegmentByTime(_x12, _x13) {
439
435
  return _loadSegmentByTime.apply(this, arguments);
440
436
  }
441
437
  return loadSegmentByTime;
@@ -467,7 +463,7 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
467
463
  }
468
464
  }, _callee7, this);
469
465
  }));
470
- function loadNextSegment(_x16) {
466
+ function loadNextSegment(_x14) {
471
467
  return _loadNextSegment.apply(this, arguments);
472
468
  }
473
469
  return loadNextSegment;
@@ -528,7 +524,7 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
528
524
  }
529
525
  }, _callee8);
530
526
  }));
531
- return function load2(_x18) {
527
+ return function load2(_x16) {
532
528
  return _ref4.apply(this, arguments);
533
529
  };
534
530
  }();
@@ -540,7 +536,7 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
540
536
  }
541
537
  }, _callee9, this);
542
538
  }));
543
- function preload(_x17) {
539
+ function preload(_x15) {
544
540
  return _preload.apply(this, arguments);
545
541
  }
546
542
  return preload;
@@ -654,7 +650,7 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
654
650
  }
655
651
  }, _callee12, this, [[4, , 8, 11]]);
656
652
  }));
657
- function _loadSegment(_x19, _x20, _x21, _x22, _x23) {
653
+ function _loadSegment(_x17, _x18, _x19, _x20, _x21) {
658
654
  return _loadSegment2.apply(this, arguments);
659
655
  }
660
656
  return _loadSegment;
@@ -662,32 +658,33 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
662
658
  }, {
663
659
  key: "loadData",
664
660
  value: function() {
665
- var _loadData = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee13(range, cache, config) {
666
- var cacheKey, data, res, url;
661
+ var _loadData = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime().mark(function _callee13(range, cache) {
662
+ var config, cacheKey, data, res, url, _args13 = arguments;
667
663
  return _regeneratorRuntime().wrap(function _callee13$(_context13) {
668
664
  while (1)
669
665
  switch (_context13.prev = _context13.next) {
670
666
  case 0:
667
+ config = _args13.length > 2 && _args13[2] !== void 0 ? _args13[2] : {};
671
668
  cacheKey = this._getCacheKey(range);
672
- _context13.next = 3;
669
+ _context13.next = 4;
673
670
  return this.cache.get(cacheKey);
674
- case 3:
671
+ case 4:
675
672
  data = _context13.sent;
676
673
  if (data) {
677
- _context13.next = 11;
674
+ _context13.next = 12;
678
675
  break;
679
676
  }
680
- url = config && config.url ? config.url : this.url;
681
- _context13.next = 8;
677
+ url = config !== null && config !== void 0 && config.url ? config.url : this.url;
678
+ _context13.next = 9;
682
679
  return this._loader.load(url, _objectSpread2({
683
680
  range,
684
681
  vid: this.vid
685
682
  }, config));
686
- case 8:
683
+ case 9:
687
684
  res = _context13.sent;
688
- _context13.next = 12;
685
+ _context13.next = 13;
689
686
  break;
690
- case 11:
687
+ case 12:
691
688
  res = {
692
689
  data,
693
690
  state: true,
@@ -697,13 +694,13 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
697
694
  vid: this.vid
698
695
  }
699
696
  };
700
- case 12:
697
+ case 13:
701
698
  if (res) {
702
- _context13.next = 14;
699
+ _context13.next = 15;
703
700
  break;
704
701
  }
705
702
  return _context13.abrupt("return");
706
- case 14:
703
+ case 15:
707
704
  if (!data) {
708
705
  res.data && this.downloadInfo.push({
709
706
  startTime: res.startTime,
@@ -716,13 +713,13 @@ var MP4Loader = /* @__PURE__ */ function(_EventEmitter) {
716
713
  }
717
714
  }
718
715
  return _context13.abrupt("return", res);
719
- case 17:
716
+ case 18:
720
717
  case "end":
721
718
  return _context13.stop();
722
719
  }
723
720
  }, _callee13, this);
724
721
  }));
725
- function loadData(_x24, _x25, _x26) {
722
+ function loadData(_x22, _x23) {
726
723
  return _loadData.apply(this, arguments);
727
724
  }
728
725
  return loadData;
package/es/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export function moovToSegments(moov: any, duration: any): {
1
+ export function moovToSegments(moov: any, config: any): {
2
2
  videoSegments: any[];
3
3
  audioSegments: any[];
4
4
  };
@@ -16,3 +16,4 @@ export function moovToMeta(moov: any): {
16
16
  moov: any;
17
17
  };
18
18
  export function isNumber(n: any): boolean;
19
+ export function isSegmentsOk(segments: any): boolean;