@banou/media-player 0.10.26 → 0.10.28
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/README.md +27 -1
- package/dist/engine/index.js +1 -1
- package/dist/engine/playback.d.ts +5 -0
- package/dist/{engine-AjFLuCdA.js → engine-DeEY2qao.js} +94 -92
- package/dist/index.js +745 -700
- package/dist/language/index.d.ts +25 -0
- package/dist/language/index.js +75 -0
- package/dist/react/video-player.d.ts +25 -0
- package/dist/volume-normalizer-worklet.js +15 -7
- package/package.json +5 -1
- package/src/lib/audio/volume-normalizer-worklet.js +15 -7
- package/src/lib/engine/playback.ts +18 -6
- package/src/lib/language/index.ts +129 -0
- package/src/lib/react/hooks/use-playback.ts +50 -17
- package/src/lib/react/video-player.tsx +51 -6
package/README.md
CHANGED
|
@@ -167,7 +167,8 @@ chrome at once.
|
|
|
167
167
|
Play and pause, seek with a preview thumbnail and a keyframe-accurate scrub, chapters on the seekbar,
|
|
168
168
|
an offer to skip an opening or ending, volume on a log curve, mute, playback speed, audio track
|
|
169
169
|
selection, subtitle track selection, picture in picture, fullscreen, and keyboard shortcuts. Nothing
|
|
170
|
-
is persisted: volume
|
|
170
|
+
is persisted: volume and speed start at their defaults every load, and tracks at the
|
|
171
|
+
[preferred languages](#preferred-languages) you pass, or the file's defaults.
|
|
171
172
|
|
|
172
173
|
The shortcuts (Space or `k`, `f`, `m`, the arrow keys, and `<` and `>` to pause and step one frame back or forward)
|
|
173
174
|
listen on the whole page, and leave Ctrl, Cmd and Alt combinations to the browser. The frame steps need a media
|
|
@@ -295,6 +296,31 @@ on the page's next click, tap or key press, and the video plays as it always did
|
|
|
295
296
|
The refusal comes when routing would, once the switch is on and the AudioContext runs: until then the switch reads as
|
|
296
297
|
available, and from then on it reads Unavailable, with the element never routed and playing as it always did.
|
|
297
298
|
|
|
299
|
+
### Preferred languages
|
|
300
|
+
|
|
301
|
+
Pass the languages to start a file in, and save what the viewer picks:
|
|
302
|
+
|
|
303
|
+
```tsx
|
|
304
|
+
<MediaPlayer
|
|
305
|
+
{...source}
|
|
306
|
+
preferredAudioLanguage={saved.audio}
|
|
307
|
+
preferredSubtitleLanguage={saved.subtitles}
|
|
308
|
+
onPreferredAudioLanguageChange={(audio) => save({ ...saved, audio })}
|
|
309
|
+
onPreferredSubtitleLanguageChange={(subtitles) => save({ ...saved, subtitles })}
|
|
310
|
+
/>
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
A preference is a tag or a name (`ja`, `ja-JP`, `jpn`, `Japanese`, `English (US)`), and a pick is reported the way the
|
|
314
|
+
track names its language, its tag or else its title, or null for subtitles off. A file starts on its full track in the
|
|
315
|
+
preferred language, never a commentary or a signs and songs track when a full one exists, and on its default when it has
|
|
316
|
+
nothing in that language. What the viewer picks wins for that file. A subtitle track that names no language is reported
|
|
317
|
+
by its title, and only when it turns subtitles on, so the next file starts with them on, on the track of that title if
|
|
318
|
+
it has one.
|
|
319
|
+
|
|
320
|
+
A media the player does not own reports picks the same way, by the option's label once the source's `select`
|
|
321
|
+
resolves, and its host applies the preference to its own tracks: `preferredSelection(selection, preference)`, from
|
|
322
|
+
`@banou/media-player/language`, names the option to select, and imports nothing else of the player.
|
|
323
|
+
|
|
298
324
|
## Layout
|
|
299
325
|
|
|
300
326
|
One package. `src/` is the demo app, `src/lib` is the library it publishes, and the app imports it by
|
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-DeEY2qao.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 };
|
|
@@ -64,6 +64,11 @@ export type PlaybackOptions = {
|
|
|
64
64
|
cjkFontUrl?: string;
|
|
65
65
|
bufferSize?: number;
|
|
66
66
|
audioStreamIndex?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Picks the audio stream from the file's own when `audioStreamIndex` names none, undefined for the default. A pick
|
|
69
|
+
* other than the default makes the remuxer again before anything plays, since libav fixes its stream when it is made.
|
|
70
|
+
*/
|
|
71
|
+
chooseAudioStream?: (streams: AudioStream[]) => number | undefined;
|
|
67
72
|
onReady?: () => void;
|
|
68
73
|
onError?: (error: unknown) => void;
|
|
69
74
|
onRecovered?: () => void;
|
|
@@ -184,15 +184,15 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
184
184
|
clearTimeout(n), t.terminate();
|
|
185
185
|
});
|
|
186
186
|
}, ee = async (t) => {
|
|
187
|
-
let { videoElement: n, subtitleContainer: r, read: a, length: s, publicPath: c, libavWorkerUrl: l, jassubWorkerUrl: u, jassubWasmUrl: d, jassubLegacyWasmUrl: f, defaultFontUrl: p, cjkFontUrl: m, bufferSize: h = j, audioStreamIndex: v,
|
|
187
|
+
let { videoElement: n, subtitleContainer: r, read: a, length: s, publicPath: c, libavWorkerUrl: l, jassubWorkerUrl: u, jassubWasmUrl: d, jassubLegacyWasmUrl: f, defaultFontUrl: p, cjkFontUrl: m, bufferSize: h = j, audioStreamIndex: v, chooseAudioStream: ee, onReady: te, onError: ne, onRecovered: re, onSeek: ie, onSubtitleStreams: ae, onAudioStreams: oe, onOutput: N } = t, se = (t) => e({
|
|
188
188
|
publicPath: c,
|
|
189
189
|
workerUrl: l,
|
|
190
190
|
workerOptions: { type: "module" },
|
|
191
191
|
bufferSize: h,
|
|
192
192
|
length: s,
|
|
193
|
-
audioStreamIndex:
|
|
193
|
+
audioStreamIndex: t,
|
|
194
194
|
read: a
|
|
195
|
-
}), F = [], I = !1,
|
|
195
|
+
}), P = await se(v), F = [], I = !1, ce = () => {
|
|
196
196
|
if (!I) {
|
|
197
197
|
I = !0;
|
|
198
198
|
for (let e of [...F].reverse()) try {
|
|
@@ -202,9 +202,11 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
202
202
|
};
|
|
203
203
|
F.push(() => M(P));
|
|
204
204
|
try {
|
|
205
|
-
let e = await P.init(), t =
|
|
206
|
-
|
|
207
|
-
let s =
|
|
205
|
+
let e = await P.init(), t = v ?? ee?.(e.audioStreams ?? []);
|
|
206
|
+
v === void 0 && t !== void 0 && t !== e.audioStreams?.[0]?.streamIndex && (M(P), P = await se(t), e = await P.init());
|
|
207
|
+
let a = e.audioStreams ?? [], s = a.some((e) => e.streamIndex === t) ? t : a[0]?.streamIndex ?? -1;
|
|
208
|
+
oe?.(a, s);
|
|
209
|
+
let c = g({
|
|
208
210
|
video: n,
|
|
209
211
|
container: r,
|
|
210
212
|
workerUrl: u,
|
|
@@ -212,160 +214,160 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
212
214
|
legacyWasmUrl: f,
|
|
213
215
|
defaultFontUrl: p,
|
|
214
216
|
cjkFontUrl: m,
|
|
215
|
-
onStreams:
|
|
217
|
+
onStreams: ae
|
|
216
218
|
});
|
|
217
|
-
if (F.push(() =>
|
|
218
|
-
let
|
|
219
|
-
if (!MediaSource.isTypeSupported(
|
|
220
|
-
let
|
|
221
|
-
F.push(() => URL.revokeObjectURL(
|
|
219
|
+
if (F.push(() => c.destroy()), e.attachments?.length && c.pushAttachments(e.attachments), !e.info.output.videoMimeType) throw Error("The video codec in this file could not be identified");
|
|
220
|
+
let l = [e.info.output.videoMimeType, e.info.output.audioMimeType].filter(Boolean).join(","), h = `video/mp4; codecs="${l}"`;
|
|
221
|
+
if (!MediaSource.isTypeSupported(h)) throw Error(`This browser cannot play the codecs in this file: ${l}`);
|
|
222
|
+
let j = new MediaSource(), le = URL.createObjectURL(j);
|
|
223
|
+
F.push(() => URL.revokeObjectURL(le)), n.src = le, F.push(() => {
|
|
222
224
|
try {
|
|
223
225
|
n.pause();
|
|
224
226
|
} catch {}
|
|
225
227
|
n.removeAttribute("src"), n.load();
|
|
226
228
|
});
|
|
227
|
-
let
|
|
229
|
+
let L = await new Promise((t, n) => {
|
|
228
230
|
let r = setTimeout(() => {
|
|
229
231
|
i(), n(/* @__PURE__ */ Error("The MediaSource never opened"));
|
|
230
232
|
}, T), i = () => {
|
|
231
|
-
clearTimeout(r),
|
|
233
|
+
clearTimeout(r), j.removeEventListener("sourceopen", a), j.removeEventListener("sourceclose", o), j.removeEventListener("error", o);
|
|
232
234
|
}, a = () => {
|
|
233
235
|
try {
|
|
234
|
-
let n =
|
|
236
|
+
let n = j.addSourceBuffer(h);
|
|
235
237
|
n.mode = "segments";
|
|
236
238
|
let r = e.info.input.duration;
|
|
237
|
-
Number.isFinite(r) && r > 0 && (
|
|
239
|
+
Number.isFinite(r) && r > 0 && (j.duration = r), i(), t(n);
|
|
238
240
|
} catch (e) {
|
|
239
241
|
i(), n(e);
|
|
240
242
|
}
|
|
241
243
|
}, o = () => {
|
|
242
244
|
i(), n(/* @__PURE__ */ Error("The MediaSource closed before a SourceBuffer could be created"));
|
|
243
245
|
};
|
|
244
|
-
|
|
245
|
-
}), { appendBuffer:
|
|
246
|
-
await
|
|
246
|
+
j.addEventListener("sourceopen", a, { once: !0 }), j.addEventListener("sourceclose", o, { once: !0 }), j.addEventListener("error", o, { once: !0 });
|
|
247
|
+
}), { appendBuffer: R, unbufferRange: ue, updateTimestampOffset: de, endOfStream: fe } = o(L, j);
|
|
248
|
+
await R(e.data), N?.({
|
|
247
249
|
type: "init",
|
|
248
250
|
data: e.data,
|
|
249
251
|
audioMimeType: e.info.output.audioMimeType,
|
|
250
|
-
audioStreamIndex:
|
|
252
|
+
audioStreamIndex: s
|
|
251
253
|
}), N?.({
|
|
252
254
|
type: "run",
|
|
253
255
|
pts: 0
|
|
254
|
-
}), e.subtitles?.length &&
|
|
255
|
-
let
|
|
256
|
+
}), e.subtitles?.length && c.pushFragments(e.subtitles), te?.();
|
|
257
|
+
let z = !1, B = !1, pe = 0, V, me = () => V ?? n.currentTime, H = !1, he = !1, ge = 0, U = 0, W = null, G = 0, K = 0, q = !1, _e = 0, J = !0, Y = (e, t, n = !1) => {
|
|
256
258
|
let r = e?.message === "Cancelled";
|
|
257
|
-
t && r || (console.error(e), (!q || n) && (q = !0,
|
|
258
|
-
},
|
|
259
|
-
if (
|
|
260
|
-
let t = n.currentTime, r = e ? S : y, a = e ? C : b, o = i(
|
|
259
|
+
t && r || (console.error(e), (!q || n) && (q = !0, ne?.(r ? Error("Reading the video file failed", { cause: e }) : e)));
|
|
260
|
+
}, ve = async (e = !1) => {
|
|
261
|
+
if (pe > 0 && !e) return;
|
|
262
|
+
let t = n.currentTime, r = e ? S : y, a = e ? C : b, o = i(L), s = (e, t) => (J = !1, ue(e, t));
|
|
261
263
|
o.length && o[0].start < t + r && await s(0, t + r);
|
|
262
264
|
for (let { end: e } of o) e > t + a && await s(t + a, e);
|
|
263
|
-
},
|
|
264
|
-
let e = i(
|
|
265
|
+
}, ye = () => {
|
|
266
|
+
let e = i(L);
|
|
265
267
|
if (!e.length) return !0;
|
|
266
|
-
let t =
|
|
267
|
-
return
|
|
268
|
-
},
|
|
269
|
-
let t =
|
|
268
|
+
let t = me(), n = e.find((e) => e.start <= t + E && t < e.end);
|
|
269
|
+
return we() && Se(t) && (!n || n.start <= t) || n && n.end >= t + b ? !1 : !n || n.end < t + x;
|
|
270
|
+
}, be = (e) => i(L).find((t) => t.start <= e + E && e < t.end), xe = () => be(n.currentTime), Se = (e = n.currentTime) => {
|
|
271
|
+
let t = be(e);
|
|
270
272
|
return e >= K - .1 || !!t && t.end >= K - .1;
|
|
271
|
-
},
|
|
272
|
-
let e = i(
|
|
273
|
-
e.length && (K = Math.max(K, ...e)), H && (
|
|
274
|
-
},
|
|
275
|
-
|
|
273
|
+
}, Ce = () => {
|
|
274
|
+
let e = i(L).map((e) => e.end);
|
|
275
|
+
e.length && (K = Math.max(K, ...e)), H && (he = !0);
|
|
276
|
+
}, we = () => H || he && (i(L).at(-1)?.end ?? 0) >= K - .1, X = async (e) => {
|
|
277
|
+
B = !0, W = null, G = 0, _e = e, J = !0;
|
|
276
278
|
let t = ++U;
|
|
277
279
|
try {
|
|
278
280
|
let { data: n, pts: r, subtitles: i, finished: a } = await P.seek(e);
|
|
279
|
-
if (I || t !== U || (a && (H = !0), i?.length &&
|
|
281
|
+
if (I || t !== U || (a && (H = !0), i?.length && c.pushFragments(i), await de(r), I || t !== U)) return;
|
|
280
282
|
N?.({
|
|
281
283
|
type: "run",
|
|
282
284
|
pts: r
|
|
283
285
|
}), n.byteLength && N?.({
|
|
284
286
|
type: "fragment",
|
|
285
287
|
data: n
|
|
286
|
-
}), a && N?.({ type: "end" }), n.byteLength && (await
|
|
288
|
+
}), a && N?.({ type: "end" }), n.byteLength && (await R(n), Ce());
|
|
287
289
|
} catch (e) {
|
|
288
290
|
t === U && (J = !1), Y(e, I || t !== U);
|
|
289
291
|
} finally {
|
|
290
|
-
t === U && (
|
|
292
|
+
t === U && (B = !1);
|
|
291
293
|
}
|
|
292
|
-
},
|
|
294
|
+
}, Te = async () => {
|
|
293
295
|
let e = W;
|
|
294
296
|
if (e) try {
|
|
295
|
-
await
|
|
297
|
+
await R(e), Ce(), W === e && (W = null, G = 0);
|
|
296
298
|
} catch (t) {
|
|
297
299
|
if (W !== e) return;
|
|
298
300
|
if (t?.name === "QuotaExceededError") {
|
|
299
|
-
let t = await
|
|
301
|
+
let t = await ve(!0).then(() => !0, () => !1);
|
|
300
302
|
if (W !== e) return;
|
|
301
303
|
if (t) {
|
|
302
|
-
H = !1, await X(
|
|
304
|
+
H = !1, await X(xe()?.end ?? n.currentTime);
|
|
303
305
|
return;
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
308
|
if (G += 1, G < w) return;
|
|
307
309
|
throw W = null, t;
|
|
308
310
|
}
|
|
309
|
-
},
|
|
310
|
-
if (
|
|
311
|
-
let e = ++
|
|
312
|
-
|
|
311
|
+
}, Ee = async () => {
|
|
312
|
+
if (z || B || $ !== void 0 || I || !W && (H || !ye())) return;
|
|
313
|
+
let e = ++ge, t = U, n = () => I || e !== ge || t !== U;
|
|
314
|
+
z = !0;
|
|
313
315
|
try {
|
|
314
316
|
if (!W) {
|
|
315
317
|
let { data: e, subtitles: t, finished: r } = await P.read();
|
|
316
|
-
if (n() || (r && (H = !0), t?.length &&
|
|
318
|
+
if (n() || (r && (H = !0), t?.length && c.pushFragments(t), e.byteLength && N?.({
|
|
317
319
|
type: "fragment",
|
|
318
320
|
data: e
|
|
319
321
|
}), r && N?.({ type: "end" }), !e.byteLength)) return;
|
|
320
322
|
W = e, G = 0;
|
|
321
323
|
}
|
|
322
|
-
await
|
|
324
|
+
await Te(), !n() && q && (q = !1, re?.());
|
|
323
325
|
} catch (e) {
|
|
324
326
|
Y(e, n());
|
|
325
327
|
} finally {
|
|
326
|
-
e ===
|
|
328
|
+
e === ge && (z = !1);
|
|
327
329
|
}
|
|
328
|
-
},
|
|
329
|
-
let t =
|
|
330
|
+
}, De = (e) => i(L).some((t) => t.start <= e && e < t.end && t.end >= _e) && ke(e), Oe = (e) => i(L).some((t) => t.start <= e && e < t.end), Z = (e) => {
|
|
331
|
+
let t = be(e);
|
|
330
332
|
return t ? t.end - e : 0;
|
|
331
|
-
},
|
|
332
|
-
if (!I && !(
|
|
333
|
-
$ && clearTimeout($), $ = void 0, H = !1,
|
|
333
|
+
}, ke = (e) => Z(e) >= D || we() && Se(e), Ae = async (e) => {
|
|
334
|
+
if (!I && !(Oe(e) && ke(e))) {
|
|
335
|
+
$ && clearTimeout($), $ = void 0, H = !1, pe++, V = e;
|
|
334
336
|
try {
|
|
335
337
|
await X(e);
|
|
336
338
|
let t = U;
|
|
337
339
|
for (let n = 0; n < O && !(I || t !== U || H || Z(e) >= D); n++) {
|
|
338
340
|
let t = Z(e);
|
|
339
|
-
if (await
|
|
341
|
+
if (await Ee(), Z(e) <= t) break;
|
|
340
342
|
}
|
|
341
343
|
} finally {
|
|
342
|
-
|
|
344
|
+
pe--, V === e && (V = void 0);
|
|
343
345
|
}
|
|
344
346
|
}
|
|
345
|
-
},
|
|
346
|
-
let t = performance.now(), n = t -
|
|
347
|
+
}, je = 0, Me = null, Q, Ne = (e) => {
|
|
348
|
+
let t = performance.now(), n = t - je;
|
|
347
349
|
if (n >= k) {
|
|
348
|
-
|
|
350
|
+
je = t, Me = null, ie?.(e);
|
|
349
351
|
return;
|
|
350
352
|
}
|
|
351
|
-
|
|
353
|
+
Me = e, !Q && (Q = setTimeout(() => {
|
|
352
354
|
Q = void 0;
|
|
353
|
-
let e =
|
|
354
|
-
|
|
355
|
+
let e = Me;
|
|
356
|
+
Me = null, !(e === null || I) && (je = performance.now(), ie?.(e));
|
|
355
357
|
}, k - n));
|
|
356
358
|
};
|
|
357
359
|
F.push(() => {
|
|
358
360
|
Q && clearTimeout(Q);
|
|
359
361
|
});
|
|
360
|
-
let
|
|
362
|
+
let Pe = 0, $;
|
|
361
363
|
F.push(() => {
|
|
362
364
|
$ && clearTimeout($);
|
|
363
365
|
});
|
|
364
|
-
let
|
|
366
|
+
let Fe = () => {
|
|
365
367
|
let t = n.currentTime, r = e.info.input.duration || n.duration;
|
|
366
|
-
r > 0 &&
|
|
367
|
-
let i = performance.now(), a = i -
|
|
368
|
-
if (
|
|
368
|
+
r > 0 && Ne(Math.min(Math.max(t / r, 0), 1));
|
|
369
|
+
let i = performance.now(), a = i - Pe < A;
|
|
370
|
+
if (Pe = i, !De(t) && !(J && (B || Z(t) > 0) && Math.abs(t - _e) < .001)) {
|
|
369
371
|
if (H = !1, $ && clearTimeout($), !a) {
|
|
370
372
|
$ = void 0, X(t);
|
|
371
373
|
return;
|
|
@@ -373,26 +375,26 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
373
375
|
$ = setTimeout(() => {
|
|
374
376
|
if ($ = void 0, I) return;
|
|
375
377
|
let e = n.currentTime;
|
|
376
|
-
|
|
378
|
+
De(e) || (H = !1, X(e));
|
|
377
379
|
}, A);
|
|
378
380
|
}
|
|
379
381
|
};
|
|
380
|
-
n.addEventListener("seeking",
|
|
381
|
-
let
|
|
382
|
-
if (
|
|
383
|
-
|
|
382
|
+
n.addEventListener("seeking", Fe), F.push(() => n.removeEventListener("seeking", Fe));
|
|
383
|
+
let Ie = !1, Le = () => {
|
|
384
|
+
if (Ie) return;
|
|
385
|
+
Ie = !0;
|
|
384
386
|
let e = n.error;
|
|
385
387
|
Y(new _(`the media element failed: ${e?.message ?? "unknown"}`, { cause: e }), !1, !0);
|
|
386
388
|
};
|
|
387
|
-
n.addEventListener("error",
|
|
388
|
-
let
|
|
389
|
-
|
|
389
|
+
n.addEventListener("error", Le), F.push(() => n.removeEventListener("error", Le));
|
|
390
|
+
let Re = setInterval(() => {
|
|
391
|
+
Ie || n.error || (ve().catch(() => {}), Ee().catch((e) => Y(e, !1)), we() && !W && Se() && j.readyState === "open" && fe(() => !B).catch(() => {}));
|
|
390
392
|
}, 100);
|
|
391
|
-
return F.push(() => clearInterval(
|
|
392
|
-
destroy:
|
|
393
|
-
prepareSeek:
|
|
393
|
+
return F.push(() => clearInterval(Re)), {
|
|
394
|
+
destroy: ce,
|
|
395
|
+
prepareSeek: Ae,
|
|
394
396
|
videoElement: n,
|
|
395
|
-
selectSubtitleStream: (e) =>
|
|
397
|
+
selectSubtitleStream: (e) => c.selectStream(e),
|
|
396
398
|
indexes: e.indexes ?? [],
|
|
397
399
|
chapters: e.chapters ?? [],
|
|
398
400
|
duration: e.info.input.duration,
|
|
@@ -400,9 +402,9 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
400
402
|
audioMimeType: e.info.output.audioMimeType
|
|
401
403
|
};
|
|
402
404
|
} catch (e) {
|
|
403
|
-
throw
|
|
405
|
+
throw ce(), e;
|
|
404
406
|
}
|
|
405
|
-
}, te = 5, ne = 500, re = 320, ie = 1e6, ae = 3,
|
|
407
|
+
}, te = 5, ne = 500, re = 320, ie = 1e6, ae = 3, oe = 1e4, N = 1.5, se = 4e6, P = 3e4, F = async (e) => {
|
|
406
408
|
let { publicPath: n, workerUrl: r, length: i, read: a, onThumbnails: o, width: s = re } = e, c = await t({
|
|
407
409
|
publicPath: n,
|
|
408
410
|
workerUrl: r,
|
|
@@ -458,7 +460,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
458
460
|
}), o(e);
|
|
459
461
|
}, x = async (e) => {
|
|
460
462
|
if (d) return;
|
|
461
|
-
let t = await Promise.race([c.readKeyframe(e.timestamp), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")),
|
|
463
|
+
let t = await Promise.race([c.readKeyframe(e.timestamp), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")), oe))]), n = await createImageBitmap(new Blob([t], { type: "image/png" })), r = new OffscreenCanvas(s, Math.max(1, Math.round(n.height * (s / n.width))));
|
|
462
464
|
r.getContext("2d").drawImage(n, 0, 0, r.width, r.height), n.close();
|
|
463
465
|
let i = await r.convertToBlob({
|
|
464
466
|
type: "image/webp",
|
|
@@ -491,7 +493,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
491
493
|
}, w = async (e) => {
|
|
492
494
|
_ = !0;
|
|
493
495
|
try {
|
|
494
|
-
let t = await Promise.race([c.init(), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")),
|
|
496
|
+
let t = await Promise.race([c.init(), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")), P))]);
|
|
495
497
|
if (d) return;
|
|
496
498
|
h = e;
|
|
497
499
|
let n = l(t.indexes);
|
|
@@ -517,7 +519,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
517
519
|
if (d) return;
|
|
518
520
|
v = e;
|
|
519
521
|
let t = T(e);
|
|
520
|
-
h < 0 ? h = t : (t >= Math.max(h *
|
|
522
|
+
h < 0 ? h = t : (t >= Math.max(h * N, h + se) || t >= i && h < i) && (g = !0), E(e), S();
|
|
521
523
|
},
|
|
522
524
|
prioritize: (e) => {
|
|
523
525
|
d || (m = e);
|
|
@@ -531,8 +533,8 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
531
533
|
} catch (e) {
|
|
532
534
|
throw M(c), e;
|
|
533
535
|
}
|
|
534
|
-
},
|
|
535
|
-
let { video: t, subtitles: n } = e, r = e.mode ??
|
|
536
|
+
}, I = 1280, ce = 1920, le = 250, L = 100, R = () => typeof HTMLCanvasElement < "u" && "captureStream" in HTMLCanvasElement.prototype, ue = () => typeof document < "u" && typeof HTMLVideoElement < "u" && typeof HTMLVideoElement.prototype.requestPictureInPicture == "function" && !!document.pictureInPictureEnabled, de = () => typeof HTMLVideoElement < "u" && "mozCaptureStream" in HTMLVideoElement.prototype, fe = () => R() ? ue() ? "window" : de() ? "burn-in" : null : null, z = (e) => {
|
|
537
|
+
let { video: t, subtitles: n } = e, r = e.mode ?? fe() ?? "window", i = e.maxWidth ?? (r === "burn-in" ? ce : I), 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) => {
|
|
536
538
|
r.drawImage(t, 0, 0, e.width, e.height);
|
|
537
539
|
let i = n.querySelector("canvas");
|
|
538
540
|
i && i.width > 0 && i.height > 0 && r.drawImage(i, 0, 0, e.width, e.height);
|
|
@@ -561,11 +563,11 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
561
563
|
l = !0;
|
|
562
564
|
let { mirror: e } = a;
|
|
563
565
|
h(), e.play().then(() => new Promise((e) => {
|
|
564
|
-
setTimeout(e,
|
|
566
|
+
setTimeout(e, L);
|
|
565
567
|
})).catch(() => {}).finally(() => {
|
|
566
568
|
e.pause(), setTimeout(() => {
|
|
567
569
|
l = !1;
|
|
568
|
-
},
|
|
570
|
+
}, L);
|
|
569
571
|
});
|
|
570
572
|
}, E = [["play", () => {
|
|
571
573
|
t.play().catch(() => {});
|
|
@@ -602,7 +604,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
602
604
|
};
|
|
603
605
|
if (a = f, u.srcObject = f.stream, (e.container ?? t.parentElement ?? document.body).appendChild(u), v(), s = setInterval(() => {
|
|
604
606
|
t.paused && h();
|
|
605
|
-
},
|
|
607
|
+
}, le), u.play().catch(() => {}), u.readyState === 0 && await new Promise((e) => {
|
|
606
608
|
let t = () => {
|
|
607
609
|
clearTimeout(n), e();
|
|
608
610
|
}, n = setTimeout(t, 1e3);
|
|
@@ -648,4 +650,4 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
648
650
|
};
|
|
649
651
|
};
|
|
650
652
|
//#endregion
|
|
651
|
-
export { _ as a, M as c, i as d, o as f, j as i, s as l,
|
|
653
|
+
export { _ as a, M as c, i as d, o as f, j as i, s as l, fe as n, v as o, F as r, ee as s, z as t, g as u };
|