@banou/media-player 0.10.27 → 0.10.29
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 +66 -1
- package/dist/chapters/index.d.ts +3 -0
- package/dist/chapters/index.js +2 -0
- package/dist/chapters-EBYXcEml.js +115 -0
- 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.d.ts +1 -1
- package/dist/index.js +875 -916
- package/dist/language/index.d.ts +25 -0
- package/dist/language/index.js +75 -0
- package/dist/react/components/chrome.d.ts +4 -1
- package/dist/react/components/control-bar.d.ts +3 -1
- package/dist/react/components/tooltip-display.d.ts +2 -0
- package/dist/react/video-player.d.ts +44 -0
- package/dist/remote/index.d.ts +27 -1
- package/dist/remote/index.js +163 -139
- package/dist/remote/protocol.d.ts +16 -4
- package/package.json +9 -1
- package/src/lib/chapters/index.ts +5 -0
- package/src/lib/engine/playback.ts +18 -6
- package/src/lib/index.tsx +1 -0
- package/src/lib/language/index.ts +129 -0
- package/src/lib/react/components/chrome.tsx +12 -3
- package/src/lib/react/components/control-bar.tsx +21 -6
- package/src/lib/react/components/tooltip-display.tsx +14 -2
- package/src/lib/react/hooks/use-playback.ts +50 -17
- package/src/lib/react/video-player.tsx +94 -8
- package/src/lib/remote/index.ts +99 -18
- package/src/lib/remote/protocol.ts +16 -5
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
|
|
@@ -205,6 +206,10 @@ ninety seconds in each half of the runtime is the opening and the ending. Nothin
|
|
|
205
206
|
fifteen seconds is ever offered, and a disc that is mostly themes offers nothing, because there the
|
|
206
207
|
themes are what is being watched.
|
|
207
208
|
|
|
209
|
+
The same guess is published on its own, for a page that has to know what a chapter is without loading the player:
|
|
210
|
+
`classifyChapters(chapters)` from `@banou/media-player/chapters`, which imports nothing else of the player, gives
|
|
211
|
+
`'opening'`, `'ending'` or undefined for each chapter.
|
|
212
|
+
|
|
208
213
|
### Picture in picture keeps the subtitles
|
|
209
214
|
|
|
210
215
|
Subtitles are painted by jassub onto a canvas over the video, and picture in picture takes a video
|
|
@@ -253,6 +258,29 @@ A finger never rests on the control before it presses, so a tap cannot arm it. T
|
|
|
253
258
|
only where the primary pointer hovers (`(hover: hover) and (pointer: fine)`), and a touch hides it
|
|
254
259
|
until a pointer that hovers moves again.
|
|
255
260
|
|
|
261
|
+
### Fullscreen kept by the host page
|
|
262
|
+
|
|
263
|
+
A page that fullscreens an element of its own around the player, so that fullscreen outlasts the player in it, passes
|
|
264
|
+
`fullscreen`:
|
|
265
|
+
|
|
266
|
+
```tsx
|
|
267
|
+
<div ref={stage}>
|
|
268
|
+
<MediaPlayer
|
|
269
|
+
{...source}
|
|
270
|
+
fullscreen={{
|
|
271
|
+
active: stageIsFullscreen,
|
|
272
|
+
request: () => document.fullscreenElement ? document.exitFullscreen() : stage.current!.requestFullscreen(),
|
|
273
|
+
}}
|
|
274
|
+
/>
|
|
275
|
+
</div>
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
The player then calls no `requestFullscreen`. The button, `f` and a double click each call `request` once, during the
|
|
279
|
+
press's own event, so the page's `requestFullscreen` has the press's activation, and the button and
|
|
280
|
+
`shortcuts="player"` follow `active`, which the page keeps up to date from its `fullscreenchange`. Without the prop
|
|
281
|
+
the player fullscreens itself. A player in another document hands its fullscreen over through
|
|
282
|
+
[`<MediaPlayer expose>`](#layout), to a mirror that asks for it.
|
|
283
|
+
|
|
256
284
|
### The volume normalizer
|
|
257
285
|
|
|
258
286
|
A "Normalize volume" switch in the settings menu keeps the file's own normal level and turns down what goes well over
|
|
@@ -295,6 +323,31 @@ on the page's next click, tap or key press, and the video plays as it always did
|
|
|
295
323
|
The refusal comes when routing would, once the switch is on and the AudioContext runs: until then the switch reads as
|
|
296
324
|
available, and from then on it reads Unavailable, with the element never routed and playing as it always did.
|
|
297
325
|
|
|
326
|
+
### Preferred languages
|
|
327
|
+
|
|
328
|
+
Pass the languages to start a file in, and save what the viewer picks:
|
|
329
|
+
|
|
330
|
+
```tsx
|
|
331
|
+
<MediaPlayer
|
|
332
|
+
{...source}
|
|
333
|
+
preferredAudioLanguage={saved.audio}
|
|
334
|
+
preferredSubtitleLanguage={saved.subtitles}
|
|
335
|
+
onPreferredAudioLanguageChange={(audio) => save({ ...saved, audio })}
|
|
336
|
+
onPreferredSubtitleLanguageChange={(subtitles) => save({ ...saved, subtitles })}
|
|
337
|
+
/>
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
A preference is a tag or a name (`ja`, `ja-JP`, `jpn`, `Japanese`, `English (US)`), and a pick is reported the way the
|
|
341
|
+
track names its language, its tag or else its title, or null for subtitles off. A file starts on its full track in the
|
|
342
|
+
preferred language, never a commentary or a signs and songs track when a full one exists, and on its default when it has
|
|
343
|
+
nothing in that language. What the viewer picks wins for that file. A subtitle track that names no language is reported
|
|
344
|
+
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
|
|
345
|
+
it has one.
|
|
346
|
+
|
|
347
|
+
A media the player does not own reports picks the same way, by the option's label once the source's `select`
|
|
348
|
+
resolves, and its host applies the preference to its own tracks: `preferredSelection(selection, preference)`, from
|
|
349
|
+
`@banou/media-player/language`, names the option to select, and imports nothing else of the player.
|
|
350
|
+
|
|
298
351
|
## Layout
|
|
299
352
|
|
|
300
353
|
One package. `src/` is the demo app, `src/lib` is the library it publishes, and the app imports it by
|
|
@@ -362,6 +415,18 @@ its published name so it stays an honest consumer.
|
|
|
362
415
|
`emptied` and then the new state, the way an element would. Hand a remote player to a second
|
|
363
416
|
`<MediaPlayer media={player}>` after `ready`. A document served with no frame around it serves
|
|
364
417
|
nobody; `exposePlayer(media)` does the same without React.
|
|
418
|
+
|
|
419
|
+
A `<MediaPlayer expose>` also carries its chapters, as `player.chapters` with a `chapterschange` event after each
|
|
420
|
+
change (a bare element has none), and hands its fullscreen to a mirror made with `fullscreen: true`: the far
|
|
421
|
+
player's button, `f` and double click then fire one `fullscreenrequest` on the mirror each, within the press's
|
|
422
|
+
activation, and show `player.fullscreen` as this page sets it, until `destroy()` gives the fullscreen back.
|
|
423
|
+
|
|
424
|
+
```ts
|
|
425
|
+
const player = mediaPlayer(iframe, { origin, fullscreen: true })
|
|
426
|
+
player.addEventListener('fullscreenrequest', () => document.fullscreenElement ? document.exitFullscreen() : stage.requestFullscreen())
|
|
427
|
+
document.addEventListener('fullscreenchange', () => { player.fullscreen = !!document.fullscreenElement })
|
|
428
|
+
player.addEventListener('chapterschange', () => console.log(player.chapters))
|
|
429
|
+
```
|
|
365
430
|
- `src/lib/react/` the player component, its chrome, and the hooks.
|
|
366
431
|
|
|
367
432
|
Built by `vite.lib.config.ts` into `dist/`, which is what npm publishes.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
//#region src/lib/utils/chapters.ts
|
|
2
|
+
var e = "#0000", t = (e, t) => {
|
|
3
|
+
if (!t) return [];
|
|
4
|
+
let n = /* @__PURE__ */ new Set();
|
|
5
|
+
for (let { start: r, end: i } of e) for (let e of [r, i]) {
|
|
6
|
+
let r = e / t;
|
|
7
|
+
r <= .005 || r >= .995 || n.add(Number((r * 100).toFixed(4)));
|
|
8
|
+
}
|
|
9
|
+
return n.size ? [
|
|
10
|
+
0,
|
|
11
|
+
...[...n].sort((e, t) => e - t),
|
|
12
|
+
100
|
|
13
|
+
] : [];
|
|
14
|
+
}, n = (t, n) => {
|
|
15
|
+
let r = t.length - 2, i = [];
|
|
16
|
+
for (let a = 0; a <= r; a += 1) {
|
|
17
|
+
let o = t[a], s = t[a + 1], c = a === 0 ? "0%" : `calc(${o}% + 1px)`, l = a === r ? "100%" : `calc(${s}% - 1px)`;
|
|
18
|
+
i.push(`${n(a) ? "#000" : e} ${c} ${l}`), a !== r && i.push(`${e} calc(${s}% - 1px) calc(${s}% + 1px)`);
|
|
19
|
+
}
|
|
20
|
+
return `linear-gradient(90deg, ${i.join(", ")})`;
|
|
21
|
+
}, r = /* @__PURE__ */ new Set([
|
|
22
|
+
"op",
|
|
23
|
+
"ops",
|
|
24
|
+
"opening",
|
|
25
|
+
"openings",
|
|
26
|
+
"ncop",
|
|
27
|
+
"オープニング",
|
|
28
|
+
"op主題歌"
|
|
29
|
+
]), i = /* @__PURE__ */ new Set([
|
|
30
|
+
"ed",
|
|
31
|
+
"eds",
|
|
32
|
+
"ending",
|
|
33
|
+
"endings",
|
|
34
|
+
"nced",
|
|
35
|
+
"credits",
|
|
36
|
+
"endcard",
|
|
37
|
+
"endroll",
|
|
38
|
+
"エンディング",
|
|
39
|
+
"エンドカード",
|
|
40
|
+
"エンドロール",
|
|
41
|
+
"ed主題歌"
|
|
42
|
+
]), a = /* @__PURE__ */ new Set(["intro", "イントロ"]), o = /* @__PURE__ */ new Set(["outro", "アウトロ"]), s = {
|
|
43
|
+
"credits start": "ending",
|
|
44
|
+
"credits end": null,
|
|
45
|
+
"preview end": null,
|
|
46
|
+
"end credits": "ending",
|
|
47
|
+
"closing credits": "ending"
|
|
48
|
+
}, c = /* @__PURE__ */ new Set([
|
|
49
|
+
"theme",
|
|
50
|
+
"themes",
|
|
51
|
+
"song",
|
|
52
|
+
"sequence",
|
|
53
|
+
"nc",
|
|
54
|
+
"non",
|
|
55
|
+
"credit",
|
|
56
|
+
"creditless",
|
|
57
|
+
"textless",
|
|
58
|
+
"clean",
|
|
59
|
+
"tv",
|
|
60
|
+
"size",
|
|
61
|
+
"version",
|
|
62
|
+
"ver",
|
|
63
|
+
"full",
|
|
64
|
+
"the",
|
|
65
|
+
"主題歌",
|
|
66
|
+
"ノンクレジット"
|
|
67
|
+
]), l = /* @__PURE__ */ new Set([
|
|
68
|
+
"post",
|
|
69
|
+
"pre",
|
|
70
|
+
"after",
|
|
71
|
+
"before",
|
|
72
|
+
"non"
|
|
73
|
+
]), u = /[-:|~/\\[\]()「」『』【】,.!?"'’]|\s+by\s+/u, d = (e) => !e.trim() || /^chapter\s*\d+$/i.test(e.trim()) || /^\d{1,2}:\d{2}:\d{2}([.,]\d+)?$/.test(e.trim()), f = (e) => e.replace(/([a-z-ヿ一-鿿])\s*\d+\s*$/u, "$1").split(/[\s_]+/u).map((e) => e.replace(/^[^\w-ヿ一-鿿]+|[^\w-ヿ一-鿿]+$/gu, "")).filter((e) => e && !/^\d+$/.test(e) && !c.has(e)), p = (e, t) => {
|
|
74
|
+
if (r.has(e)) return "opening";
|
|
75
|
+
if (i.has(e)) return "ending";
|
|
76
|
+
if (t) {
|
|
77
|
+
if (a.has(e)) return "opening";
|
|
78
|
+
if (o.has(e)) return "ending";
|
|
79
|
+
}
|
|
80
|
+
}, m = (e, t) => {
|
|
81
|
+
if (d(e)) return;
|
|
82
|
+
let n = e.trim().toLowerCase().replace(/\s+/gu, " ");
|
|
83
|
+
if (n in s) return s[n] ?? void 0;
|
|
84
|
+
let r = n.split(u).map((e) => e.trim()).filter(Boolean);
|
|
85
|
+
if (r.some((e) => e.split(/[\s_]+/u).some((e) => l.has(e)))) return;
|
|
86
|
+
let i = r.length > 1 ? [r[0], r.at(-1)] : r;
|
|
87
|
+
for (let e of i) {
|
|
88
|
+
let n = f(e);
|
|
89
|
+
if (n.length !== 1) continue;
|
|
90
|
+
let r = p(n[0], t);
|
|
91
|
+
if (r) return r;
|
|
92
|
+
}
|
|
93
|
+
}, h = 15, g = 87, _ = 93, v = (e) => {
|
|
94
|
+
let t = e.map(() => void 0), n = e.at(-1)?.end ?? 0;
|
|
95
|
+
if (!n) return t;
|
|
96
|
+
let r = e.map((e, t) => ({
|
|
97
|
+
index: t,
|
|
98
|
+
start: e.start,
|
|
99
|
+
length: e.end - e.start
|
|
100
|
+
})).filter(({ length: e }) => e >= g && e <= _), i = n / 2, a = r.filter(({ start: e }) => e < i), o = r.filter(({ start: e }) => e >= i);
|
|
101
|
+
return a.length === 1 && (t[a[0].index] = "opening"), o.length === 1 && (t[o[0].index] = "ending"), t;
|
|
102
|
+
}, y = (e) => {
|
|
103
|
+
let t = e.map(({ title: e }) => m(e, !1)), n = e.reduce((e, n, r) => e + (t[r] ? n.end - n.start : 0), 0), r = e.reduce((e, t) => e + (t.end - t.start), 0);
|
|
104
|
+
if (r > 0 && n * 2 > r) return e.map(() => void 0);
|
|
105
|
+
let i = e.map((e, n) => {
|
|
106
|
+
if (e.end - e.start < h) return;
|
|
107
|
+
let r = t[n];
|
|
108
|
+
if (r) return r;
|
|
109
|
+
let i = m(e.title, !0);
|
|
110
|
+
return i && !t.includes(i) ? i : void 0;
|
|
111
|
+
});
|
|
112
|
+
return e.every(({ title: e }) => d(e)) ? v(e) : i;
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
export { t as n, n as r, y as t };
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { MediaPlayer, default } from './react/video-player';
|
|
2
|
-
export type { MediaPlayerOptions, MediaPlayerLocalOptions, MediaPlayerRemoteOptions, MediaPlayerSource, } from './react/video-player';
|
|
2
|
+
export type { HostFullscreen, MediaPlayerOptions, MediaPlayerLocalOptions, MediaPlayerRemoteOptions, MediaPlayerSource, } from './react/video-player';
|
|
3
3
|
export { isDelegatedTracks, isExternalThumbnails } from './react/media';
|
|
4
4
|
export type { DelegatedSelection, DelegatedTracks, ExternalThumbnails, PassThroughPictureInPicture, PlayerMedia, TimeRangesLike, } from './react/media';
|
|
5
5
|
export { Player, usePlayer } from './react/player';
|