@banou/media-player 0.10.44 → 0.10.46
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
|
@@ -457,7 +457,7 @@ var se = {
|
|
|
457
457
|
return n.reduce((e, t) => e + t, 0) / n.length;
|
|
458
458
|
}, h = !0, g = Ne(async (e) => {
|
|
459
459
|
if (!h || t.readyState === HTMLMediaElement.HAVE_NOTHING || !t.paused && (t.pause(), await Me(t, 100), !h)) return;
|
|
460
|
-
let r = m(), i = n.state.seekingTo, a = i === void 0 ? o ? o.mediaTime + (e > 0 ? 1.5 : -.5) * r : t.currentTime + e * r : i + e * r, s = Math.max(0, Math.min(a, t.duration || a)), c = new Promise((e) => {
|
|
460
|
+
let r = m(), i = n.state.seekingTo, a = i === void 0 ? o && !t.seeking ? o.mediaTime + (e > 0 ? 1.5 : -.5) * r : t.currentTime + e * r : i + e * r, s = Math.max(0, Math.min(a, t.duration || a)), c = new Promise((e) => {
|
|
461
461
|
let n = () => {
|
|
462
462
|
clearTimeout(r), t.removeEventListener("seeked", n), e();
|
|
463
463
|
}, r = setTimeout(n, 15e3);
|
|
@@ -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), () => {
|
|
@@ -8,8 +8,8 @@ import type { PlayerMedia } from '../media';
|
|
|
8
8
|
* seek presented is never read for its time: Firefox reports the seek's target as its `mediaTime`.
|
|
9
9
|
*
|
|
10
10
|
* The frame's length is learned from the shortest gaps between frames presented one after another while playing at up
|
|
11
|
-
* to 1x: faster, a 60 Hz display presents every other frame of a 60 fps file. A step while a seek
|
|
12
|
-
* starts from that seek's target.
|
|
11
|
+
* to 1x: faster, a 60 Hz display presents every other frame of a 60 fps file. A step while a seek is on its way, or
|
|
12
|
+
* waits for its data, starts from that seek's target.
|
|
13
13
|
*
|
|
14
14
|
* A media without `requestVideoFrameCallback` is stepped by `hostStep`, when its host can step it.
|
|
15
15
|
*/
|
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 {
|
|
@@ -41,8 +41,8 @@ const oneAtATime = (step: (direction: 1 | -1) => Promise<void>) => {
|
|
|
41
41
|
* seek presented is never read for its time: Firefox reports the seek's target as its `mediaTime`.
|
|
42
42
|
*
|
|
43
43
|
* The frame's length is learned from the shortest gaps between frames presented one after another while playing at up
|
|
44
|
-
* to 1x: faster, a 60 Hz display presents every other frame of a 60 fps file. A step while a seek
|
|
45
|
-
* starts from that seek's target.
|
|
44
|
+
* to 1x: faster, a 60 Hz display presents every other frame of a 60 fps file. A step while a seek is on its way, or
|
|
45
|
+
* waits for its data, starts from that seek's target.
|
|
46
46
|
*
|
|
47
47
|
* A media without `requestVideoFrameCallback` is stepped by `hostStep`, when its host can step it.
|
|
48
48
|
*/
|
|
@@ -125,9 +125,11 @@ export const useFrameStep = (media: PlayerMedia | null, hostStep?: (direction: 1
|
|
|
125
125
|
const length = frameLength()
|
|
126
126
|
// off `state`: the store has a getter only for the fields it was created with
|
|
127
127
|
const pending = player.state.seekingTo
|
|
128
|
+
// `seeking` turns true as `currentTime` is set, but the event that clears `played` is queued, so a key handled
|
|
129
|
+
// before it would step from the last frame played (Chrome 156 and Firefox 153, 2026-11-21)
|
|
128
130
|
const target = pending !== undefined
|
|
129
131
|
? pending + direction * length
|
|
130
|
-
: played
|
|
132
|
+
: played && !video.seeking
|
|
131
133
|
? played.mediaTime + (direction > 0 ? 1.5 : -0.5) * length
|
|
132
134
|
: video.currentTime + direction * length
|
|
133
135
|
const time = Math.max(0, Math.min(target, video.duration || target))
|