@banou/media-player 0.10.25 → 0.10.26
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 +7 -0
- package/dist/engine/index.js +1 -1
- package/dist/engine/playback.d.ts +1 -0
- package/dist/engine/subtitles.d.ts +8 -0
- package/dist/{engine-BdouHadr.js → engine-AjFLuCdA.js} +190 -185
- package/dist/index.js +53 -51
- package/dist/react/video-player.d.ts +2 -0
- package/package.json +2 -1
- package/src/lib/assets/noto-sans-jp.LICENSE.txt +92 -0
- package/src/lib/assets/noto-sans-jp.otf +0 -0
- package/src/lib/engine/playback.ts +3 -1
- package/src/lib/engine/subtitles.ts +34 -1
- package/src/lib/react/hooks/use-playback.ts +3 -2
- package/src/lib/react/video-player.tsx +2 -0
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ import MediaPlayer from '@banou/media-player'
|
|
|
25
25
|
jassubWasmUrl={jassubWasmUrl}
|
|
26
26
|
jassubLegacyWasmUrl={jassubLegacyWasmUrl}
|
|
27
27
|
defaultFontUrl={defaultFontUrl}
|
|
28
|
+
cjkFontUrl={cjkFontUrl}
|
|
28
29
|
title="episode.mkv"
|
|
29
30
|
autoplay
|
|
30
31
|
/>
|
|
@@ -93,6 +94,12 @@ reads as a browser bug rather than a missing asset. Serve both.
|
|
|
93
94
|
|
|
94
95
|
`libavWorkerUrl` (`libav-wasm/build/worker.js`) is named individually and still copies fine.
|
|
95
96
|
|
|
97
|
+
`cjkFontUrl` is this package's own `noto-sans-jp.otf` (`import cjkFontUrl from
|
|
98
|
+
'@banou/media-player/noto-sans-jp.otf?no-inline&url'`), Noto Sans JP cut to the JIS X 0208 kanji. jassub's libass has no
|
|
99
|
+
system font fallback, so without it Japanese in a style whose font has no Japanese, which is how releases set song
|
|
100
|
+
lyrics, draws as empty boxes. It is fetched only once the selected track shows CJK text, after `defaultFontUrl`,
|
|
101
|
+
and draws only the glyphs that face lacks.
|
|
102
|
+
|
|
96
103
|
`normalizerWorkletUrl` is this package's own `dist/volume-normalizer-worklet.js`, one plain module with no imports
|
|
97
104
|
that copies fine or imports as a url; see [the volume normalizer](#the-volume-normalizer).
|
|
98
105
|
|
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-AjFLuCdA.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 };
|
|
@@ -61,6 +61,7 @@ export type PlaybackOptions = {
|
|
|
61
61
|
/** jassub's non-SIMD build; without it subtitles fail rather than degrade on Safari before 16.4 */
|
|
62
62
|
jassubLegacyWasmUrl?: string;
|
|
63
63
|
defaultFontUrl?: string;
|
|
64
|
+
cjkFontUrl?: string;
|
|
64
65
|
bufferSize?: number;
|
|
65
66
|
audioStreamIndex?: number;
|
|
66
67
|
onReady?: () => void;
|
|
@@ -38,6 +38,14 @@ export type SubtitleRendererOptions = {
|
|
|
38
38
|
* given on `workerFetched`.
|
|
39
39
|
*/
|
|
40
40
|
defaultFontUrl?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Noto Sans JP, `@banou/media-player/noto-sans-jp.otf`, for Japanese text the file's own fonts cannot draw.
|
|
43
|
+
*
|
|
44
|
+
* Fetched only once a line on the selected track holds CJK text, after `defaultFontUrl`. It draws only the
|
|
45
|
+
* glyphs `liberation sans` lacks, so a url that fails to load leaves those as boxes and changes nothing
|
|
46
|
+
* else. May be relative, as `defaultFontUrl`.
|
|
47
|
+
*/
|
|
48
|
+
cjkFontUrl?: string;
|
|
41
49
|
onStreams?: (streams: SubtitleStream[]) => void;
|
|
42
50
|
};
|
|
43
51
|
export type SubtitleRenderer = ReturnType<typeof createSubtitleRenderer>;
|
|
@@ -32,19 +32,19 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
32
32
|
} catch {}
|
|
33
33
|
})
|
|
34
34
|
};
|
|
35
|
-
}, s = -1, c = (e) => e === void 0 ? void 0 : new URL(e, document.baseURI).toString(), l = (e) => new Date(e).toISOString().slice(11, 22), u = 1,
|
|
35
|
+
}, s = -1, c = (e) => e === void 0 ? void 0 : new URL(e, document.baseURI).toString(), l = (e) => new Date(e).toISOString().slice(11, 22), u = /[\u3000-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff00-\uffef]/, d = 1, f = (e) => new Map(r(e).styles.style.map((e, t) => [e.Name, t + d])), p = (e, t) => {
|
|
36
36
|
let n = t.replace(/^\*+/, ""), r = n.toLowerCase() === "default" ? "Default" : n;
|
|
37
37
|
return e.styles.get(r) ?? e.styles.get("Default") ?? 0;
|
|
38
|
-
},
|
|
38
|
+
}, m = (e) => {
|
|
39
39
|
let t = e.content.match(/\r?\n\[Events\]\r?\nFormat: (.*)/)?.[0];
|
|
40
40
|
return t ? {
|
|
41
41
|
type: "header",
|
|
42
42
|
streamIndex: e.streamIndex,
|
|
43
43
|
content: e.content,
|
|
44
44
|
eventsContent: t,
|
|
45
|
-
styles:
|
|
45
|
+
styles: f(e.content)
|
|
46
46
|
} : (console.warn(`subtitle stream ${e.streamIndex} has no Events format, ignoring the track`), null);
|
|
47
|
-
},
|
|
47
|
+
}, h = (e, t) => {
|
|
48
48
|
let [n, i] = t.content.split(","), a = Number(n), o = `Dialogue: ${i},${l(t.start)},${l(t.end)},${t.content.replace(`${a},${i},`, "")}`, s = r(`${e.eventsContent}\r\n${o}`).events.dialogue[0];
|
|
49
49
|
if (!s) throw Error("dialogue event is undefined");
|
|
50
50
|
return {
|
|
@@ -57,334 +57,339 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
57
57
|
MarginL: s.MarginL,
|
|
58
58
|
MarginR: s.MarginR,
|
|
59
59
|
MarginV: s.MarginV,
|
|
60
|
-
Style:
|
|
60
|
+
Style: p(e, s.Style),
|
|
61
61
|
Text: s.Text.raw,
|
|
62
62
|
Start: s.Start * 1e3,
|
|
63
63
|
Duration: (s.End - s.Start) * 1e3,
|
|
64
64
|
ReadOrder: a
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
-
},
|
|
68
|
-
let { video: t, container: r, workerUrl: i } = e, a = c(e.wasmUrl), o = c(e.legacyWasmUrl), s = c(e.defaultFontUrl), l,
|
|
67
|
+
}, g = (e) => {
|
|
68
|
+
let { video: t, container: r, workerUrl: i } = e, a = c(e.wasmUrl), o = c(e.legacyWasmUrl), s = c(e.defaultFontUrl), l = c(e.cjkFontUrl), d = !1, f = Promise.resolve(), p, g = [], _ = /* @__PURE__ */ new Map(), v = [], y = /* @__PURE__ */ new Map(), b, x = e.onStreams, S = !1, C = (e) => {
|
|
69
69
|
console.warn("the subtitle renderer failed; the file plays without subtitles", e);
|
|
70
|
-
},
|
|
71
|
-
let t =
|
|
72
|
-
t && t.ready.then(() =>
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
let e =
|
|
70
|
+
}, w = (e) => {
|
|
71
|
+
let t = p;
|
|
72
|
+
t && t.ready.then(() => p === t ? e(t.renderer) : void 0).catch(C);
|
|
73
|
+
}, T = !1, E = () => {
|
|
74
|
+
T || (T = !0, queueMicrotask(() => {
|
|
75
|
+
T = !1;
|
|
76
|
+
let e = p;
|
|
77
77
|
e && t.videoWidth && e.ready.then(() => {
|
|
78
|
-
if (
|
|
78
|
+
if (p === e) return e.manualRender({
|
|
79
79
|
expectedDisplayTime: performance.now(),
|
|
80
80
|
width: t.videoWidth,
|
|
81
81
|
height: t.videoHeight,
|
|
82
82
|
mediaTime: t.currentTime
|
|
83
83
|
}, !0);
|
|
84
|
-
}).catch(
|
|
84
|
+
}).catch(C);
|
|
85
85
|
}));
|
|
86
|
-
},
|
|
86
|
+
}, D = [
|
|
87
87
|
"loadedmetadata",
|
|
88
88
|
"seeked",
|
|
89
89
|
"pause"
|
|
90
|
-
],
|
|
90
|
+
], O = () => E(), k = (e) => {
|
|
91
91
|
let c = document.createElement("canvas");
|
|
92
92
|
r.append(c);
|
|
93
93
|
try {
|
|
94
|
-
|
|
94
|
+
p = new n({
|
|
95
95
|
video: t,
|
|
96
96
|
canvas: c,
|
|
97
97
|
subContent: e.content,
|
|
98
98
|
workerUrl: i,
|
|
99
99
|
modernWasmUrl: a,
|
|
100
100
|
...o ? { wasmUrl: o } : {},
|
|
101
|
-
fonts:
|
|
101
|
+
fonts: g.map(([, e]) => e),
|
|
102
102
|
availableFonts: {
|
|
103
|
-
...Object.fromEntries(
|
|
103
|
+
...Object.fromEntries(g),
|
|
104
104
|
...s ? { "liberation sans": s } : {}
|
|
105
105
|
},
|
|
106
106
|
queryFonts: !1
|
|
107
107
|
});
|
|
108
108
|
} catch (e) {
|
|
109
|
-
c.remove(),
|
|
109
|
+
c.remove(), C(e);
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
for (let e of
|
|
114
|
-
s &&
|
|
115
|
-
Promise.resolve(e.addFonts([s])).then(
|
|
116
|
-
}),
|
|
112
|
+
p.ready.catch(C);
|
|
113
|
+
for (let e of D) t.addEventListener(e, O);
|
|
114
|
+
s && w((e) => {
|
|
115
|
+
f = Promise.resolve(e.addFonts([s])).then(E, C);
|
|
116
|
+
}), E();
|
|
117
|
+
}, A = (e) => {
|
|
118
|
+
l && !d && e.some((e) => u.test(e.Text)) && (d = !0, w(async (e) => {
|
|
119
|
+
await f, await e.addFonts([l]), E();
|
|
120
|
+
}));
|
|
117
121
|
};
|
|
118
122
|
return {
|
|
119
123
|
pushAttachments: (e) => {
|
|
120
|
-
|
|
124
|
+
g = [...g, ...e.map((e) => [e.filename, new Uint8Array(e.data)])];
|
|
121
125
|
},
|
|
122
126
|
pushFragments: (e) => {
|
|
123
127
|
let t = [];
|
|
124
128
|
for (let n of e) if (n.type === "header") {
|
|
125
|
-
if (
|
|
126
|
-
let e =
|
|
129
|
+
if (_.has(n.streamIndex)) continue;
|
|
130
|
+
let e = m(n);
|
|
127
131
|
if (!e) continue;
|
|
128
|
-
|
|
132
|
+
_.set(n.streamIndex, e), v.push({
|
|
129
133
|
streamIndex: n.streamIndex,
|
|
130
134
|
title: n.title,
|
|
131
135
|
language: n.language
|
|
132
|
-
}),
|
|
136
|
+
}), x?.([...v]), b === void 0 && (b = n.streamIndex), !p && !S && k(e);
|
|
133
137
|
} else {
|
|
134
|
-
let e =
|
|
138
|
+
let e = _.get(n.streamIndex);
|
|
135
139
|
if (!e) continue;
|
|
136
|
-
let r =
|
|
137
|
-
r || (r = /* @__PURE__ */ new Map(),
|
|
140
|
+
let r = y.get(n.streamIndex);
|
|
141
|
+
r || (r = /* @__PURE__ */ new Map(), y.set(n.streamIndex, r));
|
|
138
142
|
let i = `${n.start},${n.end},${n.content.slice(n.content.indexOf(",") + 1)}`;
|
|
139
143
|
if (r.has(i)) continue;
|
|
140
|
-
let a =
|
|
141
|
-
r.set(i, a),
|
|
144
|
+
let a = h(e, n);
|
|
145
|
+
r.set(i, a), b === n.streamIndex && t.push(a.assEvent);
|
|
142
146
|
}
|
|
143
|
-
t.length && (
|
|
147
|
+
t.length && (w((e) => Promise.all(t.map((t) => e.createEvent(t)))), A(t), E());
|
|
144
148
|
},
|
|
145
149
|
selectStream: (e) => {
|
|
146
150
|
let t = e ?? -1;
|
|
147
|
-
if (t ===
|
|
148
|
-
|
|
149
|
-
let n =
|
|
150
|
-
|
|
151
|
+
if (t === b || !p) return;
|
|
152
|
+
b = t;
|
|
153
|
+
let n = _.get(t), r = [...y.get(t)?.values() ?? []].map((e) => e.assEvent);
|
|
154
|
+
w((e) => {
|
|
151
155
|
let t = [e.freeTrack()];
|
|
152
156
|
if (n) {
|
|
153
157
|
t.push(e.setTrack(n.content));
|
|
154
158
|
for (let n of r) t.push(e.createEvent(n));
|
|
155
159
|
}
|
|
156
160
|
return Promise.all(t);
|
|
157
|
-
}),
|
|
161
|
+
}), A(r), E();
|
|
158
162
|
},
|
|
159
|
-
getStreams: () => [...
|
|
160
|
-
getSelectedStream: () =>
|
|
163
|
+
getStreams: () => [...v],
|
|
164
|
+
getSelectedStream: () => b,
|
|
161
165
|
setOnStreams: (e) => {
|
|
162
|
-
|
|
166
|
+
x = e;
|
|
163
167
|
},
|
|
164
168
|
destroy: () => {
|
|
165
|
-
|
|
166
|
-
let e =
|
|
167
|
-
|
|
168
|
-
for (let e of
|
|
169
|
+
S = !0;
|
|
170
|
+
let e = p;
|
|
171
|
+
p = void 0;
|
|
172
|
+
for (let e of D) t.removeEventListener(e, O);
|
|
169
173
|
e?.destroy().catch(() => {});
|
|
170
174
|
}
|
|
171
175
|
};
|
|
172
|
-
},
|
|
176
|
+
}, _ = class extends Error {
|
|
173
177
|
mediaElement = !0;
|
|
174
178
|
constructor(e, t) {
|
|
175
179
|
super(e, t), this.name = "MediaElementError";
|
|
176
180
|
}
|
|
177
|
-
},
|
|
181
|
+
}, v = (e) => !!e && typeof e == "object" && e.mediaElement === !0, y = -20, b = 60, x = 30, S = -5, C = 20, w = 5, T = 15e3, E = 1, D = 3, O = 12, k = 200, A = 250, j = 25e5, M = (e) => {
|
|
178
182
|
let { worker: t } = e, n = setTimeout(() => t.terminate(), 2e3);
|
|
179
183
|
e.destroy().catch(() => {}).finally(() => {
|
|
180
184
|
clearTimeout(n), t.terminate();
|
|
181
185
|
});
|
|
182
|
-
},
|
|
183
|
-
let { videoElement: n, subtitleContainer: r, read: a, length: s, publicPath: c, libavWorkerUrl: l, jassubWorkerUrl: u, jassubWasmUrl: d, jassubLegacyWasmUrl: f, defaultFontUrl: p,
|
|
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, onReady: ee, onError: te, onRecovered: ne, onSeek: re, onSubtitleStreams: ie, onAudioStreams: ae, onOutput: N } = t, P = await e({
|
|
184
188
|
publicPath: c,
|
|
185
189
|
workerUrl: l,
|
|
186
190
|
workerOptions: { type: "module" },
|
|
187
|
-
bufferSize:
|
|
191
|
+
bufferSize: h,
|
|
188
192
|
length: s,
|
|
189
|
-
audioStreamIndex:
|
|
193
|
+
audioStreamIndex: v,
|
|
190
194
|
read: a
|
|
191
|
-
}),
|
|
192
|
-
if (!
|
|
193
|
-
|
|
194
|
-
for (let e of [...
|
|
195
|
+
}), F = [], I = !1, oe = () => {
|
|
196
|
+
if (!I) {
|
|
197
|
+
I = !0;
|
|
198
|
+
for (let e of [...F].reverse()) try {
|
|
195
199
|
e();
|
|
196
200
|
} catch {}
|
|
197
201
|
}
|
|
198
202
|
};
|
|
199
|
-
|
|
203
|
+
F.push(() => M(P));
|
|
200
204
|
try {
|
|
201
|
-
let e = await
|
|
202
|
-
|
|
203
|
-
let s =
|
|
205
|
+
let e = await P.init(), t = e.audioStreams ?? [], a = t.some((e) => e.streamIndex === v) ? v : t[0]?.streamIndex ?? -1;
|
|
206
|
+
ae?.(t, a);
|
|
207
|
+
let s = g({
|
|
204
208
|
video: n,
|
|
205
209
|
container: r,
|
|
206
210
|
workerUrl: u,
|
|
207
211
|
wasmUrl: d,
|
|
208
212
|
legacyWasmUrl: f,
|
|
209
213
|
defaultFontUrl: p,
|
|
210
|
-
|
|
214
|
+
cjkFontUrl: m,
|
|
215
|
+
onStreams: ie
|
|
211
216
|
});
|
|
212
|
-
if (
|
|
217
|
+
if (F.push(() => s.destroy()), e.attachments?.length && s.pushAttachments(e.attachments), !e.info.output.videoMimeType) throw Error("The video codec in this file could not be identified");
|
|
213
218
|
let c = [e.info.output.videoMimeType, e.info.output.audioMimeType].filter(Boolean).join(","), l = `video/mp4; codecs="${c}"`;
|
|
214
219
|
if (!MediaSource.isTypeSupported(l)) throw Error(`This browser cannot play the codecs in this file: ${c}`);
|
|
215
|
-
let
|
|
216
|
-
|
|
220
|
+
let h = new MediaSource(), j = URL.createObjectURL(h);
|
|
221
|
+
F.push(() => URL.revokeObjectURL(j)), n.src = j, F.push(() => {
|
|
217
222
|
try {
|
|
218
223
|
n.pause();
|
|
219
224
|
} catch {}
|
|
220
225
|
n.removeAttribute("src"), n.load();
|
|
221
226
|
});
|
|
222
|
-
let
|
|
227
|
+
let M = await new Promise((t, n) => {
|
|
223
228
|
let r = setTimeout(() => {
|
|
224
229
|
i(), n(/* @__PURE__ */ Error("The MediaSource never opened"));
|
|
225
|
-
},
|
|
226
|
-
clearTimeout(r),
|
|
230
|
+
}, T), i = () => {
|
|
231
|
+
clearTimeout(r), h.removeEventListener("sourceopen", a), h.removeEventListener("sourceclose", o), h.removeEventListener("error", o);
|
|
227
232
|
}, a = () => {
|
|
228
233
|
try {
|
|
229
|
-
let n =
|
|
234
|
+
let n = h.addSourceBuffer(l);
|
|
230
235
|
n.mode = "segments";
|
|
231
236
|
let r = e.info.input.duration;
|
|
232
|
-
Number.isFinite(r) && r > 0 && (
|
|
237
|
+
Number.isFinite(r) && r > 0 && (h.duration = r), i(), t(n);
|
|
233
238
|
} catch (e) {
|
|
234
239
|
i(), n(e);
|
|
235
240
|
}
|
|
236
241
|
}, o = () => {
|
|
237
242
|
i(), n(/* @__PURE__ */ Error("The MediaSource closed before a SourceBuffer could be created"));
|
|
238
243
|
};
|
|
239
|
-
|
|
240
|
-
}), { appendBuffer:
|
|
241
|
-
await
|
|
244
|
+
h.addEventListener("sourceopen", a, { once: !0 }), h.addEventListener("sourceclose", o, { once: !0 }), h.addEventListener("error", o, { once: !0 });
|
|
245
|
+
}), { appendBuffer: L, unbufferRange: se, updateTimestampOffset: ce, endOfStream: le } = o(M, h);
|
|
246
|
+
await L(e.data), N?.({
|
|
242
247
|
type: "init",
|
|
243
248
|
data: e.data,
|
|
244
249
|
audioMimeType: e.info.output.audioMimeType,
|
|
245
250
|
audioStreamIndex: a
|
|
246
|
-
}),
|
|
251
|
+
}), N?.({
|
|
247
252
|
type: "run",
|
|
248
253
|
pts: 0
|
|
249
|
-
}), e.subtitles?.length && s.pushFragments(e.subtitles),
|
|
250
|
-
let
|
|
254
|
+
}), e.subtitles?.length && s.pushFragments(e.subtitles), ee?.();
|
|
255
|
+
let R = !1, z = !1, B = 0, V, ue = () => V ?? n.currentTime, H = !1, de = !1, fe = 0, U = 0, W = null, G = 0, K = 0, q = !1, pe = 0, J = !0, Y = (e, t, n = !1) => {
|
|
251
256
|
let r = e?.message === "Cancelled";
|
|
252
|
-
t && r || (console.error(e), (!
|
|
257
|
+
t && r || (console.error(e), (!q || n) && (q = !0, te?.(r ? Error("Reading the video file failed", { cause: e }) : e)));
|
|
253
258
|
}, me = async (e = !1) => {
|
|
254
|
-
if (
|
|
255
|
-
let t = n.currentTime, r = e ?
|
|
259
|
+
if (B > 0 && !e) return;
|
|
260
|
+
let t = n.currentTime, r = e ? S : y, a = e ? C : b, o = i(M), s = (e, t) => (J = !1, se(e, t));
|
|
256
261
|
o.length && o[0].start < t + r && await s(0, t + r);
|
|
257
262
|
for (let { end: e } of o) e > t + a && await s(t + a, e);
|
|
258
263
|
}, he = () => {
|
|
259
|
-
let e = i(
|
|
264
|
+
let e = i(M);
|
|
260
265
|
if (!e.length) return !0;
|
|
261
|
-
let t =
|
|
262
|
-
return be() && ve(t) && (!n || n.start <= t) || n && n.end >= t +
|
|
263
|
-
}, ge = (e) => i(
|
|
266
|
+
let t = ue(), n = e.find((e) => e.start <= t + E && t < e.end);
|
|
267
|
+
return be() && ve(t) && (!n || n.start <= t) || n && n.end >= t + b ? !1 : !n || n.end < t + x;
|
|
268
|
+
}, ge = (e) => i(M).find((t) => t.start <= e + E && e < t.end), _e = () => ge(n.currentTime), ve = (e = n.currentTime) => {
|
|
264
269
|
let t = ge(e);
|
|
265
|
-
return e >=
|
|
270
|
+
return e >= K - .1 || !!t && t.end >= K - .1;
|
|
266
271
|
}, ye = () => {
|
|
267
|
-
let e = i(
|
|
268
|
-
e.length && (
|
|
269
|
-
}, be = () =>
|
|
270
|
-
|
|
271
|
-
let t = ++
|
|
272
|
+
let e = i(M).map((e) => e.end);
|
|
273
|
+
e.length && (K = Math.max(K, ...e)), H && (de = !0);
|
|
274
|
+
}, be = () => H || de && (i(M).at(-1)?.end ?? 0) >= K - .1, X = async (e) => {
|
|
275
|
+
z = !0, W = null, G = 0, pe = e, J = !0;
|
|
276
|
+
let t = ++U;
|
|
272
277
|
try {
|
|
273
|
-
let { data: n, pts: r, subtitles: i, finished: a } = await
|
|
274
|
-
if (
|
|
275
|
-
|
|
278
|
+
let { data: n, pts: r, subtitles: i, finished: a } = await P.seek(e);
|
|
279
|
+
if (I || t !== U || (a && (H = !0), i?.length && s.pushFragments(i), await ce(r), I || t !== U)) return;
|
|
280
|
+
N?.({
|
|
276
281
|
type: "run",
|
|
277
282
|
pts: r
|
|
278
|
-
}), n.byteLength &&
|
|
283
|
+
}), n.byteLength && N?.({
|
|
279
284
|
type: "fragment",
|
|
280
285
|
data: n
|
|
281
|
-
}), a &&
|
|
286
|
+
}), a && N?.({ type: "end" }), n.byteLength && (await L(n), ye());
|
|
282
287
|
} catch (e) {
|
|
283
|
-
t ===
|
|
288
|
+
t === U && (J = !1), Y(e, I || t !== U);
|
|
284
289
|
} finally {
|
|
285
|
-
t ===
|
|
290
|
+
t === U && (z = !1);
|
|
286
291
|
}
|
|
287
292
|
}, xe = async () => {
|
|
288
|
-
let e =
|
|
293
|
+
let e = W;
|
|
289
294
|
if (e) try {
|
|
290
|
-
await
|
|
295
|
+
await L(e), ye(), W === e && (W = null, G = 0);
|
|
291
296
|
} catch (t) {
|
|
292
|
-
if (
|
|
297
|
+
if (W !== e) return;
|
|
293
298
|
if (t?.name === "QuotaExceededError") {
|
|
294
299
|
let t = await me(!0).then(() => !0, () => !1);
|
|
295
|
-
if (
|
|
300
|
+
if (W !== e) return;
|
|
296
301
|
if (t) {
|
|
297
|
-
|
|
302
|
+
H = !1, await X(_e()?.end ?? n.currentTime);
|
|
298
303
|
return;
|
|
299
304
|
}
|
|
300
305
|
}
|
|
301
|
-
if (
|
|
302
|
-
throw
|
|
306
|
+
if (G += 1, G < w) return;
|
|
307
|
+
throw W = null, t;
|
|
303
308
|
}
|
|
304
309
|
}, Se = async () => {
|
|
305
|
-
if (
|
|
306
|
-
let e = ++
|
|
307
|
-
|
|
310
|
+
if (R || z || $ !== void 0 || I || !W && (H || !he())) return;
|
|
311
|
+
let e = ++fe, t = U, n = () => I || e !== fe || t !== U;
|
|
312
|
+
R = !0;
|
|
308
313
|
try {
|
|
309
|
-
if (!
|
|
310
|
-
let { data: e, subtitles: t, finished: r } = await
|
|
311
|
-
if (n() || (r && (
|
|
314
|
+
if (!W) {
|
|
315
|
+
let { data: e, subtitles: t, finished: r } = await P.read();
|
|
316
|
+
if (n() || (r && (H = !0), t?.length && s.pushFragments(t), e.byteLength && N?.({
|
|
312
317
|
type: "fragment",
|
|
313
318
|
data: e
|
|
314
|
-
}), r &&
|
|
315
|
-
|
|
319
|
+
}), r && N?.({ type: "end" }), !e.byteLength)) return;
|
|
320
|
+
W = e, G = 0;
|
|
316
321
|
}
|
|
317
|
-
await xe(), !n() &&
|
|
322
|
+
await xe(), !n() && q && (q = !1, ne?.());
|
|
318
323
|
} catch (e) {
|
|
319
|
-
|
|
324
|
+
Y(e, n());
|
|
320
325
|
} finally {
|
|
321
|
-
e ===
|
|
326
|
+
e === fe && (R = !1);
|
|
322
327
|
}
|
|
323
|
-
}, Ce = (e) => i(
|
|
328
|
+
}, Ce = (e) => i(M).some((t) => t.start <= e && e < t.end && t.end >= pe) && Te(e), we = (e) => i(M).some((t) => t.start <= e && e < t.end), Z = (e) => {
|
|
324
329
|
let t = ge(e);
|
|
325
330
|
return t ? t.end - e : 0;
|
|
326
|
-
}, Te = (e) =>
|
|
327
|
-
if (!
|
|
328
|
-
$ && clearTimeout($), $ = void 0,
|
|
331
|
+
}, Te = (e) => Z(e) >= D || be() && ve(e), Ee = async (e) => {
|
|
332
|
+
if (!I && !(we(e) && Te(e))) {
|
|
333
|
+
$ && clearTimeout($), $ = void 0, H = !1, B++, V = e;
|
|
329
334
|
try {
|
|
330
|
-
await
|
|
331
|
-
let t =
|
|
332
|
-
for (let n = 0; n <
|
|
333
|
-
let t =
|
|
334
|
-
if (await Se(),
|
|
335
|
+
await X(e);
|
|
336
|
+
let t = U;
|
|
337
|
+
for (let n = 0; n < O && !(I || t !== U || H || Z(e) >= D); n++) {
|
|
338
|
+
let t = Z(e);
|
|
339
|
+
if (await Se(), Z(e) <= t) break;
|
|
335
340
|
}
|
|
336
341
|
} finally {
|
|
337
|
-
|
|
342
|
+
B--, V === e && (V = void 0);
|
|
338
343
|
}
|
|
339
344
|
}
|
|
340
|
-
}, De = 0,
|
|
345
|
+
}, De = 0, Oe = null, Q, ke = (e) => {
|
|
341
346
|
let t = performance.now(), n = t - De;
|
|
342
|
-
if (n >=
|
|
343
|
-
De = t,
|
|
347
|
+
if (n >= k) {
|
|
348
|
+
De = t, Oe = null, re?.(e);
|
|
344
349
|
return;
|
|
345
350
|
}
|
|
346
|
-
|
|
351
|
+
Oe = e, !Q && (Q = setTimeout(() => {
|
|
347
352
|
Q = void 0;
|
|
348
|
-
let e =
|
|
349
|
-
|
|
350
|
-
},
|
|
353
|
+
let e = Oe;
|
|
354
|
+
Oe = null, !(e === null || I) && (De = performance.now(), re?.(e));
|
|
355
|
+
}, k - n));
|
|
351
356
|
};
|
|
352
|
-
|
|
357
|
+
F.push(() => {
|
|
353
358
|
Q && clearTimeout(Q);
|
|
354
359
|
});
|
|
355
|
-
let
|
|
356
|
-
|
|
360
|
+
let Ae = 0, $;
|
|
361
|
+
F.push(() => {
|
|
357
362
|
$ && clearTimeout($);
|
|
358
363
|
});
|
|
359
|
-
let
|
|
364
|
+
let je = () => {
|
|
360
365
|
let t = n.currentTime, r = e.info.input.duration || n.duration;
|
|
361
|
-
r > 0 &&
|
|
362
|
-
let i = performance.now(), a = i -
|
|
363
|
-
if (
|
|
364
|
-
if (
|
|
365
|
-
$ = void 0,
|
|
366
|
+
r > 0 && ke(Math.min(Math.max(t / r, 0), 1));
|
|
367
|
+
let i = performance.now(), a = i - Ae < A;
|
|
368
|
+
if (Ae = i, !Ce(t) && !(J && (z || Z(t) > 0) && Math.abs(t - pe) < .001)) {
|
|
369
|
+
if (H = !1, $ && clearTimeout($), !a) {
|
|
370
|
+
$ = void 0, X(t);
|
|
366
371
|
return;
|
|
367
372
|
}
|
|
368
373
|
$ = setTimeout(() => {
|
|
369
|
-
if ($ = void 0,
|
|
374
|
+
if ($ = void 0, I) return;
|
|
370
375
|
let e = n.currentTime;
|
|
371
|
-
Ce(e) || (
|
|
372
|
-
},
|
|
376
|
+
Ce(e) || (H = !1, X(e));
|
|
377
|
+
}, A);
|
|
373
378
|
}
|
|
374
379
|
};
|
|
375
|
-
n.addEventListener("seeking",
|
|
376
|
-
let
|
|
377
|
-
if (
|
|
378
|
-
|
|
380
|
+
n.addEventListener("seeking", je), F.push(() => n.removeEventListener("seeking", je));
|
|
381
|
+
let Me = !1, Ne = () => {
|
|
382
|
+
if (Me) return;
|
|
383
|
+
Me = !0;
|
|
379
384
|
let e = n.error;
|
|
380
|
-
|
|
385
|
+
Y(new _(`the media element failed: ${e?.message ?? "unknown"}`, { cause: e }), !1, !0);
|
|
381
386
|
};
|
|
382
|
-
n.addEventListener("error",
|
|
383
|
-
let
|
|
384
|
-
|
|
387
|
+
n.addEventListener("error", Ne), F.push(() => n.removeEventListener("error", Ne));
|
|
388
|
+
let Pe = setInterval(() => {
|
|
389
|
+
Me || n.error || (me().catch(() => {}), Se().catch((e) => Y(e, !1)), be() && !W && ve() && h.readyState === "open" && le(() => !z).catch(() => {}));
|
|
385
390
|
}, 100);
|
|
386
|
-
return
|
|
387
|
-
destroy:
|
|
391
|
+
return F.push(() => clearInterval(Pe)), {
|
|
392
|
+
destroy: oe,
|
|
388
393
|
prepareSeek: Ee,
|
|
389
394
|
videoElement: n,
|
|
390
395
|
selectSubtitleStream: (e) => s.selectStream(e),
|
|
@@ -395,10 +400,10 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
395
400
|
audioMimeType: e.info.output.audioMimeType
|
|
396
401
|
};
|
|
397
402
|
} catch (e) {
|
|
398
|
-
throw
|
|
403
|
+
throw oe(), e;
|
|
399
404
|
}
|
|
400
|
-
},
|
|
401
|
-
let { publicPath: n, workerUrl: r, length: i, read: a, onThumbnails: o, width: s =
|
|
405
|
+
}, te = 5, ne = 500, re = 320, ie = 1e6, ae = 3, N = 1e4, P = 1.5, F = 4e6, I = 3e4, oe = async (e) => {
|
|
406
|
+
let { publicPath: n, workerUrl: r, length: i, read: a, onThumbnails: o, width: s = re } = e, c = await t({
|
|
402
407
|
publicPath: n,
|
|
403
408
|
workerUrl: r,
|
|
404
409
|
workerOptions: { type: "module" },
|
|
@@ -406,7 +411,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
406
411
|
read: a
|
|
407
412
|
});
|
|
408
413
|
try {
|
|
409
|
-
let t = await c.init(), n = t.duration, r = Math.max(e.interval ??
|
|
414
|
+
let t = await c.init(), n = t.duration, r = Math.max(e.interval ?? te, n / ne), a = [], l = (e) => {
|
|
410
415
|
let t = [];
|
|
411
416
|
for (let [a, o] of e.entries()) {
|
|
412
417
|
let s = t.at(-1);
|
|
@@ -414,7 +419,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
414
419
|
timestamp: o.timestamp,
|
|
415
420
|
endTime: n,
|
|
416
421
|
startByte: o.pos,
|
|
417
|
-
endByte: Math.min((e[a + 1]?.pos ?? i) +
|
|
422
|
+
endByte: Math.min((e[a + 1]?.pos ?? i) + ie, i),
|
|
418
423
|
done: !1,
|
|
419
424
|
attempts: 0
|
|
420
425
|
});
|
|
@@ -453,7 +458,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
453
458
|
}), o(e);
|
|
454
459
|
}, x = async (e) => {
|
|
455
460
|
if (d) return;
|
|
456
|
-
let t = await Promise.race([c.readKeyframe(e.timestamp), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")),
|
|
461
|
+
let t = await Promise.race([c.readKeyframe(e.timestamp), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")), N))]), n = await createImageBitmap(new Blob([t], { type: "image/png" })), r = new OffscreenCanvas(s, Math.max(1, Math.round(n.height * (s / n.width))));
|
|
457
462
|
r.getContext("2d").drawImage(n, 0, 0, r.width, r.height), n.close();
|
|
458
463
|
let i = await r.convertToBlob({
|
|
459
464
|
type: "image/webp",
|
|
@@ -477,7 +482,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
477
482
|
if (!f.length) return;
|
|
478
483
|
let e = f.splice(y(), 1)[0];
|
|
479
484
|
p = !0, x(e).catch(() => {
|
|
480
|
-
e.attempts += 1, e.done = e.attempts >=
|
|
485
|
+
e.attempts += 1, e.done = e.attempts >= ae;
|
|
481
486
|
}).finally(() => {
|
|
482
487
|
p = !1, S();
|
|
483
488
|
});
|
|
@@ -486,7 +491,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
486
491
|
}, w = async (e) => {
|
|
487
492
|
_ = !0;
|
|
488
493
|
try {
|
|
489
|
-
let t = await Promise.race([c.init(), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")),
|
|
494
|
+
let t = await Promise.race([c.init(), new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("timed out")), I))]);
|
|
490
495
|
if (d) return;
|
|
491
496
|
h = e;
|
|
492
497
|
let n = l(t.indexes);
|
|
@@ -512,7 +517,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
512
517
|
if (d) return;
|
|
513
518
|
v = e;
|
|
514
519
|
let t = T(e);
|
|
515
|
-
h < 0 ? h = t : (t >= Math.max(h *
|
|
520
|
+
h < 0 ? h = t : (t >= Math.max(h * P, h + F) || t >= i && h < i) && (g = !0), E(e), S();
|
|
516
521
|
},
|
|
517
522
|
prioritize: (e) => {
|
|
518
523
|
d || (m = e);
|
|
@@ -520,14 +525,14 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
520
525
|
destroy: () => {
|
|
521
526
|
d = !0, f.length = 0;
|
|
522
527
|
for (let e of u) URL.revokeObjectURL(e.url);
|
|
523
|
-
u = [],
|
|
528
|
+
u = [], M(c);
|
|
524
529
|
}
|
|
525
530
|
};
|
|
526
531
|
} catch (e) {
|
|
527
|
-
throw
|
|
532
|
+
throw M(c), e;
|
|
528
533
|
}
|
|
529
|
-
},
|
|
530
|
-
let { video: t, subtitles: n } = e, r = e.mode ??
|
|
534
|
+
}, L = 1280, se = 1920, ce = 250, le = 100, R = () => typeof HTMLCanvasElement < "u" && "captureStream" in HTMLCanvasElement.prototype, z = () => typeof document < "u" && typeof HTMLVideoElement < "u" && typeof HTMLVideoElement.prototype.requestPictureInPicture == "function" && !!document.pictureInPictureEnabled, B = () => typeof HTMLVideoElement < "u" && "mozCaptureStream" in HTMLVideoElement.prototype, V = () => R() ? z() ? "window" : B() ? "burn-in" : null : null, ue = (e) => {
|
|
535
|
+
let { video: t, subtitles: n } = e, r = e.mode ?? V() ?? "window", i = e.maxWidth ?? (r === "burn-in" ? se : L), 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) => {
|
|
531
536
|
r.drawImage(t, 0, 0, e.width, e.height);
|
|
532
537
|
let i = n.querySelector("canvas");
|
|
533
538
|
i && i.width > 0 && i.height > 0 && r.drawImage(i, 0, 0, e.width, e.height);
|
|
@@ -556,39 +561,39 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
556
561
|
l = !0;
|
|
557
562
|
let { mirror: e } = a;
|
|
558
563
|
h(), e.play().then(() => new Promise((e) => {
|
|
559
|
-
setTimeout(e,
|
|
564
|
+
setTimeout(e, le);
|
|
560
565
|
})).catch(() => {}).finally(() => {
|
|
561
566
|
e.pause(), setTimeout(() => {
|
|
562
567
|
l = !1;
|
|
563
|
-
},
|
|
568
|
+
}, le);
|
|
564
569
|
});
|
|
565
570
|
}, E = [["play", () => {
|
|
566
571
|
t.play().catch(() => {});
|
|
567
|
-
}], ["pause", () => t.pause()]],
|
|
572
|
+
}], ["pause", () => t.pause()]], D = (e) => {
|
|
568
573
|
if ("mediaSession" in navigator) for (let [t, n] of E) try {
|
|
569
574
|
navigator.mediaSession.setActionHandler(t, e ? n : null);
|
|
570
575
|
} catch {}
|
|
571
|
-
},
|
|
572
|
-
if (y(),
|
|
576
|
+
}, O = () => {
|
|
577
|
+
if (y(), D(!1), t.removeEventListener("play", C), t.removeEventListener("pause", w), t.removeEventListener("seeked", T), !a) {
|
|
573
578
|
f?.();
|
|
574
579
|
return;
|
|
575
580
|
}
|
|
576
581
|
let { stream: e, mirror: n } = a;
|
|
577
|
-
n.removeEventListener("play", x), n.removeEventListener("pause", S), n.removeEventListener("leavepictureinpicture",
|
|
582
|
+
n.removeEventListener("play", x), n.removeEventListener("pause", S), n.removeEventListener("leavepictureinpicture", k);
|
|
578
583
|
for (let t of e.getTracks()) t.stop();
|
|
579
584
|
n.remove(), a = void 0, f?.();
|
|
580
|
-
},
|
|
585
|
+
}, k = () => O(), A = (e) => {
|
|
581
586
|
let r = t.style.opacity, i = n.style.display;
|
|
582
587
|
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 = () => {
|
|
583
588
|
f = void 0, t.style.opacity = r, n.style.display = i;
|
|
584
589
|
};
|
|
585
|
-
},
|
|
590
|
+
}, j = async () => {
|
|
586
591
|
let n = Math.min(t.videoWidth || i, i), o = Math.round(n * ((t.videoHeight || 9) / (t.videoWidth || 16))), c = document.createElement("canvas");
|
|
587
592
|
c.width = n, c.height = o;
|
|
588
593
|
let l = c.getContext("2d");
|
|
589
594
|
if (!l) throw Error("the picture in picture composite has no 2d context");
|
|
590
595
|
let u = document.createElement("video");
|
|
591
|
-
u.muted = !0, u.playsInline = !0, r === "burn-in" ?
|
|
596
|
+
u.muted = !0, u.playsInline = !0, r === "burn-in" ? A(u) : u.style.cssText = "position:fixed;width:1px;height:1px;opacity:0;pointer-events:none;left:-1px;top:-1px", m(c, l);
|
|
592
597
|
let f = {
|
|
593
598
|
composite: c,
|
|
594
599
|
context: l,
|
|
@@ -597,7 +602,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
597
602
|
};
|
|
598
603
|
if (a = f, u.srcObject = f.stream, (e.container ?? t.parentElement ?? document.body).appendChild(u), v(), s = setInterval(() => {
|
|
599
604
|
t.paused && h();
|
|
600
|
-
},
|
|
605
|
+
}, ce), u.play().catch(() => {}), u.readyState === 0 && await new Promise((e) => {
|
|
601
606
|
let t = () => {
|
|
602
607
|
clearTimeout(n), e();
|
|
603
608
|
}, n = setTimeout(t, 1e3);
|
|
@@ -606,7 +611,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
606
611
|
u.remove();
|
|
607
612
|
return;
|
|
608
613
|
}
|
|
609
|
-
if (u.addEventListener("play", x), u.addEventListener("pause", S), u.addEventListener("leavepictureinpicture",
|
|
614
|
+
if (u.addEventListener("play", x), u.addEventListener("pause", S), u.addEventListener("leavepictureinpicture", k), t.addEventListener("play", C), t.addEventListener("pause", w), t.addEventListener("seeked", T), D(!0), b(), r === "burn-in") {
|
|
610
615
|
t.paused && u.pause(), e.onBurnedInChange?.(!0);
|
|
611
616
|
return;
|
|
612
617
|
}
|
|
@@ -619,7 +624,7 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
619
624
|
try {
|
|
620
625
|
if (p()) {
|
|
621
626
|
if (r === "burn-in") {
|
|
622
|
-
|
|
627
|
+
O(), e.onBurnedInChange?.(!1);
|
|
623
628
|
return;
|
|
624
629
|
}
|
|
625
630
|
await document.exitPictureInPicture().catch(() => {});
|
|
@@ -627,9 +632,9 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
627
632
|
}
|
|
628
633
|
r !== "burn-in" && document.pictureInPictureElement && await document.exitPictureInPicture().catch(() => {});
|
|
629
634
|
try {
|
|
630
|
-
await
|
|
635
|
+
await j();
|
|
631
636
|
} catch (t) {
|
|
632
|
-
console.warn("subtitle compositing for picture in picture failed", t),
|
|
637
|
+
console.warn("subtitle compositing for picture in picture failed", t), O(), r === "burn-in" && e.onBurnedInChange?.(!1);
|
|
633
638
|
}
|
|
634
639
|
} finally {
|
|
635
640
|
u = !1;
|
|
@@ -638,9 +643,9 @@ var i = (e) => Array(e.buffered.length).fill(void 0).map((t, n) => ({
|
|
|
638
643
|
},
|
|
639
644
|
mode: r,
|
|
640
645
|
destroy: () => {
|
|
641
|
-
d = !0, r !== "burn-in" && p() && document.exitPictureInPicture().catch(() => {}),
|
|
646
|
+
d = !0, r !== "burn-in" && p() && document.exitPictureInPicture().catch(() => {}), O(), r === "burn-in" && e.onBurnedInChange?.(!1);
|
|
642
647
|
}
|
|
643
648
|
};
|
|
644
649
|
};
|
|
645
650
|
//#endregion
|
|
646
|
-
export {
|
|
651
|
+
export { _ as a, M as c, i as d, o as f, j as i, s as l, V as n, v as o, oe as r, ee as s, ue as t, g as u };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as e, l as t, n, o as r, r as i, s as a, t as o, u as s } from "./engine-
|
|
1
|
+
import { c as e, l as t, n, o as r, r as i, s as a, t as o, u as s } from "./engine-AjFLuCdA.js";
|
|
2
2
|
import { Children as c, Fragment as l, isValidElement as u, useCallback as d, useEffect as f, useMemo as p, useRef as m, useState as h, useSyncExternalStore as g } from "react";
|
|
3
3
|
import { css as _, keyframes as v } from "@emotion/react";
|
|
4
4
|
import { createPlayer as y, useContainerAttach as b, useMediaAttach as x } from "@videojs/react";
|
|
@@ -87,32 +87,32 @@ var U = {
|
|
|
87
87
|
}
|
|
88
88
|
return t.length ? t.join("\n") : void 0;
|
|
89
89
|
}, le = (e, t, n, i) => {
|
|
90
|
-
let o = K(), { read: s, size: c, publicPath: l = "", libavWorkerUrl: u = "", jassubWorkerUrl: p = "", jassubWasmUrl: g = "", jassubLegacyWasmUrl: _, defaultFontUrl: v,
|
|
91
|
-
|
|
92
|
-
let [
|
|
90
|
+
let o = K(), { read: s, size: c, publicPath: l = "", libavWorkerUrl: u = "", jassubWorkerUrl: p = "", jassubWasmUrl: g = "", jassubLegacyWasmUrl: _, defaultFontUrl: v, cjkFontUrl: y, bufferSize: b, autoplay: x = !1, chapters: S, seekPrepareBudgetMs: C = X } = n ?? {}, w = m(S);
|
|
91
|
+
w.current = S;
|
|
92
|
+
let [T, E] = h(void 0), [D, O] = h(0), k = m({
|
|
93
93
|
count: 0,
|
|
94
94
|
at: 0
|
|
95
|
-
}),
|
|
96
|
-
f(() => (
|
|
95
|
+
}), A = m(void 0);
|
|
96
|
+
f(() => (k.current = {
|
|
97
97
|
count: 0,
|
|
98
98
|
at: 0
|
|
99
99
|
}, o.setSourceState({ playbackErrors: [] }), () => {
|
|
100
|
-
|
|
100
|
+
A.current && clearTimeout(A.current);
|
|
101
101
|
}), [c]);
|
|
102
|
-
let
|
|
103
|
-
|
|
104
|
-
let
|
|
105
|
-
|
|
106
|
-
let
|
|
107
|
-
|
|
108
|
-
let
|
|
109
|
-
|
|
110
|
-
let
|
|
102
|
+
let j = m(null), M = m(null), N = m(!1), P = m(s);
|
|
103
|
+
P.current = s;
|
|
104
|
+
let F = m(n?.onSeek);
|
|
105
|
+
F.current = n?.onSeek;
|
|
106
|
+
let I = m(n?.onPlaybackError);
|
|
107
|
+
I.current = n?.onPlaybackError;
|
|
108
|
+
let L = m(i);
|
|
109
|
+
L.current = i;
|
|
110
|
+
let R = d((e) => {
|
|
111
111
|
let t = typeof e == "number" ? e : void 0;
|
|
112
|
-
|
|
113
|
-
}, [o]),
|
|
114
|
-
let t =
|
|
115
|
-
if (!t ||
|
|
112
|
+
N.current = !0, o.setSourceState({ selectedSubtitleTrack: t }), j.current?.selectSubtitleStream(t);
|
|
113
|
+
}, [o]), z = d((e) => {
|
|
114
|
+
let t = j.current;
|
|
115
|
+
if (!t || C <= 0) {
|
|
116
116
|
o.seek(e);
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
@@ -130,24 +130,24 @@ var U = {
|
|
|
130
130
|
c?.addEventListener("seeked", l);
|
|
131
131
|
let d = setTimeout(() => {
|
|
132
132
|
a = "deadline", s();
|
|
133
|
-
},
|
|
133
|
+
}, C);
|
|
134
134
|
t.prepareSeek(e).catch(() => {}).finally(() => {
|
|
135
135
|
clearTimeout(d), s();
|
|
136
136
|
});
|
|
137
|
-
}, [o,
|
|
138
|
-
typeof e == "number" && (o.setSourceState({ selectedAudioTrack: e }),
|
|
139
|
-
}, [o]),
|
|
137
|
+
}, [o, C]), B = d((e) => {
|
|
138
|
+
typeof e == "number" && (o.setSourceState({ selectedAudioTrack: e }), E(e));
|
|
139
|
+
}, [o]), V = K((e) => e.setSourceState);
|
|
140
140
|
f(() => {
|
|
141
|
-
|
|
142
|
-
selectSubtitleTrack:
|
|
143
|
-
selectAudioTrack:
|
|
144
|
-
requestSeek:
|
|
141
|
+
V({
|
|
142
|
+
selectSubtitleTrack: R,
|
|
143
|
+
selectAudioTrack: B,
|
|
144
|
+
requestSeek: z
|
|
145
145
|
});
|
|
146
146
|
}, [
|
|
147
|
+
V,
|
|
148
|
+
R,
|
|
147
149
|
B,
|
|
148
|
-
|
|
149
|
-
z,
|
|
150
|
-
R
|
|
150
|
+
z
|
|
151
151
|
]), f(() => {
|
|
152
152
|
if (!e || !t || !c || !s) return;
|
|
153
153
|
let n = !1;
|
|
@@ -181,25 +181,25 @@ var U = {
|
|
|
181
181
|
let t = r(e);
|
|
182
182
|
if (i(e, t), t) {
|
|
183
183
|
let t = performance.now();
|
|
184
|
-
t -
|
|
184
|
+
t - k.current.at > ae && (k.current = {
|
|
185
185
|
count: 0,
|
|
186
186
|
at: t
|
|
187
187
|
});
|
|
188
|
-
let n = Y[Math.min(
|
|
189
|
-
|
|
190
|
-
count:
|
|
188
|
+
let n = Y[Math.min(k.current.count, Y.length - 1)];
|
|
189
|
+
k.current = {
|
|
190
|
+
count: k.current.count + 1,
|
|
191
191
|
at: t
|
|
192
|
-
}, console.warn(`the media element failed; rebuilding the pipeline${n ? ` in ${n}ms` : ""}`, e),
|
|
192
|
+
}, console.warn(`the media element failed; rebuilding the pipeline${n ? ` in ${n}ms` : ""}`, e), A.current && clearTimeout(A.current), A.current = setTimeout(() => O((e) => e + 1), n);
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
|
-
console.error("playback failed", e), o.setSourceState({ playbackError: e }),
|
|
195
|
+
console.error("playback failed", e), o.setSourceState({ playbackError: e }), I.current?.(e);
|
|
196
196
|
};
|
|
197
197
|
return (async () => {
|
|
198
198
|
try {
|
|
199
199
|
let r = await a({
|
|
200
200
|
videoElement: e,
|
|
201
201
|
subtitleContainer: t,
|
|
202
|
-
read: (e, t) =>
|
|
202
|
+
read: (e, t) => P.current(e, t),
|
|
203
203
|
length: c,
|
|
204
204
|
publicPath: l,
|
|
205
205
|
libavWorkerUrl: u,
|
|
@@ -207,24 +207,25 @@ var U = {
|
|
|
207
207
|
jassubWasmUrl: g,
|
|
208
208
|
jassubLegacyWasmUrl: _,
|
|
209
209
|
defaultFontUrl: v,
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
cjkFontUrl: y,
|
|
211
|
+
bufferSize: b,
|
|
212
|
+
audioStreamIndex: T,
|
|
212
213
|
onReady: () => {
|
|
213
214
|
if (n) return;
|
|
214
215
|
o.setSourceState({ ready: !0 });
|
|
215
|
-
let t =
|
|
216
|
-
|
|
216
|
+
let t = M.current;
|
|
217
|
+
M.current = null, t && t.size === c && t.time > 0 && (e.currentTime = t.time), x && e.play().catch(() => {});
|
|
217
218
|
},
|
|
218
219
|
onError: d,
|
|
219
220
|
onRecovered: () => {
|
|
220
221
|
n || o.setSourceState({ playbackError: null });
|
|
221
222
|
},
|
|
222
|
-
onSeek: (e) =>
|
|
223
|
-
onOutput: (e) =>
|
|
223
|
+
onSeek: (e) => F.current?.(e),
|
|
224
|
+
onOutput: (e) => L.current?.(e),
|
|
224
225
|
onSubtitleStreams: (e) => {
|
|
225
226
|
n || o.setSourceState({
|
|
226
227
|
subtitleTracks: J(e),
|
|
227
|
-
...
|
|
228
|
+
...N.current ? {} : { selectedSubtitleTrack: e[0]?.streamIndex }
|
|
228
229
|
});
|
|
229
230
|
},
|
|
230
231
|
onAudioStreams: (e, t) => {
|
|
@@ -238,9 +239,9 @@ var U = {
|
|
|
238
239
|
r.destroy();
|
|
239
240
|
return;
|
|
240
241
|
}
|
|
241
|
-
|
|
242
|
+
j.current = r, o.setSourceState({
|
|
242
243
|
indexes: r.indexes,
|
|
243
|
-
chapters:
|
|
244
|
+
chapters: w.current ?? r.chapters
|
|
244
245
|
});
|
|
245
246
|
let i = o.selectedSubtitleTrack;
|
|
246
247
|
typeof i == "number" && r.selectSubtitleStream(i);
|
|
@@ -248,10 +249,10 @@ var U = {
|
|
|
248
249
|
d(e);
|
|
249
250
|
}
|
|
250
251
|
})(), () => {
|
|
251
|
-
n = !0,
|
|
252
|
+
n = !0, M.current = {
|
|
252
253
|
time: e.currentTime,
|
|
253
254
|
size: c
|
|
254
|
-
},
|
|
255
|
+
}, j.current?.destroy(), j.current = null, o.setSourceState({ ready: !1 });
|
|
255
256
|
};
|
|
256
257
|
}, [
|
|
257
258
|
o,
|
|
@@ -265,9 +266,10 @@ var U = {
|
|
|
265
266
|
_,
|
|
266
267
|
v,
|
|
267
268
|
y,
|
|
268
|
-
w,
|
|
269
269
|
b,
|
|
270
|
-
|
|
270
|
+
T,
|
|
271
|
+
x,
|
|
272
|
+
D
|
|
271
273
|
]);
|
|
272
274
|
}, ue = 1001 / 24e3, de = (e, t) => new Promise((n) => {
|
|
273
275
|
let r = setTimeout(n, t);
|
|
@@ -128,6 +128,8 @@ export type MediaPlayerLocalOptions = CommonOptions & MediaPlayerSource & {
|
|
|
128
128
|
jassubLegacyWasmUrl?: string;
|
|
129
129
|
/** Fallback face for `liberation sans`, used when a subtitle track names a font the file does not carry. */
|
|
130
130
|
defaultFontUrl?: string;
|
|
131
|
+
/** `@banou/media-player/noto-sans-jp.otf`, the face for CJK text, fetched once the selected track shows some. */
|
|
132
|
+
cjkFontUrl?: string;
|
|
131
133
|
bufferSize?: number;
|
|
132
134
|
/**
|
|
133
135
|
* How long a seek waits for its own data before the playhead moves anyway, in ms. Default 500.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@banou/media-player",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.26",
|
|
4
4
|
"description": "A video player for containers and codecs the browser cannot play natively, remuxed on the fly",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"import": "./dist/remote/index.js"
|
|
20
20
|
},
|
|
21
21
|
"./volume-normalizer-worklet.js": "./dist/volume-normalizer-worklet.js",
|
|
22
|
+
"./noto-sans-jp.otf": "./src/lib/assets/noto-sans-jp.otf",
|
|
22
23
|
"./package.json": "./package.json"
|
|
23
24
|
},
|
|
24
25
|
"files": [
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
This Font Software is licensed under the SIL Open Font License,
|
|
2
|
+
Version 1.1.
|
|
3
|
+
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
http://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
-----------------------------------------------------------
|
|
8
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
9
|
+
-----------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
PREAMBLE
|
|
12
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
13
|
+
development of collaborative font projects, to support the font
|
|
14
|
+
creation efforts of academic and linguistic communities, and to
|
|
15
|
+
provide a free and open framework in which fonts may be shared and
|
|
16
|
+
improved in partnership with others.
|
|
17
|
+
|
|
18
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
19
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
20
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
21
|
+
redistributed and/or sold with any software provided that any reserved
|
|
22
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
23
|
+
however, cannot be released under any other type of license. The
|
|
24
|
+
requirement for fonts to remain under this license does not apply to
|
|
25
|
+
any document created using the fonts or their derivatives.
|
|
26
|
+
|
|
27
|
+
DEFINITIONS
|
|
28
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
29
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
30
|
+
include source files, build scripts and documentation.
|
|
31
|
+
|
|
32
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
33
|
+
copyright statement(s).
|
|
34
|
+
|
|
35
|
+
"Original Version" refers to the collection of Font Software
|
|
36
|
+
components as distributed by the Copyright Holder(s).
|
|
37
|
+
|
|
38
|
+
"Modified Version" refers to any derivative made by adding to,
|
|
39
|
+
deleting, or substituting -- in part or in whole -- any of the
|
|
40
|
+
components of the Original Version, by changing formats or by porting
|
|
41
|
+
the Font Software to a new environment.
|
|
42
|
+
|
|
43
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
44
|
+
writer or other person who contributed to the Font Software.
|
|
45
|
+
|
|
46
|
+
PERMISSION & CONDITIONS
|
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
48
|
+
a copy of the Font Software, to use, study, copy, merge, embed,
|
|
49
|
+
modify, redistribute, and sell modified and unmodified copies of the
|
|
50
|
+
Font Software, subject to the following conditions:
|
|
51
|
+
|
|
52
|
+
1) Neither the Font Software nor any of its individual components, in
|
|
53
|
+
Original or Modified Versions, may be sold by itself.
|
|
54
|
+
|
|
55
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
56
|
+
redistributed and/or sold with any software, provided that each copy
|
|
57
|
+
contains the above copyright notice and this license. These can be
|
|
58
|
+
included either as stand-alone text files, human-readable headers or
|
|
59
|
+
in the appropriate machine-readable metadata fields within text or
|
|
60
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
61
|
+
|
|
62
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
63
|
+
Name(s) unless explicit written permission is granted by the
|
|
64
|
+
corresponding Copyright Holder. This restriction only applies to the
|
|
65
|
+
primary font name as presented to the users.
|
|
66
|
+
|
|
67
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
68
|
+
Software shall not be used to promote, endorse or advertise any
|
|
69
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
70
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
71
|
+
permission.
|
|
72
|
+
|
|
73
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
74
|
+
must be distributed entirely under this license, and must not be
|
|
75
|
+
distributed under any other license. The requirement for fonts to
|
|
76
|
+
remain under this license does not apply to any document created using
|
|
77
|
+
the Font Software.
|
|
78
|
+
|
|
79
|
+
TERMINATION
|
|
80
|
+
This license becomes null and void if any of the above conditions are
|
|
81
|
+
not met.
|
|
82
|
+
|
|
83
|
+
DISCLAIMER
|
|
84
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
85
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
86
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
87
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
88
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
89
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
90
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
91
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
92
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
@@ -55,6 +55,7 @@ export type PlaybackOptions = {
|
|
|
55
55
|
/** jassub's non-SIMD build; without it subtitles fail rather than degrade on Safari before 16.4 */
|
|
56
56
|
jassubLegacyWasmUrl?: string
|
|
57
57
|
defaultFontUrl?: string
|
|
58
|
+
cjkFontUrl?: string
|
|
58
59
|
bufferSize?: number
|
|
59
60
|
audioStreamIndex?: number
|
|
60
61
|
onReady?: () => void
|
|
@@ -157,7 +158,7 @@ export const terminateRemuxer = (remuxer: { worker: Worker, destroy: () => Promi
|
|
|
157
158
|
export const startPlayback = async (options: PlaybackOptions): Promise<PlaybackController> => {
|
|
158
159
|
const {
|
|
159
160
|
videoElement, subtitleContainer, read, length, publicPath, libavWorkerUrl,
|
|
160
|
-
jassubWorkerUrl, jassubWasmUrl, jassubLegacyWasmUrl, defaultFontUrl, bufferSize = DEFAULT_BUFFER_SIZE,
|
|
161
|
+
jassubWorkerUrl, jassubWasmUrl, jassubLegacyWasmUrl, defaultFontUrl, cjkFontUrl, bufferSize = DEFAULT_BUFFER_SIZE,
|
|
161
162
|
audioStreamIndex, onReady, onError, onRecovered, onSeek, onSubtitleStreams,
|
|
162
163
|
onAudioStreams, onOutput,
|
|
163
164
|
} = options
|
|
@@ -199,6 +200,7 @@ export const startPlayback = async (options: PlaybackOptions): Promise<PlaybackC
|
|
|
199
200
|
wasmUrl: jassubWasmUrl,
|
|
200
201
|
legacyWasmUrl: jassubLegacyWasmUrl,
|
|
201
202
|
defaultFontUrl,
|
|
203
|
+
cjkFontUrl,
|
|
202
204
|
onStreams: onSubtitleStreams,
|
|
203
205
|
})
|
|
204
206
|
teardown.push(() => subtitles.destroy())
|
|
@@ -44,6 +44,14 @@ export type SubtitleRendererOptions = {
|
|
|
44
44
|
* given on `workerFetched`.
|
|
45
45
|
*/
|
|
46
46
|
defaultFontUrl?: string
|
|
47
|
+
/**
|
|
48
|
+
* Noto Sans JP, `@banou/media-player/noto-sans-jp.otf`, for Japanese text the file's own fonts cannot draw.
|
|
49
|
+
*
|
|
50
|
+
* Fetched only once a line on the selected track holds CJK text, after `defaultFontUrl`. It draws only the
|
|
51
|
+
* glyphs `liberation sans` lacks, so a url that fails to load leaves those as boxes and changes nothing
|
|
52
|
+
* else. May be relative, as `defaultFontUrl`.
|
|
53
|
+
*/
|
|
54
|
+
cjkFontUrl?: string
|
|
47
55
|
onStreams?: (streams: SubtitleStream[]) => void
|
|
48
56
|
}
|
|
49
57
|
|
|
@@ -63,6 +71,16 @@ const workerFetched = (url: string | undefined) =>
|
|
|
63
71
|
|
|
64
72
|
const convertTimestamp = (ms: number) => new Date(ms).toISOString().slice(11, 22)
|
|
65
73
|
|
|
74
|
+
/**
|
|
75
|
+
* jassub's libass has no system font fallback (`ASS_FONTPROVIDER_NONE`): a glyph the style's face lacks
|
|
76
|
+
* is looked for in the default family and nowhere else, and `liberation sans` has no CJK at all. Releases
|
|
77
|
+
* set song lyrics in a Latin-only font and rely on the player's fallback, so without the CJK face a line
|
|
78
|
+
* of hiragana draws as a row of empty boxes. That face carries `liberation sans` as a second family name
|
|
79
|
+
* (scripts/cjk-font.py), and libass takes the first face of a family that has the glyph, so it is loaded
|
|
80
|
+
* after the default face and is never made the default itself.
|
|
81
|
+
*/
|
|
82
|
+
const CJK_TEXT = /[\u3000-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff00-\uffef]/
|
|
83
|
+
|
|
66
84
|
/**
|
|
67
85
|
* How many styles libass keeps in front of the ones the file declares.
|
|
68
86
|
*
|
|
@@ -153,6 +171,9 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
153
171
|
const wasmUrl = workerFetched(options.wasmUrl)!
|
|
154
172
|
const legacyWasmUrl = workerFetched(options.legacyWasmUrl)
|
|
155
173
|
const defaultFontUrl = workerFetched(options.defaultFontUrl)
|
|
174
|
+
const cjkFontUrl = workerFetched(options.cjkFontUrl)
|
|
175
|
+
let cjkFontRequested = false
|
|
176
|
+
let defaultFontLoaded: Promise<unknown> = Promise.resolve()
|
|
156
177
|
let jassub: JASSUB | undefined
|
|
157
178
|
let attachments: [string, Uint8Array][] = []
|
|
158
179
|
const headers = new Map<number, SubtitleHeaderPart>()
|
|
@@ -307,12 +328,22 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
307
328
|
*/
|
|
308
329
|
if (defaultFontUrl) {
|
|
309
330
|
onRenderer((renderer) => {
|
|
310
|
-
|
|
331
|
+
defaultFontLoaded = Promise.resolve(renderer.addFonts([defaultFontUrl])).then(repaint, rendererFailed)
|
|
311
332
|
})
|
|
312
333
|
}
|
|
313
334
|
repaint()
|
|
314
335
|
}
|
|
315
336
|
|
|
337
|
+
const loadCjkFontFor = (events: ASSEvent[]) => {
|
|
338
|
+
if (!cjkFontUrl || cjkFontRequested || !events.some((event) => CJK_TEXT.test(event.Text))) return
|
|
339
|
+
cjkFontRequested = true
|
|
340
|
+
onRenderer(async (renderer) => {
|
|
341
|
+
await defaultFontLoaded
|
|
342
|
+
await renderer.addFonts([cjkFontUrl])
|
|
343
|
+
repaint()
|
|
344
|
+
})
|
|
345
|
+
}
|
|
346
|
+
|
|
316
347
|
const pushAttachments = (incoming: Attachment[]) => {
|
|
317
348
|
attachments = [...attachments, ...incoming.map((a) => [a.filename, new Uint8Array(a.data)] as [string, Uint8Array])]
|
|
318
349
|
}
|
|
@@ -348,6 +379,7 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
348
379
|
if (!incoming.length) return
|
|
349
380
|
// one hop for the whole burst rather than one per event
|
|
350
381
|
onRenderer((renderer) => Promise.all(incoming.map((event) => renderer.createEvent(event))))
|
|
382
|
+
loadCjkFontFor(incoming)
|
|
351
383
|
repaint()
|
|
352
384
|
}
|
|
353
385
|
|
|
@@ -365,6 +397,7 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
365
397
|
}
|
|
366
398
|
return Promise.all(calls)
|
|
367
399
|
})
|
|
400
|
+
loadCjkFontFor(events)
|
|
368
401
|
// outside the callback so that turning subtitles OFF while paused clears the picture too
|
|
369
402
|
repaint()
|
|
370
403
|
}
|
|
@@ -81,7 +81,7 @@ export const usePlayback = (
|
|
|
81
81
|
// null, and the effect below returns before touching them in that case.
|
|
82
82
|
const {
|
|
83
83
|
read, size, publicPath = '', libavWorkerUrl = '', jassubWorkerUrl = '', jassubWasmUrl = '',
|
|
84
|
-
jassubLegacyWasmUrl, defaultFontUrl, bufferSize, autoplay = false, chapters,
|
|
84
|
+
jassubLegacyWasmUrl, defaultFontUrl, cjkFontUrl, bufferSize, autoplay = false, chapters,
|
|
85
85
|
seekPrepareBudgetMs = SEEK_PREPARE_BUDGET_MS,
|
|
86
86
|
} = options ?? ({} as Partial<MediaPlayerLocalOptions>)
|
|
87
87
|
|
|
@@ -342,6 +342,7 @@ export const usePlayback = (
|
|
|
342
342
|
jassubWasmUrl,
|
|
343
343
|
jassubLegacyWasmUrl,
|
|
344
344
|
defaultFontUrl,
|
|
345
|
+
cjkFontUrl,
|
|
345
346
|
bufferSize,
|
|
346
347
|
audioStreamIndex,
|
|
347
348
|
onReady: () => {
|
|
@@ -402,6 +403,6 @@ export const usePlayback = (
|
|
|
402
403
|
// times a second, and the restart loop reads as "Loading metadata" forever at a flat 0 B/s.
|
|
403
404
|
}, [
|
|
404
405
|
player, video, subtitles, size, publicPath, libavWorkerUrl, jassubWorkerUrl, jassubWasmUrl,
|
|
405
|
-
jassubLegacyWasmUrl, defaultFontUrl, bufferSize, audioStreamIndex, autoplay, restartToken,
|
|
406
|
+
jassubLegacyWasmUrl, defaultFontUrl, cjkFontUrl, bufferSize, audioStreamIndex, autoplay, restartToken,
|
|
406
407
|
])
|
|
407
408
|
}
|
|
@@ -148,6 +148,8 @@ export type MediaPlayerLocalOptions =
|
|
|
148
148
|
jassubLegacyWasmUrl?: string
|
|
149
149
|
/** Fallback face for `liberation sans`, used when a subtitle track names a font the file does not carry. */
|
|
150
150
|
defaultFontUrl?: string
|
|
151
|
+
/** `@banou/media-player/noto-sans-jp.otf`, the face for CJK text, fetched once the selected track shows some. */
|
|
152
|
+
cjkFontUrl?: string
|
|
151
153
|
bufferSize?: number
|
|
152
154
|
/**
|
|
153
155
|
* How long a seek waits for its own data before the playhead moves anyway, in ms. Default 500.
|