@banou/media-player 0.10.24 → 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.
@@ -10,5 +10,7 @@ import type { PlayerMedia } from '../media';
10
10
  * The frame's length is learned from the gaps between frames presented one after another while playing at up to 1x:
11
11
  * faster, a 60 Hz display presents every other frame of a 60 fps file. A step while a seek waits for its data starts
12
12
  * from that seek's target.
13
+ *
14
+ * A media without `requestVideoFrameCallback` is stepped by `hostStep`, when its host can step it.
13
15
  */
14
- export declare const useFrameStep: (media: PlayerMedia | null) => void;
16
+ export declare const useFrameStep: (media: PlayerMedia | null, hostStep?: (direction: 1 | -1) => Promise<void>) => void;
@@ -218,7 +218,10 @@ export type SourceState = {
218
218
  * caller should seek directly.
219
219
  */
220
220
  requestSeek?: (time: number) => void;
221
- /** One frame back or forward, pausing first. Undefined for a media whose frames this document cannot see. */
221
+ /**
222
+ * One frame back or forward, pausing first. Undefined for a media whose frames this document cannot see, unless its
223
+ * host steps it (the remote arm's `stepFrame`).
224
+ */
222
225
  stepFrame?: (direction: 1 | -1) => void;
223
226
  /** Set when the pipeline fails. Cleared when it recovers. */
224
227
  playbackError: unknown;
@@ -367,7 +370,10 @@ export declare const sourceFeature: import("@videojs/react").PlayerFeature<{
367
370
  * caller should seek directly.
368
371
  */
369
372
  requestSeek?: (time: number) => void;
370
- /** One frame back or forward, pausing first. Undefined for a media whose frames this document cannot see. */
373
+ /**
374
+ * One frame back or forward, pausing first. Undefined for a media whose frames this document cannot see, unless its
375
+ * host steps it (the remote arm's `stepFrame`).
376
+ */
371
377
  stepFrame?: (direction: 1 | -1) => void;
372
378
  /** Set when the pipeline fails. Cleared when it recovers. */
373
379
  playbackError: unknown;
@@ -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.
@@ -217,6 +219,15 @@ export type MediaPlayerRemoteOptions = CommonOptions & {
217
219
  * host takes on by passing it. Read by value, so it may be written inline.
218
220
  */
219
221
  pictureInPicture?: PassThroughPictureInPicture;
222
+ /**
223
+ * Steps the media one frame back (-1) or forward (1), made by the host inside the media's own
224
+ * document, where its frames can be seen; pausing first is the host's. Used only for a media
225
+ * without `requestVideoFrameCallback`, as one in another document is: a media with it is stepped
226
+ * by the player, and without either `<` and `>` do nothing. One press before the promise settles
227
+ * waits for it and the rest are dropped, so a held key steps as fast as the host lands them, and
228
+ * a rejection is logged. Read by value, so it may be written inline.
229
+ */
230
+ stepFrame?: (direction: 1 | -1) => Promise<void>;
220
231
  };
221
232
  export type MediaPlayerOptions = MediaPlayerLocalOptions | MediaPlayerRemoteOptions;
222
233
  export declare const MediaPlayer: (options: MediaPlayerOptions & {
@@ -564,8 +564,10 @@ export const createAnalysis = ({ toWorklet, toPage = () => {} }) => {
564
564
  toWorklet({ drop: block })
565
565
  }
566
566
  if (!Number.isFinite(level)) return
567
- for (let block = Math.max(0, here - 1); block <= here + 3; block++) {
568
- if (block * BLOCK_BINS >= endBin) break
567
+ // the playhead's own block first: under load each took 21 to 43 ms, and sent after the one before it, a seek's
568
+ // cut over HTTP reached the worklet 64 to 75 ms after the seek, its audio 72 to 83 ms (HOR-888, 2026-10-23)
569
+ for (const block of [here, here - 1, here + 1, here + 2, here + 3]) {
570
+ if (block < 0 || block * BLOCK_BINS >= endBin) continue
569
571
  const start = block * BLOCK_BINS
570
572
  const known = signature(start - MARGIN_BINS, start + BLOCK_BINS + MARGIN_BINS)
571
573
  const last = sent.get(block)
@@ -1064,14 +1066,16 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
1064
1066
  * finds it at all, is taken only once the next search, 250 ms later, peaks within 2 ms of it, clear or not: voiced
1065
1067
  * dialogue repeats with its pitch, so a peak a pitch period off can come out ahead, and a FLAC run once matched 45 ms
1066
1068
  * off with every check passed. Over the whole 250 ms either way an Opus file's matches were never that clear (HOR-498
1067
- * build, 2026-10-17).
1069
+ * build, 2026-10-17). Kept past that next one, a candidate that a match came back to after four elsewhere locked an
1070
+ * Opus run under load 18 ms off, every cut that much late (HOR-888, 2026-10-23).
1068
1071
  */
1069
1072
  found(offset, clear) {
1070
1073
  const near = (other) => other !== null && Math.abs(offset - other) <= 0.002
1071
- if (near(this.candidate)) {
1074
+ const confirmed = near(this.candidate)
1075
+ this.candidate = null
1076
+ if (confirmed) {
1072
1077
  this.offset = offset
1073
1078
  this.doubt = false
1074
- this.candidate = null
1075
1079
  } else if (clear) {
1076
1080
  if (!this.doubt && near(this.offset)) this.offset = offset
1077
1081
  else this.candidate = offset
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banou/media-player",
3
- "version": "0.10.24",
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
@@ -564,8 +564,10 @@ export const createAnalysis = ({ toWorklet, toPage = () => {} }) => {
564
564
  toWorklet({ drop: block })
565
565
  }
566
566
  if (!Number.isFinite(level)) return
567
- for (let block = Math.max(0, here - 1); block <= here + 3; block++) {
568
- if (block * BLOCK_BINS >= endBin) break
567
+ // the playhead's own block first: under load each took 21 to 43 ms, and sent after the one before it, a seek's
568
+ // cut over HTTP reached the worklet 64 to 75 ms after the seek, its audio 72 to 83 ms (HOR-888, 2026-10-23)
569
+ for (const block of [here, here - 1, here + 1, here + 2, here + 3]) {
570
+ if (block < 0 || block * BLOCK_BINS >= endBin) continue
569
571
  const start = block * BLOCK_BINS
570
572
  const known = signature(start - MARGIN_BINS, start + BLOCK_BINS + MARGIN_BINS)
571
573
  const last = sent.get(block)
@@ -1064,14 +1066,16 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
1064
1066
  * finds it at all, is taken only once the next search, 250 ms later, peaks within 2 ms of it, clear or not: voiced
1065
1067
  * dialogue repeats with its pitch, so a peak a pitch period off can come out ahead, and a FLAC run once matched 45 ms
1066
1068
  * off with every check passed. Over the whole 250 ms either way an Opus file's matches were never that clear (HOR-498
1067
- * build, 2026-10-17).
1069
+ * build, 2026-10-17). Kept past that next one, a candidate that a match came back to after four elsewhere locked an
1070
+ * Opus run under load 18 ms off, every cut that much late (HOR-888, 2026-10-23).
1068
1071
  */
1069
1072
  found(offset, clear) {
1070
1073
  const near = (other) => other !== null && Math.abs(offset - other) <= 0.002
1071
- if (near(this.candidate)) {
1074
+ const confirmed = near(this.candidate)
1075
+ this.candidate = null
1076
+ if (confirmed) {
1072
1077
  this.offset = offset
1073
1078
  this.doubt = false
1074
- this.candidate = null
1075
1079
  } else if (clear) {
1076
1080
  if (!this.doubt && near(this.offset)) this.offset = offset
1077
1081
  else this.candidate = offset
@@ -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
- void Promise.resolve(renderer.addFonts([defaultFontUrl])).then(repaint, rendererFailed)
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
  }
@@ -1,6 +1,6 @@
1
1
  import type { PlayerMedia } from '../media'
2
2
 
3
- import { useEffect } from 'react'
3
+ import { useEffect, useRef } from 'react'
4
4
 
5
5
  import { usePlayer } from '../player'
6
6
 
@@ -12,6 +12,26 @@ const presented = (video: HTMLVideoElement, timeout: number) => new Promise<void
12
12
  video.requestVideoFrameCallback(() => { clearTimeout(timer); done() })
13
13
  })
14
14
 
15
+ // one press waits for the step on its way, so two quick presses move two frames, and the rest are dropped, so a held key
16
+ // steps as fast as frames land
17
+ const oneAtATime = (step: (direction: 1 | -1) => Promise<void>) => {
18
+ let busy = false
19
+ let next: 1 | -1 | undefined
20
+ const run = async (direction: 1 | -1) => {
21
+ if (busy) { next = direction; return }
22
+ busy = true
23
+ try {
24
+ await step(direction)
25
+ } finally {
26
+ busy = false
27
+ const queued = next
28
+ next = undefined
29
+ if (queued) void run(queued)
30
+ }
31
+ }
32
+ return run
33
+ }
34
+
15
35
  /**
16
36
  * Offers `stepFrame` for a media whose frames this document can see, one with `requestVideoFrameCallback`.
17
37
  *
@@ -23,13 +43,31 @@ const presented = (video: HTMLVideoElement, timeout: number) => new Promise<void
23
43
  * The frame's length is learned from the gaps between frames presented one after another while playing at up to 1x:
24
44
  * faster, a 60 Hz display presents every other frame of a 60 fps file. A step while a seek waits for its data starts
25
45
  * from that seek's target.
46
+ *
47
+ * A media without `requestVideoFrameCallback` is stepped by `hostStep`, when its host can step it.
26
48
  */
27
- export const useFrameStep = (media: PlayerMedia | null) => {
49
+ export const useFrameStep = (media: PlayerMedia | null, hostStep?: (direction: 1 | -1) => Promise<void>) => {
28
50
  const player = usePlayer()
29
51
  const setSourceState = usePlayer((state) => state.setSourceState)
52
+ const host = useRef(hostStep)
53
+ host.current = hostStep
54
+ const hosted = !!hostStep
30
55
  useEffect(() => {
31
56
  const video = media as HTMLVideoElement | null
32
- if (!video || typeof video.requestVideoFrameCallback !== 'function') return
57
+ if (!video) return
58
+ if (typeof video.requestVideoFrameCallback !== 'function') {
59
+ if (!hosted) return
60
+ setSourceState({
61
+ stepFrame: oneAtATime(async (direction) => {
62
+ try {
63
+ await host.current?.(direction)
64
+ } catch (error) {
65
+ console.warn('the host could not step a frame', error)
66
+ }
67
+ }),
68
+ })
69
+ return () => setSourceState({ stepFrame: undefined })
70
+ }
33
71
 
34
72
  let played: VideoFrameCallbackMetadata | undefined
35
73
  let bySeek = false
@@ -66,38 +104,30 @@ export const useFrameStep = (media: PlayerMedia | null) => {
66
104
  return near.reduce((sum, gap) => sum + gap, 0) / near.length
67
105
  }
68
106
 
69
- let busy = false
70
- const stepFrame = async (direction: 1 | -1) => {
71
- // a key repeat while a step is on its way is dropped, so a held key steps as fast as frames land
72
- if (busy) return
73
- busy = true
74
- try {
75
- if (!video.paused) {
76
- video.pause()
77
- // Chrome can still report the frame on screen after the pause
78
- await presented(video, 100)
79
- }
80
- const length = frameLength()
81
- // off `state`: the store has a getter only for the fields it was created with
82
- const pending = player.state.seekingTo
83
- const target = pending !== undefined
84
- ? pending + direction * length
85
- : played
86
- ? played.mediaTime + (direction > 0 ? 1.5 : -0.5) * length
87
- : video.currentTime + direction * length
88
- const time = Math.max(0, Math.min(target, video.duration || target))
89
- const landed = new Promise<void>((done) => {
90
- const timer = setTimeout(done, 1000)
91
- video.addEventListener('seeked', () => { clearTimeout(timer); done() }, { once: true })
92
- })
93
- const { requestSeek } = player.state
94
- if (requestSeek) requestSeek(time)
95
- else video.currentTime = time
96
- await landed
97
- } finally {
98
- busy = false
107
+ const stepFrame = oneAtATime(async (direction) => {
108
+ if (!video.paused) {
109
+ video.pause()
110
+ // Chrome can still report the frame on screen after the pause
111
+ await presented(video, 100)
99
112
  }
100
- }
113
+ const length = frameLength()
114
+ // off `state`: the store has a getter only for the fields it was created with
115
+ const pending = player.state.seekingTo
116
+ const target = pending !== undefined
117
+ ? pending + direction * length
118
+ : played
119
+ ? played.mediaTime + (direction > 0 ? 1.5 : -0.5) * length
120
+ : video.currentTime + direction * length
121
+ const time = Math.max(0, Math.min(target, video.duration || target))
122
+ const landed = new Promise<void>((done) => {
123
+ const timer = setTimeout(done, 1000)
124
+ video.addEventListener('seeked', () => { clearTimeout(timer); done() }, { once: true })
125
+ })
126
+ const { requestSeek } = player.state
127
+ if (requestSeek) requestSeek(time)
128
+ else video.currentTime = time
129
+ await landed
130
+ })
101
131
  setSourceState({ stepFrame })
102
132
  return () => {
103
133
  video.removeEventListener('seeking', onSeeking)
@@ -105,5 +135,5 @@ export const useFrameStep = (media: PlayerMedia | null) => {
105
135
  video.cancelVideoFrameCallback(handle)
106
136
  setSourceState({ stepFrame: undefined })
107
137
  }
108
- }, [media, player, setSourceState])
138
+ }, [media, hosted, player, setSourceState])
109
139
  }
@@ -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
  }
@@ -238,7 +238,10 @@ export type SourceState = {
238
238
  */
239
239
  requestSeek?: (time: number) => void
240
240
 
241
- /** One frame back or forward, pausing first. Undefined for a media whose frames this document cannot see. */
241
+ /**
242
+ * One frame back or forward, pausing first. Undefined for a media whose frames this document cannot see, unless its
243
+ * host steps it (the remote arm's `stepFrame`).
244
+ */
242
245
  stepFrame?: (direction: 1 | -1) => void
243
246
 
244
247
  /** Set when the pipeline fails. Cleared when it recovers. */
@@ -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.
@@ -244,6 +246,15 @@ export type MediaPlayerRemoteOptions =
244
246
  * host takes on by passing it. Read by value, so it may be written inline.
245
247
  */
246
248
  pictureInPicture?: PassThroughPictureInPicture
249
+ /**
250
+ * Steps the media one frame back (-1) or forward (1), made by the host inside the media's own
251
+ * document, where its frames can be seen; pausing first is the host's. Used only for a media
252
+ * without `requestVideoFrameCallback`, as one in another document is: a media with it is stepped
253
+ * by the player, and without either `<` and `>` do nothing. One press before the promise settles
254
+ * waits for it and the rest are dropped, so a held key steps as fast as the host lands them, and
255
+ * a rejection is logged. Read by value, so it may be written inline.
256
+ */
257
+ stepFrame?: (direction: 1 | -1) => Promise<void>
247
258
  }
248
259
 
249
260
  export type MediaPlayerOptions = MediaPlayerLocalOptions | MediaPlayerRemoteOptions
@@ -274,7 +285,7 @@ const PlayerRoot = ({ options, children }: { options: MediaPlayerOptions, childr
274
285
  // permanent no-op.
275
286
  const media = remote?.media ?? video
276
287
  useEffect(() => { setMedia?.(media); return () => setMedia?.(null) }, [media, setMedia])
277
- useFrameStep(media)
288
+ useFrameStep(media, remote?.stepFrame)
278
289
 
279
290
  // Served after it is attached, and re-served when the media changes: what an embedder drives is
280
291
  // whatever this player drives at the time. Keyed on the option's `origin` and `channel`, not on the