@banou/media-player 0.10.19 → 0.10.21
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 +29 -22
- package/dist/audio/loudness-analysis.d.ts +30 -0
- package/dist/audio/volume-normalizer.d.ts +4 -2
- package/dist/index.js +841 -623
- package/dist/react/hooks/use-volume-normalizer.d.ts +5 -1
- package/dist/react/video-player.d.ts +11 -7
- package/dist/volume-normalizer-worklet.js +1190 -78
- package/package.json +1 -1
- package/src/lib/audio/loudness-analysis.ts +274 -0
- package/src/lib/audio/volume-normalizer-worklet.d.ts +49 -0
- package/src/lib/audio/volume-normalizer-worklet.js +1190 -78
- package/src/lib/audio/volume-normalizer.ts +5 -3
- package/src/lib/react/components/chrome.tsx +31 -6
- package/src/lib/react/components/control-bar.tsx +1 -0
- package/src/lib/react/hooks/use-volume-normalizer.ts +37 -2
- package/src/lib/react/video-player.tsx +39 -11
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import type { LoudnessSource } from '../../audio/loudness-analysis';
|
|
1
2
|
/**
|
|
2
3
|
* Normalizes the element's volume while `enabled`. Nothing is built until it first is, and turning it off
|
|
3
4
|
* afterwards bypasses rather than unroutes, since an element cannot be handed back. `refused` is true once the
|
|
4
5
|
* engine turned the element down, which leaves it playing exactly as before.
|
|
6
|
+
*
|
|
7
|
+
* With a `source`, the file is also analysed ahead of the playhead while it is on, reading only the byte `ranges`
|
|
8
|
+
* given (all of them when undefined).
|
|
5
9
|
*/
|
|
6
|
-
export declare const useVolumeNormalizer: (video: HTMLVideoElement | null, workletUrl: string | undefined, enabled: boolean) => {
|
|
10
|
+
export declare const useVolumeNormalizer: (video: HTMLVideoElement | null, workletUrl: string | undefined, enabled: boolean, source?: LoudnessSource, ranges?: [number, number][]) => {
|
|
7
11
|
refused: boolean;
|
|
8
12
|
};
|
|
@@ -134,11 +134,12 @@ export type MediaPlayerLocalOptions = CommonOptions & MediaPlayerSource & {
|
|
|
134
134
|
/** Byte spans available, painted on the seekbar and informing the thumbnail generator. */
|
|
135
135
|
downloadedRanges?: DownloadedRange[];
|
|
136
136
|
/**
|
|
137
|
-
* Reader for the thumbnail engine, when it should differ from playback's.
|
|
137
|
+
* Reader for the thumbnail engine and the volume normalizer's analysis, when it should differ from playback's.
|
|
138
138
|
*
|
|
139
139
|
* They are the same by default so generation shares playback's fetch order. A consumer whose
|
|
140
140
|
* reads are not free wants them apart: a torrent hands this a non-prioritising, fail-fast reader
|
|
141
|
-
* so generating previews cannot steal download order from the bytes playback is blocked on.
|
|
141
|
+
* so generating previews cannot steal download order from the bytes playback is blocked on. The
|
|
142
|
+
* analysis asks it only for bytes inside `downloadedRanges`, and with none given, for the whole file.
|
|
142
143
|
*/
|
|
143
144
|
thumbnailRead?: (offset: number, size: number) => Promise<ArrayBuffer>;
|
|
144
145
|
/** Off entirely. A second wasm worker during pipeline boot is worth avoiding on a slow source. */
|
|
@@ -153,10 +154,13 @@ export type MediaPlayerLocalOptions = CommonOptions & MediaPlayerSource & {
|
|
|
153
154
|
*/
|
|
154
155
|
normalizerWorkletUrl?: string;
|
|
155
156
|
/**
|
|
156
|
-
* The settings menu's "Normalize volume" switch:
|
|
157
|
-
*
|
|
158
|
-
* clicks; nothing is saved, so an app that wants it to stick saves what
|
|
159
|
-
* passes it back.
|
|
157
|
+
* The settings menu's "Normalize volume" switch: keeps the file's normal level and turns down what goes well
|
|
158
|
+
* over it, a loud burst before it starts. On by default; pass false for off. The player keeps the switch's
|
|
159
|
+
* state from here and from the viewer's clicks; nothing is saved, so an app that wants it to stick saves what
|
|
160
|
+
* `onNormalizeVolumeChange` reports and passes it back.
|
|
161
|
+
*
|
|
162
|
+
* While it is on the file is read a second time, in a worker, as far as `downloadedRanges` allows, to find the
|
|
163
|
+
* loud parts ahead of the playhead. The sound plays 10 ms behind its input, on or off, once routed.
|
|
160
164
|
*
|
|
161
165
|
* The first time it is on, the element is routed through Web Audio for the rest of its life (off then
|
|
162
166
|
* bypasses). If autoplay rules hold the audio back, that waits for the page's next click, tap or key press, and
|
|
@@ -165,7 +169,7 @@ export type MediaPlayerLocalOptions = CommonOptions & MediaPlayerSource & {
|
|
|
165
169
|
* the element is never routed.
|
|
166
170
|
*/
|
|
167
171
|
normalizeVolume?: boolean;
|
|
168
|
-
/** The viewer flipped the switch
|
|
172
|
+
/** The viewer flipped the switch, to `normalizeVolume`: what an app saves to pass back as `normalizeVolume`. */
|
|
169
173
|
onNormalizeVolumeChange?: (normalizeVolume: boolean) => void;
|
|
170
174
|
};
|
|
171
175
|
/**
|