@remotion/player 4.0.537 → 4.0.539

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.
Files changed (42) hide show
  1. package/dist/cjs/BufferingIndicator.js +3 -5
  2. package/dist/cjs/DefaultPlayPauseButton.js +3 -3
  3. package/dist/cjs/EmitterProvider.js +1 -1
  4. package/dist/cjs/MediaVolumeSlider.js +2 -2
  5. package/dist/cjs/PlaybackrateControl.js +18 -8
  6. package/dist/cjs/Player.d.ts +6 -1
  7. package/dist/cjs/Player.js +6 -4
  8. package/dist/cjs/PlayerControls.js +3 -11
  9. package/dist/cjs/PlayerSeekBar.js +1 -5
  10. package/dist/cjs/PlayerTimeLabel.js +1 -1
  11. package/dist/cjs/PlayerUI.d.ts +3 -3
  12. package/dist/cjs/PlayerUI.js +4 -7
  13. package/dist/cjs/SharedPlayerContext.d.ts +1 -0
  14. package/dist/cjs/SharedPlayerContext.js +2 -2
  15. package/dist/cjs/Thumbnail.d.ts +1 -1
  16. package/dist/cjs/Thumbnail.js +1 -1
  17. package/dist/cjs/ThumbnailUI.d.ts +1 -1
  18. package/dist/cjs/ThumbnailUI.js +3 -3
  19. package/dist/cjs/browser-mediasession.js +2 -2
  20. package/dist/cjs/calculate-scale.d.ts +11 -11
  21. package/dist/cjs/error-boundary.js +5 -2
  22. package/dist/cjs/event-emitter.js +88 -84
  23. package/dist/cjs/icons.js +9 -13
  24. package/dist/cjs/index.d.ts +14 -32
  25. package/dist/cjs/index.js +2 -2
  26. package/dist/cjs/license-blacklist.js +1 -1
  27. package/dist/cjs/player-css-classname.d.ts +1 -1
  28. package/dist/cjs/render-volume-slider.js +3 -5
  29. package/dist/cjs/set-global-time-anchor.d.ts +2 -1
  30. package/dist/cjs/timeline-imperative-context.d.ts +11 -0
  31. package/dist/cjs/timeline-imperative-context.js +76 -0
  32. package/dist/cjs/use-hover-state.d.ts +1 -1
  33. package/dist/cjs/use-playback.d.ts +2 -1
  34. package/dist/cjs/use-playback.js +48 -38
  35. package/dist/cjs/use-player-methods.js +9 -8
  36. package/dist/cjs/use-player.d.ts +21 -0
  37. package/dist/cjs/use-player.js +195 -0
  38. package/dist/cjs/use-remotion-license-acknowledge.d.ts +2 -1
  39. package/dist/cjs/utils/calculate-player-size.d.ts +4 -3
  40. package/dist/cjs/volume-persistence.d.ts +2 -1
  41. package/dist/esm/index.mjs +83 -53
  42. package/package.json +5 -5
@@ -23,7 +23,11 @@ const shouldForceAnchorChange = (newState) => {
23
23
  throw new Error(`Unexpected audio context state: ${newState}`);
24
24
  };
