@banou/media-player 0.8.12 → 0.8.15
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 +1 -1
- package/dist/engine/playback.d.ts +9 -0
- package/dist/{engine-Cownv8gD.js → engine-CDdjRm_U.js} +130 -112
- package/dist/index.js +305 -259
- package/dist/react/player.d.ts +1 -0
- package/dist/react/source-feature.d.ts +24 -0
- package/dist/react/video-player.d.ts +8 -0
- package/package.json +1 -1
- package/src/lib/engine/playback.ts +136 -3
- package/src/lib/react/components/control-bar.tsx +7 -3
- package/src/lib/react/components/progress-bar.tsx +65 -3
- package/src/lib/react/hooks/use-drag-value.ts +5 -2
- package/src/lib/react/hooks/use-playback.ts +82 -2
- package/src/lib/react/source-feature.ts +13 -0
- package/src/lib/react/video-player.tsx +8 -0
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-CDdjRm_U.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 };
|
|
@@ -30,6 +30,15 @@ export type PlaybackOptions = {
|
|
|
30
30
|
};
|
|
31
31
|
export type PlaybackController = {
|
|
32
32
|
destroy: () => void;
|
|
33
|
+
/**
|
|
34
|
+
* Get the data for a position in place BEFORE the playhead moves there.
|
|
35
|
+
*
|
|
36
|
+
* Resolves at once when that position already has data. The caller decides how long to wait,
|
|
37
|
+
* because this can take as long as a read, which over a torrent has no ceiling.
|
|
38
|
+
*/
|
|
39
|
+
prepareSeek: (time: number) => Promise<void>;
|
|
40
|
+
/** The element this pipeline drives, so a caller can read what actually got buffered. */
|
|
41
|
+
videoElement: HTMLVideoElement;
|
|
33
42
|
selectSubtitleStream: (streamIndex: number | undefined) => void;
|
|
34
43
|
/** Keyframe index of the input, which is what maps a downloaded byte range onto the timeline. */
|
|
35
44
|
indexes: MediaIndex[];
|
|
@@ -167,13 +167,13 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
167
167
|
constructor(e, t) {
|
|
168
168
|
super(e, t), this.name = "MediaElementError";
|
|
169
169
|
}
|
|
170
|
-
}, g = (e) => !!e && typeof e == "object" && e.mediaElement === !0, _ = -20, v = 60, y = 30, b = -5, x = 20,
|
|
170
|
+
}, g = (e) => !!e && typeof e == "object" && e.mediaElement === !0, _ = -20, v = 60, y = 30, b = -5, x = 20, ee = 5, S = 15e3, C = 1, w = 3, te = 12, T = 200, E = 250, D = 25e5, O = (e) => {
|
|
171
171
|
let { worker: t } = e, n = setTimeout(() => t.terminate(), 2e3);
|
|
172
172
|
e.destroy().catch(() => {}).finally(() => {
|
|
173
173
|
clearTimeout(n), t.terminate();
|
|
174
174
|
});
|
|
175
175
|
}, k = async (t) => {
|
|
176
|
-
let { videoElement: n, canvasElement: r, read: i, length: o, publicPath: c, libavWorkerUrl: l, jassubWorkerUrl: u, jassubWasmUrl: d, jassubLegacyWasmUrl: f, defaultFontUrl: p, bufferSize: g = D, audioStreamIndex: k, onReady:
|
|
176
|
+
let { videoElement: n, canvasElement: r, read: i, length: o, publicPath: c, libavWorkerUrl: l, jassubWorkerUrl: u, jassubWasmUrl: d, jassubLegacyWasmUrl: f, defaultFontUrl: p, bufferSize: g = D, audioStreamIndex: k, onReady: ne, onError: re, onRecovered: ie, onSeek: ae, onSubtitleStreams: oe, onAudioStreams: se } = t, A = await e({
|
|
177
177
|
publicPath: c,
|
|
178
178
|
workerUrl: l,
|
|
179
179
|
workerOptions: { type: "module" },
|
|
@@ -181,18 +181,18 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
181
181
|
length: o,
|
|
182
182
|
audioStreamIndex: k,
|
|
183
183
|
read: i
|
|
184
|
-
}),
|
|
185
|
-
if (!
|
|
186
|
-
|
|
187
|
-
for (let e of [...
|
|
184
|
+
}), j = [], M = !1, N = () => {
|
|
185
|
+
if (!M) {
|
|
186
|
+
M = !0;
|
|
187
|
+
for (let e of [...j].reverse()) try {
|
|
188
188
|
e();
|
|
189
189
|
} catch {}
|
|
190
190
|
}
|
|
191
191
|
};
|
|
192
|
-
|
|
192
|
+
j.push(() => O(A));
|
|
193
193
|
try {
|
|
194
|
-
let e = await
|
|
195
|
-
|
|
194
|
+
let e = await A.init(), t = e.audioStreams ?? [], i = t.some((e) => e.streamIndex === k) ? k : t[0]?.streamIndex ?? -1;
|
|
195
|
+
se?.(t, i);
|
|
196
196
|
let o = m({
|
|
197
197
|
video: n,
|
|
198
198
|
canvas: r,
|
|
@@ -200,13 +200,13 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
200
200
|
wasmUrl: d,
|
|
201
201
|
legacyWasmUrl: f,
|
|
202
202
|
defaultFontUrl: p,
|
|
203
|
-
onStreams:
|
|
203
|
+
onStreams: oe
|
|
204
204
|
});
|
|
205
|
-
if (
|
|
205
|
+
if (j.push(() => o.destroy()), e.attachments?.length && o.pushAttachments(e.attachments), !e.info.output.videoMimeType) throw Error("The video codec in this file could not be identified");
|
|
206
206
|
let c = [e.info.output.videoMimeType, e.info.output.audioMimeType].filter(Boolean).join(","), l = `video/mp4; codecs="${c}"`;
|
|
207
207
|
if (!MediaSource.isTypeSupported(l)) throw Error(`This browser cannot play the codecs in this file: ${c}`);
|
|
208
208
|
let g = new MediaSource(), D = URL.createObjectURL(g);
|
|
209
|
-
|
|
209
|
+
j.push(() => URL.revokeObjectURL(D)), n.src = D, j.push(() => {
|
|
210
210
|
try {
|
|
211
211
|
n.pause();
|
|
212
212
|
} catch {}
|
|
@@ -215,7 +215,7 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
215
215
|
let O = await new Promise((t, n) => {
|
|
216
216
|
let r = setTimeout(() => {
|
|
217
217
|
i(), n(/* @__PURE__ */ Error("The MediaSource never opened"));
|
|
218
|
-
},
|
|
218
|
+
}, S), i = () => {
|
|
219
219
|
clearTimeout(r), g.removeEventListener("sourceopen", a), g.removeEventListener("sourceclose", o), g.removeEventListener("error", o);
|
|
220
220
|
}, a = () => {
|
|
221
221
|
try {
|
|
@@ -230,123 +230,141 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
230
230
|
i(), n(/* @__PURE__ */ Error("The MediaSource closed before a SourceBuffer could be created"));
|
|
231
231
|
};
|
|
232
232
|
g.addEventListener("sourceopen", a, { once: !0 }), g.addEventListener("sourceclose", o, { once: !0 }), g.addEventListener("error", o, { once: !0 });
|
|
233
|
-
}), { appendBuffer:
|
|
234
|
-
await
|
|
235
|
-
let
|
|
233
|
+
}), { appendBuffer: P, unbufferRange: ce, updateTimestampOffset: le, endOfStream: ue } = s(O, g);
|
|
234
|
+
await P(e.data), e.subtitles?.length && o.pushFragments(e.subtitles), ne?.();
|
|
235
|
+
let F = !1, I = !1, L = 0, R, de = () => R ?? n.currentTime, z = !1, B = 0, V = 0, H = null, U = 0, W = 0, G = !1, K = 0, q = (e, t, n = !1) => {
|
|
236
236
|
let r = e?.message === "Cancelled";
|
|
237
|
-
t && r || (console.error(e), !(
|
|
238
|
-
},
|
|
237
|
+
t && r || (console.error(e), !(G && !n) && (G = !0, re?.(r ? Error("Reading the video file failed", { cause: e }) : e)));
|
|
238
|
+
}, fe = async (e = !1) => {
|
|
239
|
+
if (L > 0 && !e) return;
|
|
239
240
|
let t = n.currentTime, r = e ? b : _, i = e ? x : v;
|
|
240
|
-
for (let { start: e, end: n } of a(O)) e < t + r && await
|
|
241
|
-
},
|
|
241
|
+
for (let { start: e, end: n } of a(O)) e < t + r && await ce(e, t + r), n > t + i && await ce(t + i, n);
|
|
242
|
+
}, pe = () => {
|
|
242
243
|
let e = a(O);
|
|
243
244
|
if (!e.length) return !0;
|
|
244
|
-
let t = n.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return !r || r.end < t + y;
|
|
248
|
-
}, J = () => {
|
|
245
|
+
let t = de(), n = e.find((e) => e.start <= t + C && t < e.end);
|
|
246
|
+
return n && n.end >= t + v ? !1 : !n || n.end < t + y;
|
|
247
|
+
}, me = () => {
|
|
249
248
|
let e = n.currentTime;
|
|
250
|
-
return a(O).find((t) => t.start <= e +
|
|
251
|
-
},
|
|
252
|
-
let e =
|
|
253
|
-
return !!e && e.end >=
|
|
254
|
-
},
|
|
249
|
+
return a(O).find((t) => t.start <= e + C && e < t.end);
|
|
250
|
+
}, he = () => {
|
|
251
|
+
let e = me();
|
|
252
|
+
return !!e && e.end >= W - .1;
|
|
253
|
+
}, ge = () => {
|
|
255
254
|
let e = a(O).map((e) => e.end);
|
|
256
|
-
e.length && (
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
let t = ++
|
|
255
|
+
e.length && (W = Math.max(W, ...e));
|
|
256
|
+
}, J = async (e) => {
|
|
257
|
+
I = !0, H = null, U = 0, K = e;
|
|
258
|
+
let t = ++V;
|
|
260
259
|
try {
|
|
261
|
-
let { data: n, pts: r, subtitles: i, finished: a } = await
|
|
262
|
-
if (
|
|
263
|
-
n.byteLength && (await
|
|
260
|
+
let { data: n, pts: r, subtitles: i, finished: a } = await A.seek(e);
|
|
261
|
+
if (M || t !== V || (a && (z = !0), i?.length && o.pushFragments(i), await le(r), M || t !== V)) return;
|
|
262
|
+
n.byteLength && (await P(n), ge());
|
|
264
263
|
} catch (e) {
|
|
265
|
-
q(e,
|
|
264
|
+
q(e, M || t !== V);
|
|
266
265
|
} finally {
|
|
267
|
-
t ===
|
|
266
|
+
t === V && (I = !1);
|
|
268
267
|
}
|
|
269
|
-
},
|
|
270
|
-
let e =
|
|
268
|
+
}, _e = async () => {
|
|
269
|
+
let e = H;
|
|
271
270
|
if (e) try {
|
|
272
|
-
await
|
|
271
|
+
await P(e), ge(), H === e && (H = null, U = 0);
|
|
273
272
|
} catch (t) {
|
|
274
|
-
if (
|
|
273
|
+
if (H !== e) return;
|
|
275
274
|
if (t?.name === "QuotaExceededError") {
|
|
276
|
-
let t = await
|
|
277
|
-
if (
|
|
275
|
+
let t = await fe(!0).then(() => !0, () => !1);
|
|
276
|
+
if (H !== e) return;
|
|
278
277
|
if (t) {
|
|
279
|
-
|
|
278
|
+
z = !1, await J(me()?.end ?? n.currentTime);
|
|
280
279
|
return;
|
|
281
280
|
}
|
|
282
281
|
}
|
|
283
|
-
if (
|
|
284
|
-
throw
|
|
282
|
+
if (U += 1, U < ee) return;
|
|
283
|
+
throw H = null, t;
|
|
285
284
|
}
|
|
286
|
-
},
|
|
287
|
-
if (
|
|
288
|
-
let e = ++
|
|
289
|
-
|
|
285
|
+
}, ve = async () => {
|
|
286
|
+
if (F || I || $ !== void 0 || M || !H && (z || !pe())) return;
|
|
287
|
+
let e = ++B, t = V, n = () => M || e !== B || t !== V;
|
|
288
|
+
F = !0;
|
|
290
289
|
try {
|
|
291
|
-
if (!
|
|
292
|
-
let { data: e, subtitles: t, finished: r } = await
|
|
293
|
-
if (n() || (r && (
|
|
294
|
-
|
|
290
|
+
if (!H) {
|
|
291
|
+
let { data: e, subtitles: t, finished: r } = await A.read();
|
|
292
|
+
if (n() || (r && (z = !0), t?.length && o.pushFragments(t), !e.byteLength)) return;
|
|
293
|
+
H = e, U = 0;
|
|
295
294
|
}
|
|
296
|
-
await
|
|
295
|
+
await _e(), !n() && G && (G = !1, ie?.());
|
|
297
296
|
} catch (e) {
|
|
298
297
|
q(e, n());
|
|
299
298
|
} finally {
|
|
300
|
-
e ===
|
|
299
|
+
e === B && (F = !1);
|
|
300
|
+
}
|
|
301
|
+
}, ye = (e) => e >= K && !!me(), be = (e) => a(O).some((t) => t.start <= e + C && e < t.end), Y = (e) => {
|
|
302
|
+
let t = a(O).find((t) => t.start <= e + C && e < t.end);
|
|
303
|
+
return t ? t.end - e : 0;
|
|
304
|
+
}, xe = async (e) => {
|
|
305
|
+
if (!M && !(Y(e) >= w)) {
|
|
306
|
+
z = !1, L++, R = e;
|
|
307
|
+
try {
|
|
308
|
+
be(e) || await J(e);
|
|
309
|
+
let t = V;
|
|
310
|
+
for (let n = 0; n < te && !(M || t !== V || z || Y(e) >= w); n++) {
|
|
311
|
+
let t = Y(e);
|
|
312
|
+
if (await ve(), Y(e) <= t) break;
|
|
313
|
+
}
|
|
314
|
+
} finally {
|
|
315
|
+
L--, R === e && (R = void 0);
|
|
316
|
+
}
|
|
301
317
|
}
|
|
302
|
-
},
|
|
318
|
+
}, X = 0, Z = null, Q, Se = (e) => {
|
|
303
319
|
let t = performance.now(), n = t - X;
|
|
304
320
|
if (n >= T) {
|
|
305
|
-
X = t, Z = null,
|
|
321
|
+
X = t, Z = null, ae?.(e);
|
|
306
322
|
return;
|
|
307
323
|
}
|
|
308
324
|
Z = e, !Q && (Q = setTimeout(() => {
|
|
309
325
|
Q = void 0;
|
|
310
326
|
let e = Z;
|
|
311
|
-
Z = null, !(e === null ||
|
|
327
|
+
Z = null, !(e === null || M) && (X = performance.now(), ae?.(e));
|
|
312
328
|
}, T - n));
|
|
313
329
|
};
|
|
314
|
-
|
|
330
|
+
j.push(() => {
|
|
315
331
|
Q && clearTimeout(Q);
|
|
316
332
|
});
|
|
317
|
-
let
|
|
318
|
-
|
|
333
|
+
let Ce = 0, $;
|
|
334
|
+
j.push(() => {
|
|
319
335
|
$ && clearTimeout($);
|
|
320
336
|
});
|
|
321
|
-
let
|
|
337
|
+
let we = () => {
|
|
322
338
|
let t = n.currentTime, r = e.info.input.duration || n.duration;
|
|
323
|
-
r > 0 &&
|
|
324
|
-
let i = performance.now(), a = i -
|
|
325
|
-
if (
|
|
326
|
-
if (
|
|
327
|
-
$ = void 0,
|
|
339
|
+
r > 0 && Se(Math.min(Math.max(t / r, 0), 1));
|
|
340
|
+
let i = performance.now(), a = i - Ce < E;
|
|
341
|
+
if (Ce = i, !ye(t) && !(I && Math.abs(t - K) < .001)) {
|
|
342
|
+
if (z = !1, $ && clearTimeout($), !a) {
|
|
343
|
+
$ = void 0, J(t);
|
|
328
344
|
return;
|
|
329
345
|
}
|
|
330
346
|
$ = setTimeout(() => {
|
|
331
|
-
if ($ = void 0,
|
|
347
|
+
if ($ = void 0, M) return;
|
|
332
348
|
let e = n.currentTime;
|
|
333
|
-
|
|
349
|
+
ye(e) || (z = !1, J(e));
|
|
334
350
|
}, E);
|
|
335
351
|
}
|
|
336
352
|
};
|
|
337
|
-
n.addEventListener("seeking",
|
|
338
|
-
let
|
|
339
|
-
if (
|
|
340
|
-
|
|
353
|
+
n.addEventListener("seeking", we), j.push(() => n.removeEventListener("seeking", we));
|
|
354
|
+
let Te = !1, Ee = () => {
|
|
355
|
+
if (Te) return;
|
|
356
|
+
Te = !0;
|
|
341
357
|
let e = n.error;
|
|
342
358
|
q(new h(`the media element failed: ${e?.message ?? "unknown"}`, { cause: e }), !1, !0);
|
|
343
359
|
};
|
|
344
|
-
n.addEventListener("error",
|
|
345
|
-
let
|
|
346
|
-
|
|
360
|
+
n.addEventListener("error", Ee), j.push(() => n.removeEventListener("error", Ee));
|
|
361
|
+
let De = setInterval(() => {
|
|
362
|
+
Te || n.error || (fe().catch(() => {}), ve().catch((e) => q(e, !1)), z && !H && he() && g.readyState === "open" && ue().catch(() => {}));
|
|
347
363
|
}, 100);
|
|
348
|
-
return
|
|
349
|
-
destroy:
|
|
364
|
+
return j.push(() => clearInterval(De)), {
|
|
365
|
+
destroy: N,
|
|
366
|
+
prepareSeek: xe,
|
|
367
|
+
videoElement: n,
|
|
350
368
|
selectSubtitleStream: (e) => o.selectStream(e),
|
|
351
369
|
indexes: e.indexes ?? [],
|
|
352
370
|
duration: e.info.input.duration,
|
|
@@ -354,10 +372,10 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
354
372
|
audioMimeType: e.info.output.audioMimeType
|
|
355
373
|
};
|
|
356
374
|
} catch (e) {
|
|
357
|
-
throw
|
|
375
|
+
throw N(), e;
|
|
358
376
|
}
|
|
359
|
-
},
|
|
360
|
-
let { publicPath: n, workerUrl: r, length: i, read: a, onThumbnails: o, width: s =
|
|
377
|
+
}, ne = 5, re = 500, ie = 320, ae = 1e6, oe = 3, se = 1e4, A = async (e) => {
|
|
378
|
+
let { publicPath: n, workerUrl: r, length: i, read: a, onThumbnails: o, width: s = ie } = e, c = await t({
|
|
361
379
|
publicPath: n,
|
|
362
380
|
workerUrl: r,
|
|
363
381
|
workerOptions: { type: "module" },
|
|
@@ -365,14 +383,14 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
365
383
|
read: a
|
|
366
384
|
});
|
|
367
385
|
try {
|
|
368
|
-
let t = await c.init(), n = t.duration, r = Math.max(e.interval ??
|
|
386
|
+
let t = await c.init(), n = t.duration, r = Math.max(e.interval ?? ne, n / re), a = [];
|
|
369
387
|
for (let [e, o] of t.indexes.entries()) {
|
|
370
388
|
let s = a.at(-1);
|
|
371
389
|
s && o.timestamp - s.timestamp < r || a.push({
|
|
372
390
|
timestamp: o.timestamp,
|
|
373
391
|
endTime: n,
|
|
374
392
|
startByte: o.pos,
|
|
375
|
-
endByte: Math.min((t.indexes[e + 1]?.pos ?? i) +
|
|
393
|
+
endByte: Math.min((t.indexes[e + 1]?.pos ?? i) + ae, i),
|
|
376
394
|
done: !1,
|
|
377
395
|
attempts: 0
|
|
378
396
|
});
|
|
@@ -403,7 +421,7 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
403
421
|
}, p = (e) => {
|
|
404
422
|
e.done = !0, d = d.then(async () => {
|
|
405
423
|
if (u) return;
|
|
406
|
-
let t = await Promise.race([c.readKeyframe(e.timestamp), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")),
|
|
424
|
+
let t = await Promise.race([c.readKeyframe(e.timestamp), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")), se))]), n = await createImageBitmap(new Blob([t], { type: "image/png" })), r = new OffscreenCanvas(s, Math.max(1, Math.round(n.height * (s / n.width))));
|
|
407
425
|
r.getContext("2d").drawImage(n, 0, 0, r.width, r.height), n.close();
|
|
408
426
|
let i = await r.convertToBlob({
|
|
409
427
|
type: "image/webp",
|
|
@@ -415,7 +433,7 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
415
433
|
endTime: e.endTime
|
|
416
434
|
}].sort((e, t) => e.startTime - t.startTime), f());
|
|
417
435
|
}).catch(() => {
|
|
418
|
-
e.attempts += 1, e.done = e.attempts >=
|
|
436
|
+
e.attempts += 1, e.done = e.attempts >= oe;
|
|
419
437
|
});
|
|
420
438
|
};
|
|
421
439
|
return f(), {
|
|
@@ -431,8 +449,8 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
431
449
|
} catch (e) {
|
|
432
450
|
throw O(c), e;
|
|
433
451
|
}
|
|
434
|
-
},
|
|
435
|
-
let { video: t, canvas: n } = e, r = e.mode ??
|
|
452
|
+
}, j = 1280, M = 1920, N = 250, P = 100, ce = () => typeof HTMLCanvasElement < "u" && "captureStream" in HTMLCanvasElement.prototype, le = () => typeof document < "u" && typeof HTMLVideoElement < "u" && typeof HTMLVideoElement.prototype.requestPictureInPicture == "function" && !!document.pictureInPictureEnabled, ue = () => typeof HTMLVideoElement < "u" && "mozCaptureStream" in HTMLVideoElement.prototype, F = () => ce() ? le() ? "window" : ue() ? "burn-in" : null : null, I = (e) => {
|
|
453
|
+
let { video: t, canvas: n } = e, r = e.mode ?? F() ?? "window", i = e.maxWidth ?? (r === "burn-in" ? M : j), a, o, s, c = !1, l = !1, u = !1, d = !1, f, p = () => r === "burn-in" ? !!a : !!a && document.pictureInPictureElement === a.mirror, m = (e, r) => {
|
|
436
454
|
r.drawImage(t, 0, 0, e.width, e.height), n.width > 0 && n.height > 0 && r.drawImage(n, 0, 0, e.width, e.height);
|
|
437
455
|
}, h = () => {
|
|
438
456
|
a && m(a.composite, a.context);
|
|
@@ -446,52 +464,52 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
446
464
|
"mediaSession" in navigator && (navigator.mediaSession.playbackState = t.paused ? "paused" : "playing");
|
|
447
465
|
}, x = () => {
|
|
448
466
|
c || l || !t.paused || t.play().catch(() => {});
|
|
449
|
-
},
|
|
467
|
+
}, ee = () => {
|
|
450
468
|
c || l || (t.paused || t.pause(), r !== "burn-in" && (c = !0, a?.mirror.play().catch(() => {}).finally(() => {
|
|
451
469
|
c = !1;
|
|
452
470
|
})));
|
|
453
|
-
},
|
|
471
|
+
}, S = () => {
|
|
454
472
|
b(), a?.mirror.play().catch(() => {});
|
|
455
|
-
},
|
|
473
|
+
}, C = () => {
|
|
456
474
|
b(), r === "burn-in" && a?.mirror.pause();
|
|
457
|
-
},
|
|
475
|
+
}, w = () => {
|
|
458
476
|
if (r !== "burn-in" || !a || !t.paused || l) return;
|
|
459
477
|
l = !0;
|
|
460
478
|
let { mirror: e } = a;
|
|
461
479
|
h(), e.play().then(() => new Promise((e) => {
|
|
462
|
-
setTimeout(e,
|
|
480
|
+
setTimeout(e, P);
|
|
463
481
|
})).catch(() => {}).finally(() => {
|
|
464
482
|
e.pause(), setTimeout(() => {
|
|
465
483
|
l = !1;
|
|
466
|
-
},
|
|
484
|
+
}, P);
|
|
467
485
|
});
|
|
468
|
-
},
|
|
486
|
+
}, te = [["play", () => {
|
|
469
487
|
t.play().catch(() => {});
|
|
470
|
-
}], ["pause", () => t.pause()]],
|
|
471
|
-
if ("mediaSession" in navigator) for (let [t, n] of
|
|
488
|
+
}], ["pause", () => t.pause()]], T = (e) => {
|
|
489
|
+
if ("mediaSession" in navigator) for (let [t, n] of te) try {
|
|
472
490
|
navigator.mediaSession.setActionHandler(t, e ? n : null);
|
|
473
491
|
} catch {}
|
|
474
|
-
},
|
|
475
|
-
if (y(),
|
|
492
|
+
}, E = () => {
|
|
493
|
+
if (y(), T(!1), t.removeEventListener("play", S), t.removeEventListener("pause", C), t.removeEventListener("seeked", w), !a) {
|
|
476
494
|
f?.();
|
|
477
495
|
return;
|
|
478
496
|
}
|
|
479
497
|
let { stream: e, mirror: n } = a;
|
|
480
|
-
n.removeEventListener("play", x), n.removeEventListener("pause",
|
|
498
|
+
n.removeEventListener("play", x), n.removeEventListener("pause", ee), n.removeEventListener("leavepictureinpicture", D);
|
|
481
499
|
for (let t of e.getTracks()) t.stop();
|
|
482
500
|
n.remove(), a = void 0, f?.();
|
|
483
|
-
},
|
|
501
|
+
}, D = () => E(), O = (e) => {
|
|
484
502
|
let r = t.style.opacity, i = n.style.display;
|
|
485
503
|
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", f = () => {
|
|
486
504
|
f = void 0, t.style.opacity = r, n.style.display = i;
|
|
487
505
|
};
|
|
488
|
-
},
|
|
506
|
+
}, k = async () => {
|
|
489
507
|
let n = Math.min(t.videoWidth || i, i), o = Math.round(n * ((t.videoHeight || 9) / (t.videoWidth || 16))), c = document.createElement("canvas");
|
|
490
508
|
c.width = n, c.height = o;
|
|
491
509
|
let l = c.getContext("2d");
|
|
492
510
|
if (!l) throw Error("the picture in picture composite has no 2d context");
|
|
493
511
|
let u = document.createElement("video");
|
|
494
|
-
u.muted = !0, u.playsInline = !0, r === "burn-in" ?
|
|
512
|
+
u.muted = !0, u.playsInline = !0, r === "burn-in" ? O(u) : u.style.cssText = "position:fixed;width:1px;height:1px;opacity:0;pointer-events:none;left:-1px;top:-1px", m(c, l);
|
|
495
513
|
let f = {
|
|
496
514
|
composite: c,
|
|
497
515
|
context: l,
|
|
@@ -500,7 +518,7 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
500
518
|
};
|
|
501
519
|
if (a = f, u.srcObject = f.stream, (e.container ?? t.parentElement ?? document.body).appendChild(u), v(), s = setInterval(() => {
|
|
502
520
|
t.paused && h();
|
|
503
|
-
},
|
|
521
|
+
}, N), u.play().catch(() => {}), u.readyState === 0 && await new Promise((e) => {
|
|
504
522
|
let t = () => {
|
|
505
523
|
clearTimeout(n), e();
|
|
506
524
|
}, n = setTimeout(t, 1e3);
|
|
@@ -509,7 +527,7 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
509
527
|
u.remove();
|
|
510
528
|
return;
|
|
511
529
|
}
|
|
512
|
-
if (u.addEventListener("play", x), u.addEventListener("pause",
|
|
530
|
+
if (u.addEventListener("play", x), u.addEventListener("pause", ee), u.addEventListener("leavepictureinpicture", D), t.addEventListener("play", S), t.addEventListener("pause", C), t.addEventListener("seeked", w), T(!0), b(), r === "burn-in") {
|
|
513
531
|
t.paused && u.pause(), e.onBurnedInChange?.(!0);
|
|
514
532
|
return;
|
|
515
533
|
}
|
|
@@ -522,7 +540,7 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
522
540
|
try {
|
|
523
541
|
if (p()) {
|
|
524
542
|
if (r === "burn-in") {
|
|
525
|
-
|
|
543
|
+
E(), e.onBurnedInChange?.(!1);
|
|
526
544
|
return;
|
|
527
545
|
}
|
|
528
546
|
await document.exitPictureInPicture().catch(() => {});
|
|
@@ -530,9 +548,9 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
530
548
|
}
|
|
531
549
|
r !== "burn-in" && document.pictureInPictureElement && await document.exitPictureInPicture().catch(() => {});
|
|
532
550
|
try {
|
|
533
|
-
await
|
|
551
|
+
await k();
|
|
534
552
|
} catch (t) {
|
|
535
|
-
console.warn("subtitle compositing for picture in picture failed", t),
|
|
553
|
+
console.warn("subtitle compositing for picture in picture failed", t), E(), r === "burn-in" && e.onBurnedInChange?.(!1);
|
|
536
554
|
}
|
|
537
555
|
} finally {
|
|
538
556
|
u = !1;
|
|
@@ -541,9 +559,9 @@ var a = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
541
559
|
},
|
|
542
560
|
mode: r,
|
|
543
561
|
destroy: () => {
|
|
544
|
-
d = !0, r !== "burn-in" && p() && document.exitPictureInPicture().catch(() => {}),
|
|
562
|
+
d = !0, r !== "burn-in" && p() && document.exitPictureInPicture().catch(() => {}), E(), r === "burn-in" && e.onBurnedInChange?.(!1);
|
|
545
563
|
}
|
|
546
564
|
};
|
|
547
565
|
};
|
|
548
566
|
//#endregion
|
|
549
|
-
export { h as a, O as c, a as d, s as f, D as i, c as l,
|
|
567
|
+
export { h as a, O as c, a as d, s as f, D as i, c as l, F as n, g as o, A as r, k as s, I as t, m as u };
|