@banou/media-player 0.10.45 → 0.10.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -229,31 +229,31 @@ var se = {
|
|
|
229
229
|
z.current = B.current, a.setSourceState({ selectedSubtitleTrack: t }), L.current?.selectSubtitleStream(t);
|
|
230
230
|
let r = V.current.subtitles.find((e) => e.streamIndex === t), i = t === void 0 ? null : u(r) ?? (n ? r?.title?.trim() || "und" : void 0);
|
|
231
231
|
i !== void 0 && re.current?.(i), i && d(H(), i) && W.current?.(!0);
|
|
232
|
-
}, [a, H]), oe = b((e) => {
|
|
233
|
-
let t = L.current;
|
|
234
|
-
if (!
|
|
232
|
+
}, [a, H]), oe = w(0), se = b((e) => {
|
|
233
|
+
let t = ++oe.current, n = L.current;
|
|
234
|
+
if (!n || O <= 0) {
|
|
235
235
|
a.seek(e);
|
|
236
236
|
return;
|
|
237
237
|
}
|
|
238
|
-
let
|
|
239
|
-
if (!
|
|
240
|
-
let
|
|
241
|
-
if (
|
|
242
|
-
console.warn(`[media-player] seek to ${e.toFixed(2)} moved after ${Math.round(performance.now() -
|
|
238
|
+
let r = typeof window < "u" && window.__mediaPlayerSeekDebug, i = performance.now(), o = !1, s = "prepared", c = () => {
|
|
239
|
+
if (!o && (o = !0, L.current === n && oe.current === t && (a.seek(e), r))) {
|
|
240
|
+
let t = n.videoElement, r = 0;
|
|
241
|
+
if (t) for (let n = 0; n < t.buffered.length; n++) t.buffered.start(n) <= e + 1 && e < t.buffered.end(n) && (r = t.buffered.end(n) - e);
|
|
242
|
+
console.warn(`[media-player] seek to ${e.toFixed(2)} moved after ${Math.round(performance.now() - i)}ms via ${s}, runway ${r.toFixed(1)}s${s === "deadline" ? " (EXPOSED: moved before its data was ready)" : ""}`);
|
|
243
243
|
}
|
|
244
244
|
};
|
|
245
245
|
a.setSourceState({ seekingTo: e });
|
|
246
|
-
let
|
|
247
|
-
|
|
248
|
-
},
|
|
249
|
-
|
|
250
|
-
let
|
|
251
|
-
|
|
246
|
+
let l = n.videoElement, u = () => {
|
|
247
|
+
l?.removeEventListener("seeked", u), clearTimeout(d), a.setSourceState({ seekingTo: void 0 });
|
|
248
|
+
}, d = setTimeout(u, De);
|
|
249
|
+
l?.addEventListener("seeked", u);
|
|
250
|
+
let f = setTimeout(() => {
|
|
251
|
+
s = "deadline", c();
|
|
252
252
|
}, O);
|
|
253
|
-
|
|
254
|
-
clearTimeout(
|
|
253
|
+
n.prepareSeek(e).catch(() => {}).finally(() => {
|
|
254
|
+
clearTimeout(f), c();
|
|
255
255
|
});
|
|
256
|
-
}, [a, O]),
|
|
256
|
+
}, [a, O]), Y = b((e) => {
|
|
257
257
|
if (typeof e != "number" || B.current === void 0) return;
|
|
258
258
|
a.setSourceState({ selectedAudioTrack: e }), j({
|
|
259
259
|
size: B.current,
|
|
@@ -261,18 +261,18 @@ var se = {
|
|
|
261
261
|
});
|
|
262
262
|
let t = u(V.current.audio.find((t) => t.streamIndex === e));
|
|
263
263
|
t !== void 0 && ne.current?.(t);
|
|
264
|
-
}, [a]),
|
|
264
|
+
}, [a]), ce = X((e) => e.setSourceState);
|
|
265
265
|
S(() => {
|
|
266
|
-
|
|
266
|
+
ce({
|
|
267
267
|
selectSubtitleTrack: ae,
|
|
268
|
-
selectAudioTrack:
|
|
269
|
-
requestSeek:
|
|
268
|
+
selectAudioTrack: Y,
|
|
269
|
+
requestSeek: se
|
|
270
270
|
});
|
|
271
271
|
}, [
|
|
272
|
-
|
|
272
|
+
ce,
|
|
273
273
|
ae,
|
|
274
|
-
|
|
275
|
-
|
|
274
|
+
Y,
|
|
275
|
+
se
|
|
276
276
|
]), S(() => {
|
|
277
277
|
if (!e || !t || !c || !o) return;
|
|
278
278
|
let n = !1;
|
|
@@ -2678,10 +2678,12 @@ ${Nt}
|
|
|
2678
2678
|
direction: "down",
|
|
2679
2679
|
stepSize: en
|
|
2680
2680
|
});
|
|
2681
|
-
else if (a.key === "ArrowRight") {
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2681
|
+
else if (a.key === "ArrowRight" || a.key === "ArrowLeft") {
|
|
2682
|
+
let e = r.target?.media, t = a.key === "ArrowRight";
|
|
2683
|
+
if (!e?.readyState || t && !r.duration) return;
|
|
2684
|
+
let i = r.state.seekingTo ?? e.currentTime;
|
|
2685
|
+
n(t ? Math.min(i + tn, r.duration) : Math.max(i - tn, 0));
|
|
2686
|
+
} else (a.key === "<" || a.key === ">") && x ? x(a.key === ">" ? 1 : -1) : l = !1;
|
|
2685
2687
|
l && a.preventDefault();
|
|
2686
2688
|
};
|
|
2687
2689
|
return window.addEventListener("keydown", o), window.addEventListener("pointerdown", a, !0), window.addEventListener("focusin", a, !0), () => {
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="@emotion/react/types/css-prop" />
|
|
2
2
|
import type { RefObject } from 'react'
|
|
3
|
+
import type { PlayerMedia } from '../media'
|
|
3
4
|
import type { HostFullscreen } from '../video-player'
|
|
4
5
|
|
|
5
6
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
@@ -252,12 +253,17 @@ export const ControlBar = (
|
|
|
252
253
|
else if (ev.key === 'ArrowDown') {
|
|
253
254
|
modifyVolume({ direction: 'down', stepSize: VOLUME_STEP })
|
|
254
255
|
}
|
|
255
|
-
else if (ev.key === 'ArrowRight') {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
256
|
+
else if (ev.key === 'ArrowRight' || ev.key === 'ArrowLeft') {
|
|
257
|
+
const media = player.target?.media as PlayerMedia | undefined
|
|
258
|
+
const forward = ev.key === 'ArrowRight'
|
|
259
|
+
// Nothing to seek from while a new media or a rebuild has emptied the element: it reads 0, and Chrome 156 lands
|
|
260
|
+
// the seek after the rebuild has resumed (2026-11-21)
|
|
261
|
+
if (!media?.readyState || (forward && !player.duration)) return
|
|
262
|
+
// Where the playhead is going. A seek waiting for its data is only in `seekingTo`, and the store hears of a seek
|
|
263
|
+
// set in this task on the element's queued `seeking`, while the element already reads its target (Chrome 156
|
|
264
|
+
// and Firefox 153, 2026-11-21). Off `state`: the store has a getter only for the fields it was created with.
|
|
265
|
+
const from = player.state.seekingTo ?? media.currentTime
|
|
266
|
+
seek(forward ? Math.min(from + SEEK_STEP, player.duration) : Math.max(from - SEEK_STEP, 0))
|
|
261
267
|
}
|
|
262
268
|
else if ((ev.key === '<' || ev.key === '>') && stepFrame) stepFrame(ev.key === '>' ? 1 : -1)
|
|
263
269
|
else {
|
|
@@ -197,6 +197,15 @@ export const usePlayback = (
|
|
|
197
197
|
if (language && playsIn(playingAudio(), language)) onAlwaysSubtitlesRef.current?.(true)
|
|
198
198
|
}, [player, playingAudio])
|
|
199
199
|
|
|
200
|
+
/*
|
|
201
|
+
* Counts the seeks asked for, so a seek that a newer one replaced never moves the playhead.
|
|
202
|
+
*
|
|
203
|
+
* A newer remuxer task (the newer seek's prepare, or the engine seek its move starts) aborts the older seek's
|
|
204
|
+
* prepare, which then resolves as if its data were in. Firefox 153 landed on the older seek; Chrome 156 moved to it
|
|
205
|
+
* first, into ground with no data (2026-11-21).
|
|
206
|
+
*/
|
|
207
|
+
const seeks = useRef(0)
|
|
208
|
+
|
|
200
209
|
/**
|
|
201
210
|
* Seek with the data already there, or after the deadline, whichever comes first.
|
|
202
211
|
*
|
|
@@ -209,6 +218,7 @@ export const usePlayback = (
|
|
|
209
218
|
* A seek into buffered ground resolves immediately, so scrubbing inside the buffer is unaffected.
|
|
210
219
|
*/
|
|
211
220
|
const requestSeek = useCallback((time: number) => {
|
|
221
|
+
const seek = ++seeks.current
|
|
212
222
|
const controller = controllerRef.current
|
|
213
223
|
// no budget means the feature is off: seek at once and do not spend a read preparing something
|
|
214
224
|
// nobody is going to wait for
|
|
@@ -224,8 +234,8 @@ export const usePlayback = (
|
|
|
224
234
|
* quick taps of the arrow keys would have done the same.
|
|
225
235
|
*
|
|
226
236
|
* The chrome knows what gesture it is in and now says so by only calling this for settled seeks,
|
|
227
|
-
* which is knowledge rather than inference. Rapid calls are safe here anyway: each
|
|
228
|
-
* the last through
|
|
237
|
+
* which is knowledge rather than inference. Rapid calls are safe here anyway: each replaces
|
|
238
|
+
* the last through `seeks`.
|
|
229
239
|
*/
|
|
230
240
|
/*
|
|
231
241
|
* A debug trace, off unless asked for.
|
|
@@ -245,8 +255,9 @@ export const usePlayback = (
|
|
|
245
255
|
const move = () => {
|
|
246
256
|
if (moved) return
|
|
247
257
|
moved = true
|
|
248
|
-
// the pipeline went away
|
|
249
|
-
|
|
258
|
+
// a newer seek replaced this one, or the pipeline went away (a new media starts at its own beginning, and a
|
|
259
|
+
// rebuild resumes at this seek itself)
|
|
260
|
+
if (controllerRef.current !== controller || seeks.current !== seek) return
|
|
250
261
|
player.seek(time)
|
|
251
262
|
if (debug) {
|
|
252
263
|
// eslint-disable-next-line no-console
|