25
25
  const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, browserMediaControlsBehavior, getCurrentFrame, muted, }) => {
26
+ var _a, _b, _c;
26
27
  const config = remotion_1.Internals.useUnsafeVideoConfig();
28
+ const fps = (_a = config === null || config === void 0 ? void 0 : config.fps) !== null && _a !== void 0 ? _a : null;
29
+ const durationInFrames = (_b = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _b !== void 0 ? _b : null;
30
+ const compositionId = (_c = config === null || config === void 0 ? void 0 : config.id) !== null && _c !== void 0 ? _c : null;
27
31
  const frame = remotion_1.Internals.Timeline.useTimelinePosition();
28
32
  const playing = remotion_1.Internals.usePlaying();
29
33
  const { pause, emitter, isPlaying } = (0, use_player_methods_js_1.usePlayerMethods)();
@@ -38,6 +42,8 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
38
42
  const isBackgroundedRef = (0, is_backgrounded_js_1.useIsBackgrounded)();
39
43
  const lastTimeUpdateTimestamp = (0, react_2.useRef)(0);
40
44
  const playbackClockRef = (0, react_2.useRef)(null);
45
+ const previousMutedRef = (0, react_2.useRef)(muted);
46
+ const anchoredAudioContextRef = (0, react_2.useRef)(null);
41
47
  (0, browser_mediasession_js_1.useBrowserMediaSession)({
42
48
  browserMediaControlsBehavior,
43
49
  playbackRate,
@@ -52,7 +58,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
52
58
  if (!sharedAudioContext.audioContext) {
53
59
  return;
54
60
  }
55
- if (!config) {
61
+ if (fps === null) {
56
62
  return;
57
63
  }
58
64
  if (muted) {
@@ -61,7 +67,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
61
67
  const changed = (0, set_global_time_anchor_js_1.setGlobalTimeAnchor)({
62
68
  audioContext: sharedAudioContext.audioContext,
63
69
  audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
64
- absoluteTimeInSeconds: frame / config.fps,
70
+ absoluteTimeInSeconds: frame / fps,
65
71
  globalPlaybackRate: playbackRate,
66
72
  logLevel,
67
73
  force: false,
@@ -69,7 +75,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
69
75
  if (changed) {
70
76
  sharedAudioContext.audioSyncAnchorEmitter.dispatch('changed');
71
77
  }
72
- }, [config, frame, logLevel, playbackRate, sharedAudioContext, muted]);
78
+ }, [fps, frame, logLevel, playbackRate, sharedAudioContext, muted]);
73
79
  // When the audio context is suspended, we use the opportunity to
74
80
  // re-anchor the time to be exact.
75
81
  (0, react_1.useLayoutEffect)(() => {
@@ -77,7 +83,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
77
83
  if (!audioContext) {
78
84
  return;
79
85
  }
80
- if (!config) {
86
+ if (fps === null) {
81
87
  return;
82
88
  }
83
89
  if (muted) {
@@ -89,7 +95,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
89
95
  const changed = (0, set_global_time_anchor_js_1.setGlobalTimeAnchor)({
90
96
  audioContext,
91
97
  audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
92
- absoluteTimeInSeconds: getCurrentFrame() / config.fps,
98
+ absoluteTimeInSeconds: getCurrentFrame() / fps,
93
99
  globalPlaybackRate: playbackRate,
94
100
  logLevel,
95
101
  force: true,
@@ -103,18 +109,14 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
103
109
  return () => {
104
110
  audioContext === null || audioContext === void 0 ? void 0 : audioContext.removeEventListener('statechange', callback);
105
111
  };
106
- }, [
107
- config,
108
- getCurrentFrame,
109
- logLevel,
110
- muted,
111
- playbackRate,
112
- sharedAudioContext,
113
- ]);
112
+ }, [fps, getCurrentFrame, logLevel, muted, playbackRate, sharedAudioContext]);
114
113
  (0, react_2.useEffect)(() => {
115
114
  var _a;
116
115
  var _b;
117
- if (!config) {
116
+ const wasMuted = previousMutedRef.current;
117
+ previousMutedRef.current = muted;
118
+ if (fps === null || durationInFrames === null || compositionId === null) {
119
+ playbackClockRef.current = null;
118
120
  return;
119
121
  }
120
122
  if (!playing) {
@@ -122,39 +124,45 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
122
124
  (_a = sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.suspend) === null || _a === void 0 ? void 0 : _a.call(sharedAudioContext);
123
125
  return;
124
126
  }
125
- // Either carry over the previous clock or start a fresh one.
127
+ // Duration and range changes update the endpoint without losing elapsed
128
+ // sub-frame time. A different composition or timebase needs a fresh clock.
126
129
  const previousClock = playbackClockRef.current;
127
- const clock = previousClock !== null &&
128
- previousClock.fps === config.fps &&
129
- previousClock.playbackRate === playbackRate
130
- ? previousClock
131
- : {
130
+ const shouldRestartClock = previousClock === null ||
131
+ previousClock.compositionId !== compositionId ||
132
+ previousClock.fps !== fps ||
133
+ previousClock.playbackRate !== playbackRate;
134
+ const clock = shouldRestartClock
135
+ ? {
136
+ compositionId,
132
137
  startedTime: performance.now(),
133
138
  framesAdvanced: 0,
134
- fps: config.fps,
139
+ fps,
135
140
  playbackRate,
136
- };
141
+ }
142
+ : previousClock;
137
143
  playbackClockRef.current = clock;
138
144
  if ((sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext._experimentalKeepAudioContextAlive) &&
139
145
  sharedAudioContext.audioContext &&
140
146
  !muted) {
141
- // With _experimentalKeepAudioContextAlive, the context clock keeps
142
- // running while frames are not advancing (pauses, buffering, muted playback), so
143
- // the anchor is stale by the length of the stall. Without this mode,
144
- // the 'statechange' listener above re-anchors on the
145
- // suspended-to-running transition, but that transition never happens
146
- // here. Re-anchor from the current frame instead, and tell the audio
147
- // iterators so they drop the nodes they queued against the old
148
- // anchor and reschedule.
147
+ const didUnmute = wasMuted && !muted;
148
+ const didReplaceAudioContext = anchoredAudioContextRef.current !== sharedAudioContext.audioContext;
149
+ const shouldRescheduleAudio = shouldRestartClock || didUnmute || didReplaceAudioContext;
150
+ // The native clock keeps running through pauses and muted playback.
151
+ // These transitions need an exact anchor, as does a replacement context
152
+ // with its own time origin. Other effect re-runs use the drift tolerance
153
+ // so duration changes do not introduce frame-quantized audio shifts.
149
154
  const changed = (0, set_global_time_anchor_js_1.setGlobalTimeAnchor)({
150
155
  audioContext: sharedAudioContext.audioContext,
151
156
  audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
152
- absoluteTimeInSeconds: getCurrentFrame() / config.fps,
157
+ absoluteTimeInSeconds: getCurrentFrame() / fps,
153
158
  globalPlaybackRate: playbackRate,
154
159
  logLevel,
155
- force: true,
160
+ force: shouldRescheduleAudio,
156
161
  });
157
- if (changed) {
162
+ anchoredAudioContextRef.current = sharedAudioContext.audioContext;
163
+ // A changed timebase can invalidate queued audio even if the anchor
164
+ // happens to remain numerically equal (for example at frame zero).
165
+ if (changed || shouldRescheduleAudio) {
158
166
  sharedAudioContext.audioSyncAnchorEmitter.dispatch('changed');
159
167
  }
160
168
  }
@@ -191,7 +199,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
191
199
  (_b = sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.resume) === null || _b === void 0 ? void 0 : _b.call(sharedAudioContext);
192
200
  }
193
201
  const time = performance.now() - clock.startedTime;
194
- const actualLastFrame = outFrame !== null && outFrame !== void 0 ? outFrame : config.durationInFrames - 1;
202
+ const actualLastFrame = outFrame !== null && outFrame !== void 0 ? outFrame : durationInFrames - 1;
195
203
  const actualFirstFrame = inFrame !== null && inFrame !== void 0 ? inFrame : 0;
196
204
  const seekRevision = (_c = seek === null || seek === void 0 ? void 0 : seek.revision.current) !== null && _c !== void 0 ? _c : null;
197
205
  if (seekRevision !== lastSeekRevision) {
@@ -204,7 +212,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
204
212
  time,
205
213
  currentFrame,
206
214
  playbackSpeed: playbackRate,
207
- fps: config.fps,
215
+ fps,
208
216
  actualFirstFrame,
209
217
  actualLastFrame,
210
218
  framesAdvanced: clock.framesAdvanced,
@@ -219,7 +227,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
219
227
  : nextFrame;
220
228
  if (frameToDisplay !== currentFrame && !isBuffering()) {
221
229
  playbackFrame = frameToDisplay;
222
- setFrameFromPlayback((c) => ({ ...c, [config.id]: frameToDisplay }));
230
+ setFrameFromPlayback((c) => ({ ...c, [compositionId]: frameToDisplay }));
223
231
  }
224
232
  if (hasEnded) {
225
233
  stop();
@@ -280,7 +288,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
280
288
  reqAnimFrameCall = {
281
289
  type: 'timeout',
282
290
  // Note: Most likely, this will not be 1000 / fps, but the browser will throttle it to ~1/sec.
283
- id: setTimeout(callback, 1000 / config.fps),
291
+ id: setTimeout(callback, 1000 / fps),
284
292
  };
285
293
  return;
286
294
  }
@@ -302,7 +310,9 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
302
310
  stop();
303
311
  };
304
312
  }, [
305
- config,
313
+ compositionId,
314
+ durationInFrames,
315
+ fps,
306
316
  loop,
307
317
  pause,
308
318
  playing,
@@ -5,13 +5,15 @@ const react_1 = require("react");
5
5
  const remotion_1 = require("remotion");
6
6
  const emitter_context_js_1 = require("./emitter-context.js");
7
7
  const usePlayerMethods = () => {
8
- var _a;
8
+ var _a, _b, _c;
9
9
  const seekFrame = remotion_1.Internals.Timeline.useTimelineSeekFrame();
10
10
  const { setPlaying, frameRef, audioAndVideoTags, isPlaying: readIsPlaying, isBuffering, } = (0, react_1.useContext)(remotion_1.Internals.SetTimelineContext);
11
11
  const audioContext = (0, react_1.useContext)(remotion_1.Internals.SharedAudioContext);
12
12
  const audioTagsContext = (0, react_1.useContext)(remotion_1.Internals.SharedAudioTagsContext);
13
13
  const environment = (0, remotion_1.useRemotionEnvironment)();
14
14
  const video = remotion_1.Internals.useVideo();
15
+ const videoId = (_a = video === null || video === void 0 ? void 0 : video.id) !== null && _a !== void 0 ? _a : null;
16
+ const videoDurationInFrames = (_b = video === null || video === void 0 ? void 0 : video.durationInFrames) !== null && _b !== void 0 ? _b : null;
15
17
  const config = remotion_1.Internals.useUnsafeVideoConfig();
16
18
  const emitter = (0, react_1.useContext)(emitter_context_js_1.PlayerEventEmitterContext);
17
19
  const playStart = (0, react_1.useRef)(0);
@@ -22,16 +24,16 @@ const usePlayerMethods = () => {
22
24
  }
23
25
  const getCurrentFrame = (0, react_1.useCallback)(() => {
24
26
  var _a, _b, _c;
25
- if (!video) {
27
+ if (videoId === null || videoDurationInFrames === null) {
26
28
  return ((_a = fallbackFrame.current) !== null && _a !== void 0 ? _a : (typeof window === 'undefined'
27
29
  ? 0
28
30
  : ((_b = window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0)));
29
31
  }
30
- const unclamped = (_c = frameRef.current[video.id]) !== null && _c !== void 0 ? _c : (environment.isPlayer
32
+ const unclamped = (_c = frameRef.current[videoId]) !== null && _c !== void 0 ? _c : (environment.isPlayer
31
33
  ? 0
32
- : remotion_1.Internals.Timeline.getFrameForComposition(video.id));
33
- return remotion_1.Internals.Timeline.clampFrameToCompositionRange(unclamped, video.durationInFrames);
34
- }, [environment.isPlayer, frameRef, video]);
34
+ : remotion_1.Internals.Timeline.getFrameForComposition(videoId));
35
+ return remotion_1.Internals.Timeline.clampFrameToCompositionRange(unclamped, videoDurationInFrames);
36
+ }, [environment.isPlayer, frameRef, videoId, videoDurationInFrames]);
35
37
  const seek = (0, react_1.useCallback)((newFrame) => {
36
38
  const frameToSeekTo = config
37
39
  ? remotion_1.Internals.TimelinePosition.clampFrameToCompositionRange(newFrame, config.durationInFrames)
@@ -120,8 +122,7 @@ const usePlayerMethods = () => {
120
122
  }
121
123
  }
122
124
  }, [config, emitter, frameRef, readIsPlaying, setPlaying, seekFrame]);
123
- const videoId = video === null || video === void 0 ? void 0 : video.id;
124
- const lastFrame = ((_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1) - 1;
125
+ const lastFrame = ((_c = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _c !== void 0 ? _c : 1) - 1;
125
126
  const frameBack = (0, react_1.useCallback)((frames) => {
126
127
  var _a, _b;
127
128
  if (!videoId) {
@@ -0,0 +1,21 @@
1
+ import type { SyntheticEvent } from 'react';
2
+ import type { PlayerEmitter } from './event-emitter.js';
3
+ type UsePlayerMethods = {
4
+ frameBack: (frames: number) => void;
5
+ frameForward: (frames: number) => void;
6
+ isLastFrame: boolean;
7
+ isFirstFrame: boolean;
8
+ emitter: PlayerEmitter;
9
+ playing: boolean;
10
+ play: (e?: SyntheticEvent | PointerEvent) => void;
11
+ pause: () => void;
12
+ pauseAndReturnToPlayStart: () => void;
13
+ seek: (newFrame: number) => void;
14
+ getCurrentFrame: () => number;
15
+ isPlaying: () => boolean;
16
+ hasPlayed: boolean;
17
+ isBuffering: () => boolean;
18
+ toggle: (e?: SyntheticEvent | PointerEvent) => void;
19
+ };
20
+ export declare const usePlayer: () => UsePlayerMethods;
21
+ export {};
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usePlayer = void 0;
4
+ const react_1 = require("react");
5
+ const remotion_1 = require("remotion");
6
+ const emitter_context_js_1 = require("./emitter-context.js");
7
+ const usePlayer = () => {
8
+ var _a;
9
+ const [playing, setPlaying, imperativePlaying] = remotion_1.Internals.Timeline.usePlayingState();
10
+ const [hasPlayed, setHasPlayed] = (0, react_1.useState)(false);
11
+ const frame = remotion_1.Internals.Timeline.useTimelinePosition();
12
+ const playStart = (0, react_1.useRef)(frame);
13
+ const setFrame = remotion_1.Internals.Timeline.useTimelineSetFrame();
14
+ const setTimelinePosition = remotion_1.Internals.Timeline.useTimelineSetFrame();
15
+ const audioContext = (0, react_1.useContext)(remotion_1.Internals.SharedAudioContext);
16
+ const audioTagsContext = (0, react_1.useContext)(remotion_1.Internals.SharedAudioTagsContext);
17
+ const { audioAndVideoTags } = remotion_1.Internals.useTimelineContext();
18
+ const frameRef = (0, react_1.useRef)(frame);
19
+ frameRef.current = frame;
20
+ const video = remotion_1.Internals.useVideo();
21
+ const config = remotion_1.Internals.useUnsafeVideoConfig();
22
+ const emitter = (0, react_1.useContext)(emitter_context_js_1.PlayerEventEmitterContext);
23
+ const lastFrame = ((_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1) - 1;
24
+ const isLastFrame = frame === lastFrame;
25
+ const isFirstFrame = frame === 0;
26
+ if (!emitter) {
27
+ throw new TypeError('Expected Player event emitter context');
28
+ }
29
+ const bufferingContext = (0, react_1.useContext)(remotion_1.Internals.BufferingContextReact);
30
+ if (!bufferingContext) {
31
+ throw new Error('Missing the buffering context. Most likely you have a Remotion version mismatch.');
32
+ }
33
+ const { buffering } = bufferingContext;
34
+ const seek = (0, react_1.useCallback)((newFrame) => {
35
+ const frameToSeekTo = config
36
+ ? remotion_1.Internals.TimelinePosition.clampFrameToCompositionRange(newFrame, config.durationInFrames)
37
+ : Math.max(0, newFrame);
38
+ if (video === null || video === void 0 ? void 0 : video.id) {
39
+ setTimelinePosition((c) => c[video.id] === frameToSeekTo ? c : { ...c, [video.id]: frameToSeekTo });
40
+ }
41
+ frameRef.current = frameToSeekTo;
42
+ emitter.dispatchSeek(frameToSeekTo);
43
+ }, [config, emitter, setTimelinePosition, video === null || video === void 0 ? void 0 : video.id]);
44
+ const play = (0, react_1.useCallback)((e) => {
45
+ if (imperativePlaying.current) {
46
+ return;
47
+ }
48
+ setHasPlayed(true);
49
+ if (isLastFrame) {
50
+ seek(0);
51
+ }
52
+ audioContext === null || audioContext === void 0 ? void 0 : audioContext.resume();
53
+ /**
54
+ * Play silent audio tags to warm them up for autoplay
55
+ */
56
+ if (audioTagsContext && audioTagsContext.numberOfAudioTags > 0 && e) {
57
+ audioTagsContext.playAllAudios();
58
+ }
59
+ /**
60
+ * Play audios and videos directly here so they can benefit from
61
+ * being triggered by a click
62
+ */
63
+ audioAndVideoTags.current.forEach((a) => a.play('player play() was called and playing audio from a click'));
64
+ imperativePlaying.current = true;
65
+ setPlaying(true);
66
+ playStart.current = frameRef.current;
67
+ emitter.dispatchPlay();
68
+ }, [
69
+ imperativePlaying,
70
+ isLastFrame,
71
+ audioContext,
72
+ audioTagsContext,
73
+ setPlaying,
74
+ emitter,
75
+ seek,
76
+ audioAndVideoTags,
77
+ ]);
78
+ const pause = (0, react_1.useCallback)(() => {
79
+ if (imperativePlaying.current) {
80
+ imperativePlaying.current = false;
81
+ setPlaying(false);
82
+ emitter.dispatchPause();
83
+ audioContext === null || audioContext === void 0 ? void 0 : audioContext.suspend();
84
+ }
85
+ }, [emitter, imperativePlaying, setPlaying, audioContext]);
86
+ const pauseAndReturnToPlayStart = (0, react_1.useCallback)(() => {
87
+ if (imperativePlaying.current) {
88
+ imperativePlaying.current = false;
89
+ frameRef.current = playStart.current;
90
+ if (config) {
91
+ setTimelinePosition((c) => ({
92
+ ...c,
93
+ [config.id]: playStart.current,
94
+ }));
95
+ setPlaying(false);
96
+ emitter.dispatchPause();
97
+ }
98
+ }
99
+ }, [config, emitter, imperativePlaying, setPlaying, setTimelinePosition]);
100
+ const videoId = video === null || video === void 0 ? void 0 : video.id;
101
+ const frameBack = (0, react_1.useCallback)((frames) => {
102
+ if (!videoId) {
103
+ return null;
104
+ }
105
+ if (imperativePlaying.current) {
106
+ return;
107
+ }
108
+ setFrame((c) => {
109
+ var _a, _b;
110
+ const prevFrame = (_b = (_a = c[videoId]) !== null && _a !== void 0 ? _a : window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0;
111
+ const newFrame = Math.max(0, prevFrame - frames);
112
+ if (prevFrame === newFrame) {
113
+ return c;
114
+ }
115
+ return {
116
+ ...c,
117
+ [videoId]: newFrame,
118
+ };
119
+ });
120
+ }, [imperativePlaying, setFrame, videoId]);
121
+ const frameForward = (0, react_1.useCallback)((frames) => {
122
+ if (!videoId) {
123
+ return null;
124
+ }
125
+ if (imperativePlaying.current) {
126
+ return;
127
+ }
128
+ setFrame((c) => {
129
+ var _a, _b;
130
+ const prevFrame = (_b = (_a = c[videoId]) !== null && _a !== void 0 ? _a : window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0;
131
+ const newFrame = Math.min(lastFrame, prevFrame + frames);
132
+ if (prevFrame === newFrame) {
133
+ return c;
134
+ }
135
+ return {
136
+ ...c,
137
+ [videoId]: newFrame,
138
+ };
139
+ });
140
+ }, [videoId, imperativePlaying, lastFrame, setFrame]);
141
+ const toggle = (0, react_1.useCallback)((e) => {
142
+ if (imperativePlaying.current) {
143
+ pause();
144
+ }
145
+ else {
146
+ play(e);
147
+ }
148
+ }, [imperativePlaying, pause, play]);
149
+ const isPlaying = (0, react_1.useCallback)(() => {
150
+ return imperativePlaying.current;
151
+ }, [imperativePlaying]);
152
+ const getCurrentFrame = (0, react_1.useCallback)(() => {
153
+ return frameRef.current;
154
+ }, [frameRef]);
155
+ const isBuffering = (0, react_1.useCallback)(() => {
156
+ return buffering.current;
157
+ }, [buffering]);
158
+ const returnValue = (0, react_1.useMemo)(() => {
159
+ return {
160
+ frameBack,
161
+ frameForward,
162
+ isLastFrame,
163
+ emitter,
164
+ playing,
165
+ play,
166
+ pause,
167
+ seek,
168
+ isFirstFrame,
169
+ getCurrentFrame,
170
+ isPlaying,
171
+ isBuffering,
172
+ pauseAndReturnToPlayStart,
173
+ hasPlayed,
174
+ toggle,
175
+ };
176
+ }, [
177
+ emitter,
178
+ frameBack,
179
+ frameForward,
180
+ hasPlayed,
181
+ isFirstFrame,
182
+ isLastFrame,
183
+ getCurrentFrame,
184
+ pause,
185
+ pauseAndReturnToPlayStart,
186
+ play,
187
+ playing,
188
+ seek,
189
+ toggle,
190
+ isPlaying,
191
+ isBuffering,
192
+ ]);
193
+ return returnValue;
194
+ };
195
+ exports.usePlayer = usePlayer;
@@ -1 +1,2 @@
1
- export declare const acknowledgeRemotionLicenseMessage: (acknowledge: boolean, logLevel: "error" | "info" | "trace" | "verbose" | "warn") => void;
1
+ import { type LogLevel } from 'remotion';
2
+ export declare const acknowledgeRemotionLicenseMessage: (acknowledge: boolean, logLevel: LogLevel) => void;
@@ -1,8 +1,9 @@
1
+ import type { StandardLonghandProperties } from 'csstype';
1
2
  import type { Size } from './use-element-size.js';
2
3
  export declare const calculatePlayerSize: ({ currentSize, width, height, compositionWidth, compositionHeight, }: {
3
4
  currentSize: Size | null;
4
- width: import("csstype").Property.Width<0 | (string & {})> | undefined;
5
- height: import("csstype").Property.Height<0 | (string & {})> | undefined;
5
+ width: StandardLonghandProperties['width'] | undefined;
6
+ height: StandardLonghandProperties['height'] | undefined;
6
7
  compositionWidth: number;
7
8
  compositionHeight: number;
8
- }) => import("react").CSSProperties;
9
+ }) => React.CSSProperties;
@@ -1,2 +1,3 @@
1
- export declare const persistVolume: (volume: number, logLevel: "error" | "info" | "trace" | "verbose" | "warn", volumePersistenceKey: string | null) => void;
1
+ import { type LogLevel } from 'remotion';
2
+ export declare const persistVolume: (volume: number, logLevel: LogLevel, volumePersistenceKey: string | null) => void;
2
3
  export declare const getPreferredVolume: (volumePersistenceKey: string | null) => number;