@banou/media-player 0.10.53 → 0.10.54
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/dist/engine/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "../engine-
|
|
1
|
+
import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "../engine-DZ6BX5XH.js";
|
|
2
2
|
export { i as DEFAULT_BUFFER_SIZE, e as MediaElementError, a as SUBTITLES_OFF, u as createPictureInPicture, d as createSubtitleRenderer, c as createThumbnailGenerator, n as getTimeRanges, s as isMediaElementError, o as pictureInPictureMode, l as startPlayback, t as terminateRemuxer, r as updateSourceBuffer };
|
|
@@ -167,7 +167,7 @@ var i = {
|
|
|
167
167
|
l && D((e) => {
|
|
168
168
|
m = Promise.resolve(e.addFonts([l])).then(k, T);
|
|
169
169
|
}), k();
|
|
170
|
-
},
|
|
170
|
+
}, te = (e) => {
|
|
171
171
|
u && !f && e.some((e) => p.test(e.Text)) && (f = !0, D(async (e) => {
|
|
172
172
|
await m, await e.addFonts([u]), k();
|
|
173
173
|
}));
|
|
@@ -197,7 +197,7 @@ var i = {
|
|
|
197
197
|
let a = v(e, n);
|
|
198
198
|
r.set(i, a), S === n.streamIndex && t.push(a.assEvent);
|
|
199
199
|
}
|
|
200
|
-
t.length && (D((e) => Promise.all(t.map((t) => e.createEvent(t)))),
|
|
200
|
+
t.length && (D((e) => Promise.all(t.map((t) => e.createEvent(t)))), te(t), k());
|
|
201
201
|
},
|
|
202
202
|
selectStream: (e) => {
|
|
203
203
|
let t = e ?? -1;
|
|
@@ -208,7 +208,7 @@ var i = {
|
|
|
208
208
|
e.freeTrack(),
|
|
209
209
|
e.setTrack(n.content),
|
|
210
210
|
...r.map((t) => e.createEvent(t))
|
|
211
|
-
]) : e.removeAllEvents()),
|
|
211
|
+
]) : e.removeAllEvents()), te(r), k();
|
|
212
212
|
},
|
|
213
213
|
getStreams: () => [...b],
|
|
214
214
|
getSelectedStream: () => S,
|
|
@@ -228,13 +228,13 @@ var i = {
|
|
|
228
228
|
constructor(e, t) {
|
|
229
229
|
super(e, t), this.name = "MediaElementError";
|
|
230
230
|
}
|
|
231
|
-
}, x = (e) => !!e && typeof e == "object" && e.mediaElement === !0, S = -20, C = 60, w = 30, T = -5, E = 20, D = 5, O = 15e3, k = 500, A = 1, j = 3, ee = 12,
|
|
231
|
+
}, x = (e) => !!e && typeof e == "object" && e.mediaElement === !0, S = -20, C = 60, w = 30, T = -5, E = 20, D = 5, O = 15e3, k = 500, A = 1, j = 3, ee = 12, te = 200, ne = 250, M = 25e5, N = (e) => {
|
|
232
232
|
let { worker: t } = e, n = setTimeout(() => t.terminate(), 2e3);
|
|
233
233
|
e.destroy().catch(() => {}).finally(() => {
|
|
234
234
|
clearTimeout(n), t.terminate();
|
|
235
235
|
});
|
|
236
|
-
},
|
|
237
|
-
let { videoElement: n, subtitleContainer: r, read: i, length: a, publicPath: c, libavWorkerUrl: u, jassubWorkerUrl: d, jassubWasmUrl: f, jassubWasmWorkerUrl: p, jassubLegacyWasmUrl: m, jassubLegacyWasmWorkerUrl: h, defaultFontUrl: g, cjkFontUrl: _, bufferSize: v =
|
|
236
|
+
}, re = async (t) => {
|
|
237
|
+
let { videoElement: n, subtitleContainer: r, read: i, length: a, publicPath: c, libavWorkerUrl: u, jassubWorkerUrl: d, jassubWasmUrl: f, jassubWasmWorkerUrl: p, jassubLegacyWasmUrl: m, jassubLegacyWasmWorkerUrl: h, defaultFontUrl: g, cjkFontUrl: _, bufferSize: v = M, audioStreamIndex: x, chooseAudioStream: re, onReady: P, onError: ie, onRecovered: ae, onSeek: oe, onSubtitleStreams: se, onAudioStreams: ce, onOutput: F } = t, le = (t) => e({
|
|
238
238
|
publicPath: c,
|
|
239
239
|
workerUrl: u,
|
|
240
240
|
workerOptions: { type: "module" },
|
|
@@ -242,20 +242,20 @@ var i = {
|
|
|
242
242
|
length: a,
|
|
243
243
|
audioStreamIndex: t,
|
|
244
244
|
read: i
|
|
245
|
-
}),
|
|
246
|
-
if (!
|
|
247
|
-
|
|
248
|
-
for (let e of [...
|
|
245
|
+
}), I = await le(x), L = [], R = !1, ue = () => {
|
|
246
|
+
if (!R) {
|
|
247
|
+
R = !0;
|
|
248
|
+
for (let e of [...L].reverse()) try {
|
|
249
249
|
e();
|
|
250
250
|
} catch {}
|
|
251
251
|
}
|
|
252
252
|
};
|
|
253
|
-
|
|
253
|
+
L.push(() => N(I));
|
|
254
254
|
try {
|
|
255
|
-
let e = await
|
|
256
|
-
x === void 0 && t !== void 0 && t !== e.audioStreams?.[0]?.streamIndex && (
|
|
255
|
+
let e = await I.init(), t = x ?? re?.(e.audioStreams ?? []);
|
|
256
|
+
x === void 0 && t !== void 0 && t !== e.audioStreams?.[0]?.streamIndex && (N(I), I = await le(t), e = await I.init());
|
|
257
257
|
let i = e.audioStreams ?? [], a = i.some((e) => e.streamIndex === t) ? t : i[0]?.streamIndex ?? -1;
|
|
258
|
-
|
|
258
|
+
ce?.(i, a);
|
|
259
259
|
let c = y({
|
|
260
260
|
video: n,
|
|
261
261
|
container: r,
|
|
@@ -266,26 +266,26 @@ var i = {
|
|
|
266
266
|
legacyWasmWorkerUrl: h,
|
|
267
267
|
defaultFontUrl: g,
|
|
268
268
|
cjkFontUrl: _,
|
|
269
|
-
onStreams:
|
|
269
|
+
onStreams: se
|
|
270
270
|
});
|
|
271
|
-
if (
|
|
271
|
+
if (L.push(() => c.destroy()), e.attachments?.length && c.pushAttachments(e.attachments), !e.info.output.videoMimeType) throw o("The video codec in this file could not be identified");
|
|
272
272
|
let u = [e.info.output.videoMimeType, e.info.output.audioMimeType].filter(Boolean).join(","), v = `video/mp4; codecs="${u}"`;
|
|
273
273
|
if (!MediaSource.isTypeSupported(v)) throw o("This browser cannot play the codecs in this file: {codecs}", { codecs: u });
|
|
274
|
-
let
|
|
274
|
+
let M = !1, z = (e, t, n = !1) => {
|
|
275
275
|
let r = e?.message === "Cancelled";
|
|
276
|
-
t && r || (console.error(e), (!
|
|
276
|
+
t && r || (console.error(e), (!M || n) && (M = !0, ie?.(r ? o("Reading the video file failed", void 0, { cause: e }) : e)));
|
|
277
277
|
}, B = !1, de = () => {
|
|
278
|
-
if (B ||
|
|
278
|
+
if (B || R) return;
|
|
279
279
|
B = !0;
|
|
280
280
|
let e = n.error;
|
|
281
|
-
|
|
281
|
+
z(new b(`the media element failed: ${e?.message ?? "unknown"}`, { cause: e }), !1, !0);
|
|
282
282
|
}, V = new MediaSource(), H = URL.createObjectURL(V);
|
|
283
|
-
|
|
283
|
+
L.push(() => URL.revokeObjectURL(H)), n.src = H, L.push(() => {
|
|
284
284
|
try {
|
|
285
285
|
HTMLMediaElement.prototype.pause.call(n);
|
|
286
286
|
} catch {}
|
|
287
287
|
n.removeAttribute("src"), n.load();
|
|
288
|
-
}), n.addEventListener("error", de),
|
|
288
|
+
}), n.addEventListener("error", de), L.push(() => n.removeEventListener("error", de));
|
|
289
289
|
let U = await new Promise((t, n) => {
|
|
290
290
|
let r = setTimeout(() => {
|
|
291
291
|
i(), n(o("The MediaSource never opened"));
|
|
@@ -316,7 +316,7 @@ var i = {
|
|
|
316
316
|
}), !B && !n.error) throw e;
|
|
317
317
|
}
|
|
318
318
|
n.error && de();
|
|
319
|
-
let me = !1, G = !1, K, q = 0,
|
|
319
|
+
let me = !1, G = !1, K, q = 0, he, ge = () => he ?? n.currentTime, J = !1, _e = !1, ve = 0, Y = 0, X = null, Z = 0, Q = 0, ye = 0, be = !0, xe = 0, $, Se = (t) => {
|
|
320
320
|
let n = e.indexes;
|
|
321
321
|
if (!n || n.length < 2) return;
|
|
322
322
|
let r;
|
|
@@ -330,13 +330,13 @@ var i = {
|
|
|
330
330
|
let i = n.currentTime, a = e ? T : S, o = e ? E : C, c = s(U), l = (e, t) => (be = !1, fe(e, t)), u = Se(i), d = u === void 0 ? i + a : Math.min(i + a, u - .1);
|
|
331
331
|
if (c.length && c[0].start < d) {
|
|
332
332
|
let e = Ce(c);
|
|
333
|
-
await l(0, d),
|
|
333
|
+
await l(0, d), R || (t = Ce(s(U)) < e - .05);
|
|
334
334
|
}
|
|
335
|
-
if (
|
|
335
|
+
if (R || !e && (q > 0 || G || n.seeking || K !== void 0)) return t ? "back" : "none";
|
|
336
336
|
let f = n.currentTime, p = s(U), m = p.at(-1)?.end ?? 0;
|
|
337
337
|
if (m > f + o) {
|
|
338
338
|
let e = Ce(p);
|
|
339
|
-
await l(f + o, m),
|
|
339
|
+
await l(f + o, m), R || (r = Ce(s(U)) < e - .05);
|
|
340
340
|
}
|
|
341
341
|
return r ? "far" : t ? "back" : "none";
|
|
342
342
|
} finally {
|
|
@@ -345,58 +345,58 @@ var i = {
|
|
|
345
345
|
}, Te = () => {
|
|
346
346
|
let e = s(U);
|
|
347
347
|
if (!e.length) return !0;
|
|
348
|
-
let t =
|
|
348
|
+
let t = ge(), n = e.find((e) => e.start <= t + A && t < e.end);
|
|
349
349
|
return Ae() && Oe(t) && (!n || n.start <= t) || n && n.end >= t + C ? !1 : !n || n.end < t + w;
|
|
350
350
|
}, Ee = (e) => s(U).find((t) => t.start <= e + A && e < t.end), De = () => Ee(n.currentTime), Oe = (e = n.currentTime) => {
|
|
351
351
|
let t = Ee(e);
|
|
352
|
-
return e >=
|
|
352
|
+
return e >= Q - .1 || !!t && t.end >= Q - .1;
|
|
353
353
|
}, ke = () => {
|
|
354
354
|
let e = s(U).map((e) => e.end);
|
|
355
|
-
e.length && (
|
|
356
|
-
}, Ae = () =>
|
|
357
|
-
G = !0,
|
|
358
|
-
let n = ++
|
|
355
|
+
e.length && (Q = Math.max(Q, ...e)), J && (_e = !0);
|
|
356
|
+
}, Ae = () => J || _e && (s(U).at(-1)?.end ?? 0) >= Q - .1, je = async (t) => {
|
|
357
|
+
G = !0, X = null, Z = 0, $ = void 0, ye = t, be = !0;
|
|
358
|
+
let n = ++Y;
|
|
359
359
|
try {
|
|
360
|
-
let { data: r, pts: i, subtitles: a, finished: o } = await
|
|
361
|
-
if (
|
|
362
|
-
o && (
|
|
360
|
+
let { data: r, pts: i, subtitles: a, finished: o } = await I.seek(t);
|
|
361
|
+
if (R || n !== Y) return;
|
|
362
|
+
o && (J = !0), a?.length && c.pushFragments(a), F?.({
|
|
363
363
|
type: "run",
|
|
364
364
|
pts: e.timestampOffset,
|
|
365
365
|
from: i
|
|
366
|
-
}), r.byteLength &&
|
|
366
|
+
}), r.byteLength && F?.({
|
|
367
367
|
type: "fragment",
|
|
368
368
|
data: r
|
|
369
|
-
}), o &&
|
|
369
|
+
}), o && F?.({ type: "end" }), r.byteLength && (await W(r), ke());
|
|
370
370
|
} catch (e) {
|
|
371
|
-
n ===
|
|
371
|
+
n === Y && (be = !1), z(e, R || n !== Y);
|
|
372
372
|
} finally {
|
|
373
|
-
n ===
|
|
373
|
+
n === Y && (G = !1);
|
|
374
374
|
}
|
|
375
375
|
}, Me = async () => {
|
|
376
|
-
let e =
|
|
376
|
+
let e = X;
|
|
377
377
|
if (!e) return;
|
|
378
378
|
let t = () => {
|
|
379
|
-
ke(), $ = void 0,
|
|
379
|
+
ke(), $ = void 0, X === e && (X = null, Z = 0);
|
|
380
380
|
};
|
|
381
381
|
try {
|
|
382
382
|
await W(e), t();
|
|
383
383
|
} catch (r) {
|
|
384
|
-
if (
|
|
384
|
+
if (X !== e) return;
|
|
385
385
|
if (r?.name === "QuotaExceededError") {
|
|
386
386
|
let r = await we(!0).catch(() => "none");
|
|
387
|
-
if (
|
|
387
|
+
if (X !== e) return;
|
|
388
388
|
if (r === "far") {
|
|
389
|
-
$ = void 0,
|
|
389
|
+
$ = void 0, J = !1, await je(De()?.end ?? n.currentTime);
|
|
390
390
|
return;
|
|
391
391
|
}
|
|
392
392
|
if (r === "back") try {
|
|
393
393
|
await W(e), t();
|
|
394
394
|
return;
|
|
395
395
|
} catch (t) {
|
|
396
|
-
if (
|
|
396
|
+
if (X !== e) return;
|
|
397
397
|
if (t?.name !== "QuotaExceededError") {
|
|
398
|
-
if (
|
|
399
|
-
throw
|
|
398
|
+
if (Z += 1, Z < D) return;
|
|
399
|
+
throw X = null, t;
|
|
400
400
|
}
|
|
401
401
|
}
|
|
402
402
|
if (De()) {
|
|
@@ -409,105 +409,105 @@ var i = {
|
|
|
409
409
|
return;
|
|
410
410
|
}
|
|
411
411
|
}
|
|
412
|
-
if (
|
|
413
|
-
throw
|
|
412
|
+
if (Z += 1, Z < D) return;
|
|
413
|
+
throw X = null, r;
|
|
414
414
|
}
|
|
415
415
|
}, Ne = async () => {
|
|
416
|
-
if (me || G || K !== void 0 ||
|
|
416
|
+
if (me || G || K !== void 0 || R) return;
|
|
417
417
|
if ($ !== void 0) {
|
|
418
418
|
let e = n.currentTime, t = Math.abs(e - $.time) >= 1 || Se(e) !== $.keyframe, r = !n.paused && n.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA && Date.now() - $.at >= 1e3;
|
|
419
419
|
if (!t && !r) return;
|
|
420
420
|
$ = void 0;
|
|
421
421
|
}
|
|
422
|
-
if (!
|
|
423
|
-
let e = ++
|
|
422
|
+
if (!X && (J || !Te())) return;
|
|
423
|
+
let e = ++ve, t = Y, r = () => R || e !== ve || t !== Y;
|
|
424
424
|
me = !0;
|
|
425
425
|
try {
|
|
426
|
-
if (!
|
|
427
|
-
let { data: e, subtitles: t, finished: n } = await
|
|
428
|
-
if (r() || (n && (
|
|
426
|
+
if (!X) {
|
|
427
|
+
let { data: e, subtitles: t, finished: n } = await I.read();
|
|
428
|
+
if (r() || (n && (J = !0), t?.length && c.pushFragments(t), e.byteLength && F?.({
|
|
429
429
|
type: "fragment",
|
|
430
430
|
data: e
|
|
431
|
-
}), n &&
|
|
432
|
-
|
|
431
|
+
}), n && F?.({ type: "end" }), !e.byteLength)) return;
|
|
432
|
+
X = e, Z = 0;
|
|
433
433
|
}
|
|
434
|
-
await Me(), !r() &&
|
|
434
|
+
await Me(), !r() && M && (M = !1, ae?.());
|
|
435
435
|
} catch (e) {
|
|
436
|
-
|
|
436
|
+
z(e, r());
|
|
437
437
|
} finally {
|
|
438
|
-
e ===
|
|
438
|
+
e === ve && (me = !1);
|
|
439
439
|
}
|
|
440
440
|
}, Pe = (e) => s(U).some((t) => t.start <= e && e < t.end && t.end >= ye) && Le(e), Fe = (e) => s(U).some((t) => t.start <= e && e < t.end), Ie = (e) => {
|
|
441
441
|
let t = Ee(e);
|
|
442
442
|
return t ? t.end - e : 0;
|
|
443
|
-
}, Le = (e) => Ie(e) >= j || Ae() && Oe(e), Re = async (e) => {
|
|
444
|
-
if (!(
|
|
445
|
-
K && clearTimeout(K), K = void 0,
|
|
443
|
+
}, Le = (e) => Ie(e) >= j || Ae() && Oe(e), Re = () => Q > 0 && (s(U).at(-1)?.end ?? 0) >= Q - .1, ze = (e) => J && Re() && Oe(e) && (Math.abs(e - ye) < .001 || ye >= Q - .1), Be = (e) => be && ((G || Ie(e) > 0) && Math.abs(e - ye) < .001 || ze(e)), Ve = async (e) => {
|
|
444
|
+
if (!(R || B || n.error) && !(Fe(e) && Le(e)) && !Be(e)) {
|
|
445
|
+
K && clearTimeout(K), K = void 0, J = !1, q++, he = e;
|
|
446
446
|
try {
|
|
447
447
|
await je(e);
|
|
448
|
-
let t =
|
|
449
|
-
for (let n = 0; n < ee && !(
|
|
448
|
+
let t = Y;
|
|
449
|
+
for (let n = 0; n < ee && !(R || t !== Y || J || Ie(e) >= j); n++) {
|
|
450
450
|
let t = Ie(e);
|
|
451
451
|
if (await Ne(), Ie(e) <= t) break;
|
|
452
452
|
}
|
|
453
453
|
} finally {
|
|
454
|
-
q--,
|
|
454
|
+
q--, he === e && (he = void 0);
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
|
-
},
|
|
458
|
-
let t = performance.now(), n = t -
|
|
459
|
-
if (n >=
|
|
460
|
-
|
|
457
|
+
}, He = 0, Ue = null, We, Ge = (e) => {
|
|
458
|
+
let t = performance.now(), n = t - He;
|
|
459
|
+
if (n >= te) {
|
|
460
|
+
He = t, Ue = null, oe?.(e);
|
|
461
461
|
return;
|
|
462
462
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
let e =
|
|
466
|
-
|
|
467
|
-
},
|
|
463
|
+
Ue = e, !We && (We = setTimeout(() => {
|
|
464
|
+
We = void 0;
|
|
465
|
+
let e = Ue;
|
|
466
|
+
Ue = null, !(e === null || R) && (He = performance.now(), oe?.(e));
|
|
467
|
+
}, te - n));
|
|
468
468
|
};
|
|
469
|
-
|
|
470
|
-
|
|
469
|
+
L.push(() => {
|
|
470
|
+
We && clearTimeout(We);
|
|
471
471
|
});
|
|
472
|
-
let
|
|
473
|
-
|
|
472
|
+
let Ke = 0;
|
|
473
|
+
L.push(() => {
|
|
474
474
|
K && clearTimeout(K);
|
|
475
475
|
});
|
|
476
|
-
let
|
|
477
|
-
if (
|
|
476
|
+
let qe = () => {
|
|
477
|
+
if (R || B || n.error) return;
|
|
478
478
|
let t = n.currentTime, r = e.info.input.duration || n.duration;
|
|
479
|
-
r > 0 &&
|
|
480
|
-
let i = performance.now(), a = i -
|
|
481
|
-
if (
|
|
482
|
-
if (
|
|
479
|
+
r > 0 && Ge(Math.min(Math.max(t / r, 0), 1));
|
|
480
|
+
let i = performance.now(), a = i - Ke < ne;
|
|
481
|
+
if (Ke = i, !Pe(t) && !Be(t)) {
|
|
482
|
+
if (J = !1, K && clearTimeout(K), !a) {
|
|
483
483
|
K = void 0, je(t);
|
|
484
484
|
return;
|
|
485
485
|
}
|
|
486
486
|
K = setTimeout(() => {
|
|
487
|
-
if (K = void 0,
|
|
487
|
+
if (K = void 0, R) return;
|
|
488
488
|
let e = n.currentTime;
|
|
489
|
-
Pe(e) || (
|
|
490
|
-
},
|
|
489
|
+
Pe(e) || (J = !1, je(e));
|
|
490
|
+
}, ne);
|
|
491
491
|
}
|
|
492
492
|
};
|
|
493
|
-
if (!B && !
|
|
493
|
+
if (!B && !R && (n.addEventListener("seeking", qe), L.push(() => n.removeEventListener("seeking", qe)), F?.({
|
|
494
494
|
type: "init",
|
|
495
495
|
data: e.data,
|
|
496
496
|
audioMimeType: e.info.output.audioMimeType,
|
|
497
497
|
audioStreamIndex: a
|
|
498
|
-
}),
|
|
498
|
+
}), F?.({
|
|
499
499
|
type: "run",
|
|
500
500
|
pts: e.timestampOffset,
|
|
501
501
|
from: 0
|
|
502
|
-
}), e.subtitles?.length && c.pushFragments(e.subtitles),
|
|
502
|
+
}), e.subtitles?.length && c.pushFragments(e.subtitles), P?.()), !B && !R) {
|
|
503
503
|
let e = setInterval(() => {
|
|
504
|
-
B || n.error || (we().catch(() => {}), Ne().catch((e) =>
|
|
504
|
+
B || n.error || (we().catch(() => {}), Ne().catch((e) => z(e, !1)), Ae() && !X && Oe() && V.readyState === "open" && pe(() => !G).catch(() => {}));
|
|
505
505
|
}, 100);
|
|
506
|
-
|
|
506
|
+
L.push(() => clearInterval(e));
|
|
507
507
|
}
|
|
508
508
|
return {
|
|
509
|
-
destroy:
|
|
510
|
-
prepareSeek:
|
|
509
|
+
destroy: ue,
|
|
510
|
+
prepareSeek: Ve,
|
|
511
511
|
videoElement: n,
|
|
512
512
|
selectSubtitleStream: (e) => c.selectStream(e),
|
|
513
513
|
indexes: e.indexes ?? [],
|
|
@@ -517,10 +517,10 @@ var i = {
|
|
|
517
517
|
audioMimeType: e.info.output.audioMimeType
|
|
518
518
|
};
|
|
519
519
|
} catch (e) {
|
|
520
|
-
throw
|
|
520
|
+
throw ue(), e;
|
|
521
521
|
}
|
|
522
|
-
},
|
|
523
|
-
let { publicPath: n, workerUrl: r, length: i, read: a, onThumbnails: o, width: s =
|
|
522
|
+
}, P = 5, ie = 500, ae = 320, oe = 1e6, se = 3, ce = 1e4, F = 1.5, le = 4e6, I = 3e4, L = async (e) => {
|
|
523
|
+
let { publicPath: n, workerUrl: r, length: i, read: a, onThumbnails: o, width: s = ae } = e, c = await t({
|
|
524
524
|
publicPath: n,
|
|
525
525
|
workerUrl: r,
|
|
526
526
|
workerOptions: { type: "module" },
|
|
@@ -528,7 +528,7 @@ var i = {
|
|
|
528
528
|
read: a
|
|
529
529
|
});
|
|
530
530
|
try {
|
|
531
|
-
let t = await c.init(), n = t.duration, r = Math.max(e.interval ??
|
|
531
|
+
let t = await c.init(), n = t.duration, r = Math.max(e.interval ?? P, n / ie), a = [], l = (e) => {
|
|
532
532
|
let t = [];
|
|
533
533
|
for (let [a, o] of e.entries()) {
|
|
534
534
|
let s = t.at(-1);
|
|
@@ -536,7 +536,7 @@ var i = {
|
|
|
536
536
|
timestamp: o.timestamp,
|
|
537
537
|
endTime: n,
|
|
538
538
|
startByte: o.pos,
|
|
539
|
-
endByte: Math.min((e[a + 1]?.pos ?? i) +
|
|
539
|
+
endByte: Math.min((e[a + 1]?.pos ?? i) + oe, i),
|
|
540
540
|
done: !1,
|
|
541
541
|
attempts: 0
|
|
542
542
|
});
|
|
@@ -575,7 +575,7 @@ var i = {
|
|
|
575
575
|
}), o(e);
|
|
576
576
|
}, x = async (e) => {
|
|
577
577
|
if (d) return;
|
|
578
|
-
let t = await Promise.race([c.readKeyframe(e.timestamp), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")),
|
|
578
|
+
let t = await Promise.race([c.readKeyframe(e.timestamp), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")), ce))]), n = await createImageBitmap(new Blob([t], { type: "image/png" })), r = new OffscreenCanvas(s, Math.max(1, Math.round(n.height * (s / n.width))));
|
|
579
579
|
r.getContext("2d").drawImage(n, 0, 0, r.width, r.height), n.close();
|
|
580
580
|
let i = await r.convertToBlob({
|
|
581
581
|
type: "image/webp",
|
|
@@ -599,7 +599,7 @@ var i = {
|
|
|
599
599
|
if (!f.length) return;
|
|
600
600
|
let e = f.splice(y(), 1)[0];
|
|
601
601
|
p = !0, x(e).catch(() => {
|
|
602
|
-
e.attempts += 1, e.done = e.attempts >=
|
|
602
|
+
e.attempts += 1, e.done = e.attempts >= se;
|
|
603
603
|
}).finally(() => {
|
|
604
604
|
p = !1, S();
|
|
605
605
|
});
|
|
@@ -608,7 +608,7 @@ var i = {
|
|
|
608
608
|
}, w = async (e) => {
|
|
609
609
|
_ = !0;
|
|
610
610
|
try {
|
|
611
|
-
let t = await Promise.race([c.init(), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")),
|
|
611
|
+
let t = await Promise.race([c.init(), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")), I))]);
|
|
612
612
|
if (d) return;
|
|
613
613
|
h = e;
|
|
614
614
|
let n = l(t.indexes);
|
|
@@ -634,7 +634,7 @@ var i = {
|
|
|
634
634
|
if (d) return;
|
|
635
635
|
v = e;
|
|
636
636
|
let t = T(e);
|
|
637
|
-
h < 0 ? h = t : (t >= Math.max(h *
|
|
637
|
+
h < 0 ? h = t : (t >= Math.max(h * F, h + le) || t >= i && h < i) && (g = !0), E(e), S();
|
|
638
638
|
},
|
|
639
639
|
prioritize: (e) => {
|
|
640
640
|
d || (m = e);
|
|
@@ -642,13 +642,13 @@ var i = {
|
|
|
642
642
|
destroy: () => {
|
|
643
643
|
d = !0, f.length = 0;
|
|
644
644
|
for (let e of u) URL.revokeObjectURL(e.url);
|
|
645
|
-
u = [],
|
|
645
|
+
u = [], N(c);
|
|
646
646
|
}
|
|
647
647
|
};
|
|
648
648
|
} catch (e) {
|
|
649
|
-
throw
|
|
649
|
+
throw N(c), e;
|
|
650
650
|
}
|
|
651
|
-
},
|
|
651
|
+
}, R = 1280, ue = 1920, z = 100, B = 1e3 / 60, de = 250, V = 2, H = 100, U = 1e3, W, fe = (e) => {
|
|
652
652
|
W?.close();
|
|
653
653
|
let t = () => {
|
|
654
654
|
clearTimeout(r), e.mirror.removeEventListener("leavepictureinpicture", n), W = void 0;
|
|
@@ -665,8 +665,8 @@ var i = {
|
|
|
665
665
|
}, pe = () => {
|
|
666
666
|
let e = W;
|
|
667
667
|
return e?.cancel(), e?.session;
|
|
668
|
-
}, me = () => typeof HTMLCanvasElement < "u" && "captureStream" in HTMLCanvasElement.prototype, G = () => typeof document < "u" && typeof HTMLVideoElement < "u" && typeof HTMLVideoElement.prototype.requestPictureInPicture == "function" && !!document.pictureInPictureEnabled, K = () => typeof HTMLVideoElement < "u" && "mozCaptureStream" in HTMLVideoElement.prototype, q = () => me() ? G() ? "window" : K() ? "burn-in" : null : null,
|
|
669
|
-
let { video: t, subtitles: n } = e, r = e.mode ?? q() ?? "window", i = e.maxWidth ?? (r === "burn-in" ?
|
|
668
|
+
}, me = () => typeof HTMLCanvasElement < "u" && "captureStream" in HTMLCanvasElement.prototype, G = () => typeof document < "u" && typeof HTMLVideoElement < "u" && typeof HTMLVideoElement.prototype.requestPictureInPicture == "function" && !!document.pictureInPictureEnabled, K = () => typeof HTMLVideoElement < "u" && "mozCaptureStream" in HTMLVideoElement.prototype, q = () => me() ? G() ? "window" : K() ? "burn-in" : null : null, he = (e) => {
|
|
669
|
+
let { video: t, subtitles: n } = e, r = e.mode ?? q() ?? "window", i = e.maxWidth ?? (r === "burn-in" ? ue : R), a, o, s, c = 0, l = 0, u = 0, d = !1, f, p = !1, m = !1, h = !1, g, _ = () => r === "burn-in" ? !!a : !!a && document.pictureInPictureElement === a.mirror, v = (e, r) => {
|
|
670
670
|
r.drawImage(t, 0, 0, e.width, e.height);
|
|
671
671
|
let i = n.querySelector("canvas");
|
|
672
672
|
i && !("pending" in i.dataset) && i.width > 0 && i.height > 0 && Math.abs(t.currentTime - u) <= V && r.drawImage(i, 0, 0, e.width, e.height);
|
|
@@ -723,52 +723,52 @@ var i = {
|
|
|
723
723
|
p = !1;
|
|
724
724
|
}, H);
|
|
725
725
|
});
|
|
726
|
-
},
|
|
726
|
+
}, te = [["play", () => {
|
|
727
727
|
t.play().catch(() => {});
|
|
728
|
-
}], ["pause", () => t.pause()]],
|
|
729
|
-
if ("mediaSession" in navigator) for (let [t, n] of
|
|
728
|
+
}], ["pause", () => t.pause()]], ne = (e) => {
|
|
729
|
+
if ("mediaSession" in navigator) for (let [t, n] of te) try {
|
|
730
730
|
navigator.mediaSession.setActionHandler(t, e ? n : null);
|
|
731
731
|
} catch {}
|
|
732
|
-
},
|
|
732
|
+
}, M = () => {
|
|
733
733
|
u = t.currentTime, C(), s = setInterval(() => {
|
|
734
734
|
let e = performance.now();
|
|
735
|
-
e - c <
|
|
735
|
+
e - c < z || t.paused && e - l < de || b();
|
|
736
736
|
}, B);
|
|
737
|
-
},
|
|
738
|
-
e.addEventListener("play", E), e.addEventListener("pause", k), e.addEventListener("leavepictureinpicture",
|
|
739
|
-
},
|
|
740
|
-
f?.(), w(),
|
|
737
|
+
}, N = (e) => {
|
|
738
|
+
e.addEventListener("play", E), e.addEventListener("pause", k), e.addEventListener("leavepictureinpicture", ie), t.addEventListener("play", A), t.addEventListener("pause", j), t.addEventListener("seeked", ee), ne(!0), T();
|
|
739
|
+
}, re = () => {
|
|
740
|
+
f?.(), w(), ne(!1), t.removeEventListener("play", A), t.removeEventListener("pause", j), t.removeEventListener("seeked", ee);
|
|
741
741
|
let e = a;
|
|
742
|
-
return a = void 0, e?.mirror.removeEventListener("play", E), e?.mirror.removeEventListener("pause", k), e?.mirror.removeEventListener("leavepictureinpicture",
|
|
743
|
-
},
|
|
744
|
-
let e =
|
|
742
|
+
return a = void 0, e?.mirror.removeEventListener("play", E), e?.mirror.removeEventListener("pause", k), e?.mirror.removeEventListener("leavepictureinpicture", ie), e;
|
|
743
|
+
}, P = () => {
|
|
744
|
+
let e = re();
|
|
745
745
|
if (e) {
|
|
746
746
|
for (let t of e.stream.getTracks()) t.stop();
|
|
747
747
|
e.mirror.remove();
|
|
748
748
|
}
|
|
749
749
|
g?.();
|
|
750
|
-
},
|
|
750
|
+
}, ie = () => P(), ae = () => {
|
|
751
751
|
let e = t.style.visibility;
|
|
752
752
|
t.style.visibility = "hidden", g = () => {
|
|
753
753
|
g = void 0, t.style.visibility = e;
|
|
754
754
|
};
|
|
755
|
-
},
|
|
755
|
+
}, oe = (e) => {
|
|
756
756
|
let r = t.style.opacity, i = n.style.display;
|
|
757
757
|
e.style.cssText = "position:absolute;inset:0;width:100%;height:100%;object-fit:contain;background:#000;z-index:1", t.style.opacity = "0", n.style.display = "none", g = () => {
|
|
758
758
|
g = void 0, t.style.opacity = r, n.style.display = i;
|
|
759
759
|
};
|
|
760
|
-
},
|
|
760
|
+
}, se = async () => {
|
|
761
761
|
let n = Object.assign(document.createElement("canvas"), y()), i = n.getContext("2d");
|
|
762
762
|
if (!i) throw Error("the picture in picture composite has no 2d context");
|
|
763
763
|
let o = document.createElement("video");
|
|
764
|
-
o.muted = !0, o.playsInline = !0, r === "burn-in" ?
|
|
764
|
+
o.muted = !0, o.playsInline = !0, r === "burn-in" ? oe(o) : o.style.cssText = "position:fixed;width:1px;height:1px;opacity:0;pointer-events:none;left:-1px;top:-1px", v(n, i);
|
|
765
765
|
let s = {
|
|
766
766
|
composite: n,
|
|
767
767
|
context: i,
|
|
768
768
|
stream: n.captureStream(),
|
|
769
769
|
mirror: o
|
|
770
770
|
};
|
|
771
|
-
a = s, o.srcObject = s.stream, (e.container ?? (r === "burn-in" ? t.parentElement : null) ?? document.body).appendChild(o),
|
|
771
|
+
a = s, o.srcObject = s.stream, (e.container ?? (r === "burn-in" ? t.parentElement : null) ?? document.body).appendChild(o), M();
|
|
772
772
|
let c = !0, l = () => {
|
|
773
773
|
c = !1;
|
|
774
774
|
};
|
|
@@ -781,18 +781,18 @@ var i = {
|
|
|
781
781
|
o.removeEventListener("play", l), o.remove();
|
|
782
782
|
return;
|
|
783
783
|
}
|
|
784
|
-
if (o.removeEventListener("play", l),
|
|
784
|
+
if (o.removeEventListener("play", l), N(o), c && D(o), r === "burn-in") {
|
|
785
785
|
t.paused && o.pause(), e.onBurnedInChange?.(!0);
|
|
786
786
|
return;
|
|
787
787
|
}
|
|
788
|
-
await o.requestPictureInPicture(), a === s &&
|
|
789
|
-
},
|
|
788
|
+
await o.requestPictureInPicture(), a === s && ae();
|
|
789
|
+
}, ce = async () => {
|
|
790
790
|
if (!(h || m)) {
|
|
791
791
|
m = !0;
|
|
792
792
|
try {
|
|
793
793
|
if (_()) {
|
|
794
794
|
if (r === "burn-in") {
|
|
795
|
-
|
|
795
|
+
P(), e.onBurnedInChange?.(!1);
|
|
796
796
|
return;
|
|
797
797
|
}
|
|
798
798
|
await document.exitPictureInPicture().catch(() => {});
|
|
@@ -800,26 +800,26 @@ var i = {
|
|
|
800
800
|
}
|
|
801
801
|
r !== "burn-in" && document.pictureInPictureElement && await document.exitPictureInPicture().catch(() => {});
|
|
802
802
|
try {
|
|
803
|
-
await
|
|
803
|
+
await se();
|
|
804
804
|
} catch (t) {
|
|
805
|
-
console.warn("subtitle compositing for picture in picture failed", t),
|
|
805
|
+
console.warn("subtitle compositing for picture in picture failed", t), P(), r === "burn-in" && e.onBurnedInChange?.(!1);
|
|
806
806
|
}
|
|
807
807
|
} finally {
|
|
808
808
|
m = !1;
|
|
809
809
|
}
|
|
810
810
|
}
|
|
811
|
-
},
|
|
812
|
-
return
|
|
813
|
-
toggle:
|
|
811
|
+
}, F = r === "window" ? pe() : void 0;
|
|
812
|
+
return F && (a = F, F.context.fillRect(0, 0, F.composite.width, F.composite.height), M(), N(F.mirror), ae()), {
|
|
813
|
+
toggle: ce,
|
|
814
814
|
mode: r,
|
|
815
815
|
destroy: () => {
|
|
816
816
|
if (h = !0, r === "window" && _()) {
|
|
817
|
-
let e =
|
|
817
|
+
let e = re();
|
|
818
818
|
return g?.(), fe(e);
|
|
819
819
|
}
|
|
820
|
-
|
|
820
|
+
P(), r === "burn-in" && e.onBurnedInChange?.(!1);
|
|
821
821
|
}
|
|
822
822
|
};
|
|
823
823
|
};
|
|
824
824
|
//#endregion
|
|
825
|
-
export { b as a,
|
|
825
|
+
export { b as a, N as c, s as d, l as f, M as i, u as l, a as m, q as n, x as o, i as p, L as r, re as s, he as t, y as u };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as e, l as t, m as n, n as r, o as i, p as a, r as o, s, t as c, u as l } from "./engine-
|
|
1
|
+
import { c as e, l as t, m as n, n as r, o as i, p as a, r as o, s, t as c, u as l } from "./engine-DZ6BX5XH.js";
|
|
2
2
|
import { languageOf as u, playsIn as d, startingTracks as f } from "./language/index.js";
|
|
3
3
|
import { n as p, r as m, t as h } from "./chapters-EBYXcEml.js";
|
|
4
4
|
import { Children as g, Fragment as _, createContext as v, isValidElement as y, useCallback as b, useContext as x, useEffect as S, useMemo as C, useRef as w, useState as T, useSyncExternalStore as E } from "react";
|
package/package.json
CHANGED
|
@@ -679,6 +679,18 @@ export const startPlayback = async (options: PlaybackOptions): Promise<PlaybackC
|
|
|
679
679
|
*/
|
|
680
680
|
const hasRunway = (time: number) => runwayFrom(time) >= SEEK_RUNWAY || (endInBuffer() && atEnd(time))
|
|
681
681
|
|
|
682
|
+
const endBufferedInSource = () =>
|
|
683
|
+
lastAppendedEnd > 0 && (getTimeRanges(sourceBuffer).at(-1)?.end ?? 0) >= lastAppendedEnd - 0.1
|
|
684
|
+
const samePreparedEnd = (time: number) =>
|
|
685
|
+
finished &&
|
|
686
|
+
endBufferedInSource() &&
|
|
687
|
+
atEnd(time) &&
|
|
688
|
+
(Math.abs(time - lastSeekPosition) < 0.001 || lastSeekPosition >= lastAppendedEnd - 0.1)
|
|
689
|
+
const alreadyPrepared = (time: number) =>
|
|
690
|
+
positioned &&
|
|
691
|
+
(((seeking || runwayFrom(time) > 0) && Math.abs(time - lastSeekPosition) < 0.001) ||
|
|
692
|
+
samePreparedEnd(time))
|
|
693
|
+
|
|
682
694
|
/**
|
|
683
695
|
* Put the data in place for a position the playhead has NOT moved to yet.
|
|
684
696
|
*
|
|
@@ -700,6 +712,7 @@ export const startPlayback = async (options: PlaybackOptions): Promise<PlaybackC
|
|
|
700
712
|
const prepareSeek = async (time: number) => {
|
|
701
713
|
if (destroyed || elementFailed || videoElement.error) return
|
|
702
714
|
if (playableAt(time) && hasRunway(time)) return
|
|
715
|
+
if (alreadyPrepared(time)) return
|
|
703
716
|
// A drag still settling holds every read, so the runway would never be read, and its settle would then position the
|
|
704
717
|
// remuxer back where the drag stopped. A seek back under 250 ms after a seek forward is one (Firefox 153 and 157,
|
|
705
718
|
// 2026-10-23).
|
|
@@ -817,7 +830,7 @@ export const startPlayback = async (options: PlaybackOptions): Promise<PlaybackC
|
|
|
817
830
|
* away everything the first one had done. The benchmark caught it as a seek that took twice as
|
|
818
831
|
* long as seeking the old way.
|
|
819
832
|
*/
|
|
820
|
-
if (
|
|
833
|
+
if (alreadyPrepared(time)) return
|
|
821
834
|
finished = false
|
|
822
835
|
if (dragTimer) clearTimeout(dragTimer)
|
|
823
836
|
if (!dragging) {
|