@remotion/player 4.0.519 → 4.0.520

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.
@@ -3,23 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PlayerEmitterProvider = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
- const remotion_1 = require("remotion");
7
6
  const emitter_context_js_1 = require("./emitter-context.js");
8
7
  const event_emitter_js_1 = require("./event-emitter.js");
9
- const timeline_imperative_context_js_1 = require("./timeline-imperative-context.js");
10
8
  const use_buffer_state_emitter_js_1 = require("./use-buffer-state-emitter.js");
11
9
  const PlayerEmitterProvider = ({ children, currentPlaybackRate }) => {
12
10
  const [emitter] = (0, react_1.useState)(() => new event_emitter_js_1.PlayerEmitter());
13
- const bufferManager = (0, react_1.useContext)(remotion_1.Internals.BufferingContextReact);
14
- if (!bufferManager) {
15
- throw new Error('BufferingContextReact not found');
16
- }
17
11
  (0, react_1.useEffect)(() => {
18
12
  if (currentPlaybackRate) {
19
13
  emitter.dispatchRateChange(currentPlaybackRate);
20
14
  }
21
15
  }, [emitter, currentPlaybackRate]);
22
16
  (0, use_buffer_state_emitter_js_1.useBufferStateEmitter)(emitter);
23
- return (jsx_runtime_1.jsx(timeline_imperative_context_js_1.TimelineImperativeCompatibilityProvider, { children: jsx_runtime_1.jsx(emitter_context_js_1.PlayerEventEmitterContext.Provider, { value: emitter, children: children }) }));
17
+ return (jsx_runtime_1.jsx(emitter_context_js_1.PlayerEventEmitterContext.Provider, { value: emitter, children: children }));
24
18
  };
25
19
  exports.PlayerEmitterProvider = PlayerEmitterProvider;
@@ -91,10 +91,14 @@ const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps,
91
91
  const [frame, setFrame] = (0, react_1.useState)(() => ({
92
92
  [SharedPlayerContext_js_1.PLAYER_COMP_ID]: initialFrame !== null && initialFrame !== void 0 ? initialFrame : 0,
93
93
  }));
94
- const [playing, setPlaying] = (0, react_1.useState)(false);
94
+ const frameRef = (0, react_1.useRef)(frame);
95
+ frameRef.current = frame;
95
96
  const rootRef = (0, react_1.useRef)(null);
96
97
  const audioAndVideoTags = (0, react_1.useRef)([]);
97
- const imperativePlaying = (0, react_1.useRef)(false);
98
+ const playingStore = (0, react_1.useMemo)(() => remotion_1.Internals.createRuntimeValueStore({ playing: false }), []);
99
+ const bufferingStore = (0, react_1.useMemo)(() => remotion_1.Internals.createRuntimeValueStore({ buffering: false }), []);
100
+ const readIsPlaying = (0, react_1.useCallback)(() => playingStore.store.getSnapshot().playing, [playingStore]);
101
+ const readIsBuffering = (0, react_1.useCallback)(() => bufferingStore.store.getSnapshot().buffering, [bufferingStore]);
98
102
  const [currentPlaybackRate, setCurrentPlaybackRate] = (0, react_1.useState)(playbackRate);
99
103
  if (typeof compositionHeight !== 'number') {
100
104
  throw new TypeError(`'compositionHeight' must be a number but got '${typeof compositionHeight}' instead`);
@@ -184,11 +188,10 @@ const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps,
184
188
  const timelineContextValue = (0, react_1.useMemo)(() => {
185
189
  return {
186
190
  frame,
187
- playing,
188
- imperativePlaying,
191
+ isPlaying: readIsPlaying,
189
192
  audioAndVideoTags,
190
193
  };
191
- }, [frame, playing]);
194
+ }, [frame, readIsPlaying]);
192
195
  const playbackRateContextValue = (0, react_1.useMemo)(() => {
193
196
  return {
194
197
  playbackRate: currentPlaybackRate,
@@ -198,9 +201,33 @@ const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps,
198
201
  const setTimelineContextValue = (0, react_1.useMemo)(() => {
199
202
  return {
200
203
  setFrame,
201
- setPlaying,
204
+ setPlaying: (updater) => {
205
+ const current = playingStore.store.getSnapshot().playing;
206
+ const next = typeof updater === 'function' ? updater(current) : updater;
207
+ if (current !== next) {
208
+ playingStore.setSnapshot({ playing: next });
209
+ }
210
+ },
211
+ setBuffering: (buffering) => {
212
+ if (readIsBuffering() !== buffering) {
213
+ bufferingStore.setSnapshot({ buffering });
214
+ }
215
+ },
216
+ subscribePlaying: playingStore.store.subscribe,
217
+ subscribeBuffering: bufferingStore.store.subscribe,
218
+ isPlaying: readIsPlaying,
219
+ isBuffering: readIsBuffering,
220
+ frameRef,
221
+ audioAndVideoTags,
202
222
  };
203
- }, [setFrame]);
223
+ }, [
224
+ bufferingStore,
225
+ setFrame,
226
+ frameRef,
227
+ playingStore,
228
+ readIsBuffering,
229
+ readIsPlaying,
230
+ ]);
204
231
  if (typeof window !== 'undefined') {
205
232
  // eslint-disable-next-line react-hooks/rules-of-hooks
206
233
  (0, react_1.useLayoutEffect)(() => {
@@ -214,7 +241,7 @@ const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps,
214
241
  mode: 'prevent-media-session',
215
242
  });
216
243
  }, [passedBrowserMediaControlsBehavior]);
217
- const player = (jsx_runtime_1.jsx(remotion_1.Internals.IsPlayerContextProvider, { children: jsx_runtime_1.jsx(SharedPlayerContext_js_1.SharedPlayerContexts, { timelineContext: timelineContextValue, playbackRateContext: playbackRateContextValue, component: component, compositionHeight: compositionHeight, compositionWidth: compositionWidth, durationInFrames: durationInFrames, fps: fps, numberOfSharedAudioTags: numberOfSharedAudioTags, initiallyMuted: initiallyMuted, logLevel: logLevel, audioLatencyHint: audioLatencyHint, sampleRate: sampleRate, _experimentalKeepAudioContextAlive: _experimentalKeepAudioContextAlive, volumePersistenceKey: volumePersistenceKey, initialVolume: initialVolume, inputProps: actualInputProps, audioEnabled: true, children: jsx_runtime_1.jsx(remotion_1.Internals.SetTimelineContext.Provider, { value: setTimelineContextValue, children: jsx_runtime_1.jsx(EmitterProvider_js_1.PlayerEmitterProvider, { currentPlaybackRate: currentPlaybackRate, children: jsx_runtime_1.jsx(PlayerUI_js_1.default, { ref: rootRef, posterFillMode: posterFillMode, renderLoading: renderLoading, autoPlay: Boolean(autoPlay), loop: Boolean(loop), controls: Boolean(controls), errorFallback: errorFallback, style: style, inputProps: actualInputProps, allowFullscreen: Boolean(allowFullscreen), moveToBeginningWhenEnded: Boolean(moveToBeginningWhenEnded), clickToPlay: typeof clickToPlay === 'boolean'
244
+ const player = (jsx_runtime_1.jsx(remotion_1.Internals.IsPlayerContextProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.SetTimelineContext.Provider, { value: setTimelineContextValue, children: jsx_runtime_1.jsx(SharedPlayerContext_js_1.SharedPlayerContexts, { timelineContext: timelineContextValue, playbackRateContext: playbackRateContextValue, component: component, compositionHeight: compositionHeight, compositionWidth: compositionWidth, durationInFrames: durationInFrames, fps: fps, numberOfSharedAudioTags: numberOfSharedAudioTags, initiallyMuted: initiallyMuted, logLevel: logLevel, audioLatencyHint: audioLatencyHint, sampleRate: sampleRate, _experimentalKeepAudioContextAlive: _experimentalKeepAudioContextAlive, volumePersistenceKey: volumePersistenceKey, initialVolume: initialVolume, inputProps: actualInputProps, audioEnabled: true, children: jsx_runtime_1.jsx(EmitterProvider_js_1.PlayerEmitterProvider, { currentPlaybackRate: currentPlaybackRate, children: jsx_runtime_1.jsx(PlayerUI_js_1.default, { ref: rootRef, posterFillMode: posterFillMode, renderLoading: renderLoading, autoPlay: Boolean(autoPlay), loop: Boolean(loop), controls: Boolean(controls), errorFallback: errorFallback, style: style, inputProps: actualInputProps, allowFullscreen: Boolean(allowFullscreen), moveToBeginningWhenEnded: Boolean(moveToBeginningWhenEnded), clickToPlay: typeof clickToPlay === 'boolean'
218
245
  ? clickToPlay
219
246
  : Boolean(controls), showVolumeControls: Boolean(showVolumeControls), doubleClickToFullscreen: Boolean(doubleClickToFullscreen), spaceKeyToPlayOrPause: Boolean(spaceKeyToPlayOrPause), playbackRate: currentPlaybackRate, className: className !== null && className !== void 0 ? className : undefined, showPosterWhenUnplayed: Boolean(showPosterWhenUnplayed), showPosterWhenEnded: Boolean(showPosterWhenEnded), showPosterWhenPaused: Boolean(showPosterWhenPaused), showPosterWhenBuffering: Boolean(showPosterWhenBuffering), showPosterWhenBufferingAndPaused: Boolean(showPosterWhenBufferingAndPaused), renderPoster: renderPoster, inFrame: inFrame !== null && inFrame !== void 0 ? inFrame : null, outFrame: outFrame !== null && outFrame !== void 0 ? outFrame : null, initiallyShowControls: initiallyShowControls !== null && initiallyShowControls !== void 0 ? initiallyShowControls : true, renderFullscreen: renderFullscreenButton !== null && renderFullscreenButton !== void 0 ? renderFullscreenButton : null, renderPlayPauseButton: renderPlayPauseButton !== null && renderPlayPauseButton !== void 0 ? renderPlayPauseButton : null, renderMuteButton: renderMuteButton !== null && renderMuteButton !== void 0 ? renderMuteButton : null, renderVolumeSlider: renderVolumeSlider !== null && renderVolumeSlider !== void 0 ? renderVolumeSlider : null, renderCustomControls: renderCustomControls !== null && renderCustomControls !== void 0 ? renderCustomControls : null, alwaysShowControls: alwaysShowControls, showPlaybackRateControl: showPlaybackRateControl, bufferStateDelayInMilliseconds: bufferStateDelayInMilliseconds !== null && bufferStateDelayInMilliseconds !== void 0 ? bufferStateDelayInMilliseconds : 300, hideControlsWhenPointerDoesntMove: hideControlsWhenPointerDoesntMove, overflowVisible: overflowVisible, browserMediaControlsBehavior: browserMediaControlsBehavior, overrideInternalClassName: overrideInternalClassName !== null && overrideInternalClassName !== void 0 ? overrideInternalClassName : undefined, noSuspense: Boolean(noSuspense) }) }) }) }) }));
220
247
  if (!onTimelineSequenceChange) {
@@ -74,7 +74,7 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
74
74
  document.webkitFullscreenEnabled);
75
75
  }, []);
76
76
  const player = (0, use_player_methods_js_1.usePlayerMethods)();
77
- const [playing] = remotion_1.Internals.Timeline.usePlayingState();
77
+ const playing = remotion_1.Internals.usePlaying();
78
78
  const frame = remotion_1.Internals.Timeline.useTimelinePosition();
79
79
  const play = (0, react_1.useCallback)((e) => {
80
80
  if (player.isPlaying()) {
@@ -437,15 +437,11 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
437
437
  }
438
438
  const shouldShowPoster = poster &&
439
439
  [
440
- showPosterWhenPaused && !player.isPlaying() && !seeking,
441
- showPosterWhenEnded &&
442
- frame === durationInFrames - 1 &&
443
- !player.isPlaying(),
444
- showPosterWhenUnplayed && !hasPlayed && !player.isPlaying(),
445
- showPosterWhenBuffering && showBufferIndicator && player.isPlaying(),
446
- showPosterWhenBufferingAndPaused &&
447
- showBufferIndicator &&
448
- !player.isPlaying(),
440
+ showPosterWhenPaused && !playing && !seeking,
441
+ showPosterWhenEnded && frame === durationInFrames - 1 && !playing,
442
+ showPosterWhenUnplayed && !hasPlayed && !playing,
443
+ showPosterWhenBuffering && showBufferIndicator && playing,
444
+ showPosterWhenBufferingAndPaused && showBufferIndicator && !playing,
449
445
  ].some(Boolean);
450
446
  const { left, top, width, height, ...outerWithoutScale } = outer;
451
447
  const content = (jsx_runtime_1.jsxs(jsx_runtime_1.Fragment, { children: [
@@ -4,7 +4,6 @@ exports.SharedPlayerContexts = exports.PLAYER_COMP_ID = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const remotion_1 = require("remotion");
7
- const timeline_imperative_context_js_1 = require("./timeline-imperative-context.js");
8
7
  const volume_persistence_js_1 = require("./volume-persistence.js");
9
8
  exports.PLAYER_COMP_ID = 'player-comp';
10
9
  const SharedPlayerContexts = ({ children, timelineContext, playbackRateContext, fps, compositionHeight, compositionWidth, durationInFrames, component, numberOfSharedAudioTags, initiallyMuted, logLevel, audioLatencyHint, sampleRate, volumePersistenceKey, initialVolume, inputProps, audioEnabled, _experimentalKeepAudioContextAlive, }) => {
@@ -19,7 +18,7 @@ const SharedPlayerContexts = ({ children, timelineContext, playbackRateContext,
19
18
  width: compositionWidth,
20
19
  fps,
21
20
  id: exports.PLAYER_COMP_ID,
22
- nonce: [[0, 777]],
21
+ order: null,
23
22
  folderName: null,
24
23
  parentFolderName: null,
25
24
  schema: null,
@@ -94,15 +93,6 @@ const SharedPlayerContexts = ({ children, timelineContext, playbackRateContext,
94
93
  isReadOnlyStudio: false,
95
94
  };
96
95
  }, []);
97
- const frameRef = (0, react_1.useRef)(timelineContext.frame);
98
- frameRef.current = timelineContext.frame;
99
- const timelineImperativeContextValue = (0, react_1.useMemo)(() => {
100
- return {
101
- frameRef,
102
- imperativePlaying: timelineContext.imperativePlaying,
103
- audioAndVideoTags: timelineContext.audioAndVideoTags,
104
- };
105
- }, [timelineContext.audioAndVideoTags, timelineContext.imperativePlaying]);
106
- return (jsx_runtime_1.jsx(remotion_1.Internals.RemotionEnvironmentContext.Provider, { value: env, children: jsx_runtime_1.jsx(remotion_1.Internals.LogLevelContext.Provider, { value: logLevelContext, children: jsx_runtime_1.jsx(remotion_1.Internals.CanUseRemotionHooksProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.AbsoluteTimeContext.Provider, { value: timelineContext, children: jsx_runtime_1.jsx(remotion_1.Internals.PlaybackRateContext.Provider, { value: playbackRateContext, children: jsx_runtime_1.jsx(timeline_imperative_context_js_1.CoreTimelineImperativeContextProvider, { value: timelineImperativeContextValue, children: jsx_runtime_1.jsx(remotion_1.Internals.TimelineContext.Provider, { value: timelineContext, children: jsx_runtime_1.jsx(remotion_1.Internals.CompositionManager.Provider, { value: compositionManagerContext, children: jsx_runtime_1.jsx(remotion_1.Internals.PrefetchProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.DurationsContextProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.MediaVolumeContext.Provider, { value: mediaVolumeContextValue, children: jsx_runtime_1.jsx(remotion_1.Internals.SetMediaVolumeContext.Provider, { value: setMediaVolumeContextValue, children: jsx_runtime_1.jsx(remotion_1.Internals.BufferingProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.SharedAudioContextProvider, { audioLatencyHint: audioLatencyHint, audioEnabled: shouldCreateAudioContext, previewSampleRate: sampleRate, _experimentalKeepAudioContextAlive: _experimentalKeepAudioContextAlive, children: jsx_runtime_1.jsx(remotion_1.Internals.SharedAudioTagsContextProvider, { numberOfAudioTags: numberOfSharedAudioTags, children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
96
+ return (jsx_runtime_1.jsx(remotion_1.Internals.RemotionEnvironmentContext.Provider, { value: env, children: jsx_runtime_1.jsx(remotion_1.Internals.LogLevelContext.Provider, { value: logLevelContext, children: jsx_runtime_1.jsx(remotion_1.Internals.CanUseRemotionHooksProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.AbsoluteTimeContext.Provider, { value: timelineContext, children: jsx_runtime_1.jsx(remotion_1.Internals.PlaybackRateContext.Provider, { value: playbackRateContext, children: jsx_runtime_1.jsx(remotion_1.Internals.TimelineContext.Provider, { value: timelineContext, children: jsx_runtime_1.jsx(remotion_1.Internals.CompositionManager.Provider, { value: compositionManagerContext, children: jsx_runtime_1.jsx(remotion_1.Internals.PrefetchProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.DurationsContextProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.MediaVolumeContext.Provider, { value: mediaVolumeContextValue, children: jsx_runtime_1.jsx(remotion_1.Internals.SetMediaVolumeContext.Provider, { value: setMediaVolumeContextValue, children: jsx_runtime_1.jsx(remotion_1.Internals.BufferingProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.SharedAudioContextProvider, { audioLatencyHint: audioLatencyHint, audioEnabled: shouldCreateAudioContext, previewSampleRate: sampleRate, _experimentalKeepAudioContextAlive: _experimentalKeepAudioContextAlive, children: jsx_runtime_1.jsx(remotion_1.Internals.SharedAudioTagsContextProvider, { numberOfAudioTags: numberOfSharedAudioTags, children: children }) }) }) }) }) }) }) }) }) }) }) }) }) }));
107
97
  };
108
98
  exports.SharedPlayerContexts = SharedPlayerContexts;
@@ -19,15 +19,14 @@ const ThumbnailFn = ({ frameToDisplay, style, inputProps, compositionHeight, com
19
19
  }, []);
20
20
  }
21
21
  const rootRef = (0, react_1.useRef)(null);
22
- const imperativePlaying = (0, react_1.useRef)(false);
23
22
  const audioAndVideoTags = (0, react_1.useRef)([]);
23
+ const bufferingStore = (0, react_1.useMemo)(() => remotion_1.Internals.createRuntimeValueStore({ buffering: false }), []);
24
24
  const timelineState = (0, react_1.useMemo)(() => {
25
25
  const value = {
26
- playing: false,
26
+ isPlaying: () => false,
27
27
  frame: {
28
28
  [SharedPlayerContext_js_1.PLAYER_COMP_ID]: frameToDisplay,
29
29
  },
30
- imperativePlaying,
31
30
  audioAndVideoTags,
32
31
  };
33
32
  return value;
@@ -40,6 +39,25 @@ const ThumbnailFn = ({ frameToDisplay, style, inputProps, compositionHeight, com
40
39
  },
41
40
  };
42
41
  }, []);
42
+ const frameRef = (0, react_1.useRef)(timelineState.frame);
43
+ frameRef.current = timelineState.frame;
44
+ const setTimelineContext = (0, react_1.useMemo)(() => {
45
+ return {
46
+ setFrame: () => undefined,
47
+ setPlaying: () => undefined,
48
+ setBuffering: (buffering) => {
49
+ if (bufferingStore.store.getSnapshot().buffering !== buffering) {
50
+ bufferingStore.setSnapshot({ buffering });
51
+ }
52
+ },
53
+ subscribePlaying: () => () => undefined,
54
+ subscribeBuffering: bufferingStore.store.subscribe,
55
+ isPlaying: () => false,
56
+ isBuffering: () => bufferingStore.store.getSnapshot().buffering,
57
+ frameRef,
58
+ audioAndVideoTags,
59
+ };
60
+ }, [bufferingStore]);
43
61
  (0, react_1.useImperativeHandle)(ref, () => rootRef.current, []);
44
62
  const Component = remotion_1.Internals.useLazyComponent({
45
63
  compProps: componentProps,
@@ -50,7 +68,7 @@ const ThumbnailFn = ({ frameToDisplay, style, inputProps, compositionHeight, com
50
68
  const passedInputProps = (0, react_1.useMemo)(() => {
51
69
  return inputProps !== null && inputProps !== void 0 ? inputProps : {};
52
70
  }, [inputProps]);
53
- return (jsx_runtime_1.jsx(remotion_1.Internals.IsPlayerContextProvider, { children: jsx_runtime_1.jsx(SharedPlayerContext_js_1.SharedPlayerContexts, { timelineContext: timelineState, playbackRateContext: playbackRateContext, component: Component, compositionHeight: compositionHeight, compositionWidth: compositionWidth, durationInFrames: durationInFrames, fps: fps, numberOfSharedAudioTags: 0, initiallyMuted: true, logLevel: logLevel, audioLatencyHint: "playback", sampleRate: 48000, inputProps: passedInputProps, audioEnabled: false, _experimentalKeepAudioContextAlive: false, children: jsx_runtime_1.jsx(emitter_context_js_1.ThumbnailEmitterContext.Provider, { value: emitter, children: jsx_runtime_1.jsx(ThumbnailUI_js_1.default, { ref: rootRef, className: className, errorFallback: errorFallback, inputProps: passedInputProps, renderLoading: renderLoading, style: style, overflowVisible: overflowVisible, overrideInternalClassName: overrideInternalClassName, noSuspense: Boolean(noSuspense) }) }) }) }));
71
+ return (jsx_runtime_1.jsx(remotion_1.Internals.IsPlayerContextProvider, { children: jsx_runtime_1.jsx(remotion_1.Internals.SetTimelineContext.Provider, { value: setTimelineContext, children: jsx_runtime_1.jsx(SharedPlayerContext_js_1.SharedPlayerContexts, { timelineContext: timelineState, playbackRateContext: playbackRateContext, component: Component, compositionHeight: compositionHeight, compositionWidth: compositionWidth, durationInFrames: durationInFrames, fps: fps, numberOfSharedAudioTags: 0, initiallyMuted: true, logLevel: logLevel, audioLatencyHint: "playback", sampleRate: 48000, inputProps: passedInputProps, audioEnabled: false, _experimentalKeepAudioContextAlive: false, children: jsx_runtime_1.jsx(emitter_context_js_1.ThumbnailEmitterContext.Provider, { value: emitter, children: jsx_runtime_1.jsx(ThumbnailUI_js_1.default, { ref: rootRef, className: className, errorFallback: errorFallback, inputProps: passedInputProps, renderLoading: renderLoading, style: style, overflowVisible: overflowVisible, overrideInternalClassName: overrideInternalClassName, noSuspense: Boolean(noSuspense) }) }) }) }) }));
54
72
  };
55
73
  const forward = react_1.forwardRef;
56
74
  /*
@@ -5,15 +5,13 @@ const react_1 = require("react");
5
5
  const remotion_1 = require("remotion");
6
6
  const use_player_methods_js_1 = require("./use-player-methods.js");
7
7
  const useBrowserMediaSession = ({ browserMediaControlsBehavior, videoConfig, playbackRate, }) => {
8
- const [playing] = remotion_1.Internals.Timeline.usePlayingState();
8
+ const playing = remotion_1.Internals.usePlaying();
9
9
  const { pause, play, emitter, getCurrentFrame, seek } = (0, use_player_methods_js_1.usePlayerMethods)();
10
10
  const hasEverPlayed = (0, react_1.useRef)(false);
11
11
  (0, react_1.useEffect)(() => {
12
12
  if (playing) {
13
13
  hasEverPlayed.current = true;
14
14
  }
15
- }, [playing]);
16
- (0, react_1.useEffect)(() => {
17
15
  if (!navigator.mediaSession) {
18
16
  return;
19
17
  }
@@ -4,23 +4,16 @@ exports.useBufferStateEmitter = void 0;
4
4
  const react_1 = require("react");
5
5
  const remotion_1 = require("remotion");
6
6
  const useBufferStateEmitter = (emitter) => {
7
- const bufferManager = (0, react_1.useContext)(remotion_1.Internals.BufferingContextReact);
8
- if (!bufferManager) {
9
- throw new Error('BufferingContextReact not found');
10
- }
7
+ const { subscribeBuffering } = (0, react_1.useContext)(remotion_1.Internals.SetTimelineContext);
11
8
  (0, react_1.useLayoutEffect)(() => {
12
- const clear1 = bufferManager.listenForBuffering(() => {
13
- bufferManager.buffering.current = true;
14
- emitter.dispatchWaiting({});
9
+ return subscribeBuffering((state) => {
10
+ if (state.buffering) {
11
+ emitter.dispatchWaiting({});
12
+ }
13
+ else {
14
+ emitter.dispatchResume({});
15
+ }
15
16
  });
16
- const clear2 = bufferManager.listenForResume(() => {
17
- bufferManager.buffering.current = false;
18
- emitter.dispatchResume({});
19
- });
20
- return () => {
21
- clear1.remove();
22
- clear2.remove();
23
- };
24
- }, [bufferManager, emitter]);
17
+ }, [emitter, subscribeBuffering]);
25
18
  };
26
19
  exports.useBufferStateEmitter = useBufferStateEmitter;
@@ -25,21 +25,18 @@ const shouldForceAnchorChange = (newState) => {
25
25
  const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, browserMediaControlsBehavior, getCurrentFrame, muted, }) => {
26
26
  const config = remotion_1.Internals.useUnsafeVideoConfig();
27
27
  const frame = remotion_1.Internals.Timeline.useTimelinePosition();
28
- const [playing] = remotion_1.Internals.Timeline.usePlayingState();
28
+ const playing = remotion_1.Internals.usePlaying();
29
29
  const { pause, emitter, isPlaying } = (0, use_player_methods_js_1.usePlayerMethods)();
30
30
  const setFrame = remotion_1.Internals.Timeline.useTimelineSetFrame();
31
31
  const sharedAudioContext = (0, react_2.useContext)(remotion_1.Internals.SharedAudioContext);
32
32
  const { setPlayerMuted } = (0, react_2.useContext)(remotion_1.Internals.SetMediaVolumeContext);
33
+ const { isBuffering, subscribeBuffering } = (0, react_2.useContext)(remotion_1.Internals.SetTimelineContext);
33
34
  const logLevel = remotion_1.Internals.useLogLevel();
34
35
  // requestAnimationFrame() does not work if the tab is not active.
35
36
  // This means that audio will keep playing even if it has ended.
36
37
  // In that case, we use setTimeout() instead.
37
38
  const isBackgroundedRef = (0, is_backgrounded_js_1.useIsBackgrounded)();
38
39
  const lastTimeUpdateTimestamp = (0, react_2.useRef)(0);
39
- const context = (0, react_2.useContext)(remotion_1.Internals.BufferingContextReact);
40
- if (!context) {
41
- throw new Error('Missing the buffering context. Most likely you have a Remotion version mismatch.');
42
- }
43
40
  (0, browser_mediasession_js_1.useBrowserMediaSession)({
44
41
  browserMediaControlsBehavior,
45
42
  playbackRate,
@@ -170,7 +167,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
170
167
  (_a = sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.suspend) === null || _a === void 0 ? void 0 : _a.call(sharedAudioContext);
171
168
  return;
172
169
  }
173
- if (!muted && !audioContextFailed && !context.buffering.current) {
170
+ if (!muted && !audioContextFailed && !isBuffering()) {
174
171
  (_b = sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.resume) === null || _b === void 0 ? void 0 : _b.call(sharedAudioContext);
175
172
  }
176
173
  const time = performance.now() - startedTime;
@@ -190,7 +187,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
190
187
  framesAdvanced += framesToAdvance;
191
188
  if (nextFrame !== getCurrentFrame() &&
192
189
  (!hasEnded || moveToBeginningWhenEnded) &&
193
- !context.buffering.current) {
190
+ !isBuffering()) {
194
191
  setFrame((c) => ({ ...c, [config.id]: nextFrame }));
195
192
  }
196
193
  if (hasEnded) {
@@ -226,12 +223,15 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
226
223
  });
227
224
  return;
228
225
  }
229
- if (context.buffering.current) {
226
+ if (isBuffering()) {
230
227
  if (!muted && !audioContextFailed) {
231
228
  (_b = sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.suspend) === null || _b === void 0 ? void 0 : _b.call(sharedAudioContext);
232
229
  }
233
- const stopListening = context.listenForResume(() => {
234
- stopListening.remove();
230
+ const unsubscribe = subscribeBuffering((state) => {
231
+ if (state.buffering) {
232
+ return;
233
+ }
234
+ unsubscribe();
235
235
  if (!muted &&
236
236
  !audioContextFailed &&
237
237
  (sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext._experimentalKeepAudioContextAlive)) {
@@ -281,10 +281,11 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
281
281
  moveToBeginningWhenEnded,
282
282
  isBackgroundedRef,
283
283
  getCurrentFrame,
284
- context,
284
+ isBuffering,
285
285
  isPlaying,
286
286
  sharedAudioContext,
287
287
  setPlayerMuted,
288
+ subscribeBuffering,
288
289
  logLevel,
289
290
  muted,
290
291
  ]);
@@ -4,13 +4,11 @@ exports.usePlayerMethods = void 0;
4
4
  const react_1 = require("react");
5
5
  const remotion_1 = require("remotion");
6
6
  const emitter_context_js_1 = require("./emitter-context.js");
7
- const timeline_imperative_context_js_1 = require("./timeline-imperative-context.js");
8
7
  const usePlayerMethods = () => {
9
8
  var _a;
10
9
  const setFrame = remotion_1.Internals.Timeline.useTimelineSetFrame();
11
10
  const setTimelinePosition = remotion_1.Internals.Timeline.useTimelineSetFrame();
12
- const { setPlaying } = (0, react_1.useContext)(remotion_1.Internals.SetTimelineContext);
13
- const timelineImperativeContext = (0, react_1.useContext)((0, timeline_imperative_context_js_1.getTimelineImperativeContext)());
11
+ const { setPlaying, frameRef, audioAndVideoTags, isPlaying: readIsPlaying, isBuffering, } = (0, react_1.useContext)(remotion_1.Internals.SetTimelineContext);
14
12
  const audioContext = (0, react_1.useContext)(remotion_1.Internals.SharedAudioContext);
15
13
  const audioTagsContext = (0, react_1.useContext)(remotion_1.Internals.SharedAudioTagsContext);
16
14
  const environment = (0, remotion_1.useRemotionEnvironment)();
@@ -19,16 +17,9 @@ const usePlayerMethods = () => {
19
17
  const emitter = (0, react_1.useContext)(emitter_context_js_1.PlayerEventEmitterContext);
20
18
  const playStart = (0, react_1.useRef)(0);
21
19
  const fallbackFrame = (0, react_1.useRef)(null);
22
- if (!timelineImperativeContext) {
23
- throw new Error('Timeline imperative context is not available. This hook must be used inside a <Player> or the Remotion Studio.');
24
- }
25
20
  if (!emitter) {
26
21
  throw new TypeError('Expected Player event emitter context');
27
22
  }
28
- const bufferingContext = (0, react_1.useContext)(remotion_1.Internals.BufferingContextReact);
29
- if (!bufferingContext) {
30
- throw new Error('Missing the buffering context. Most likely you have a Remotion version mismatch.');
31
- }
32
23
  const getCurrentFrame = (0, react_1.useCallback)(() => {
33
24
  var _a, _b, _c;
34
25
  if (!video) {
@@ -36,20 +27,20 @@ const usePlayerMethods = () => {
36
27
  ? 0
37
28
  : ((_b = window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0)));
38
29
  }
39
- const unclamped = (_c = timelineImperativeContext.frameRef.current[video.id]) !== null && _c !== void 0 ? _c : (environment.isPlayer
30
+ const unclamped = (_c = frameRef.current[video.id]) !== null && _c !== void 0 ? _c : (environment.isPlayer
40
31
  ? 0
41
32
  : remotion_1.Internals.Timeline.getFrameForComposition(video.id));
42
33
  return remotion_1.Internals.Timeline.clampFrameToCompositionRange(unclamped, video.durationInFrames);
43
- }, [environment.isPlayer, timelineImperativeContext, video]);
34
+ }, [environment.isPlayer, frameRef, video]);
44
35
  const seek = (0, react_1.useCallback)((newFrame) => {
45
36
  const frameToSeekTo = config
46
37
  ? remotion_1.Internals.TimelinePosition.clampFrameToCompositionRange(newFrame, config.durationInFrames)
47
38
  : Math.max(0, newFrame);
48
39
  fallbackFrame.current = frameToSeekTo;
49
40
  if (video === null || video === void 0 ? void 0 : video.id) {
50
- if (timelineImperativeContext.frameRef.current[video.id] !== frameToSeekTo) {
51
- timelineImperativeContext.frameRef.current = {
52
- ...timelineImperativeContext.frameRef.current,
41
+ if (frameRef.current[video.id] !== frameToSeekTo) {
42
+ frameRef.current = {
43
+ ...frameRef.current,
53
44
  [video.id]: frameToSeekTo,
54
45
  };
55
46
  }
@@ -58,16 +49,10 @@ const usePlayerMethods = () => {
58
49
  : { ...currentFrames, [video.id]: frameToSeekTo });
59
50
  }
60
51
  emitter.dispatchSeek(frameToSeekTo);
61
- }, [
62
- config,
63
- emitter,
64
- setTimelinePosition,
65
- timelineImperativeContext,
66
- video === null || video === void 0 ? void 0 : video.id,
67
- ]);
52
+ }, [config, emitter, frameRef, setTimelinePosition, video === null || video === void 0 ? void 0 : video.id]);
68
53
  const play = (0, react_1.useCallback)((e) => {
69
54
  var _a;
70
- if (timelineImperativeContext.imperativePlaying.current) {
55
+ if (readIsPlaying()) {
71
56
  return;
72
57
  }
73
58
  const lastFrameForPlayback = ((_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1) - 1;
@@ -85,52 +70,51 @@ const usePlayerMethods = () => {
85
70
  * Play audios and videos directly here so they can benefit from
86
71
  * being triggered by a click
87
72
  */
88
- timelineImperativeContext.audioAndVideoTags.current.forEach((tag) => tag.play('player play() was called and playing audio from a click'));
89
- timelineImperativeContext.imperativePlaying.current = true;
73
+ audioAndVideoTags.current.forEach((tag) => tag.play('player play() was called and playing audio from a click'));
90
74
  setPlaying(true);
91
75
  playStart.current = getCurrentFrame();
92
76
  emitter.dispatchPlay();
93
77
  }, [
78
+ audioAndVideoTags,
94
79
  audioContext,
95
80
  audioTagsContext,
96
81
  config === null || config === void 0 ? void 0 : config.durationInFrames,
97
82
  emitter,
98
83
  getCurrentFrame,
84
+ readIsPlaying,
99
85
  seek,
100
86
  setPlaying,
101
- timelineImperativeContext,
102
87
  ]);
103
88
  const pause = (0, react_1.useCallback)(() => {
104
- if (timelineImperativeContext.imperativePlaying.current) {
105
- timelineImperativeContext.imperativePlaying.current = false;
89
+ if (readIsPlaying()) {
106
90
  setPlaying(false);
107
91
  emitter.dispatchPause();
108
92
  audioContext === null || audioContext === void 0 ? void 0 : audioContext.suspend();
109
93
  }
110
- }, [audioContext, emitter, setPlaying, timelineImperativeContext]);
94
+ }, [audioContext, emitter, readIsPlaying, setPlaying]);
111
95
  const pauseAndReturnToPlayStart = (0, react_1.useCallback)(() => {
112
- if (timelineImperativeContext.imperativePlaying.current) {
113
- timelineImperativeContext.imperativePlaying.current = false;
96
+ if (readIsPlaying()) {
97
+ setPlaying(false);
114
98
  fallbackFrame.current = playStart.current;
115
99
  if (config) {
116
- timelineImperativeContext.frameRef.current = {
117
- ...timelineImperativeContext.frameRef.current,
100
+ frameRef.current = {
101
+ ...frameRef.current,
118
102
  [config.id]: playStart.current,
119
103
  };
120
104
  setTimelinePosition((currentFrames) => ({
121
105
  ...currentFrames,
122
106
  [config.id]: playStart.current,
123
107
  }));
124
- setPlaying(false);
125
108
  emitter.dispatchPause();
126
109
  }
127
110
  }
128
111
  }, [
129
112
  config,
130
113
  emitter,
114
+ frameRef,
115
+ readIsPlaying,
131
116
  setPlaying,
132
117
  setTimelinePosition,
133
- timelineImperativeContext,
134
118
  ]);
135
119
  const videoId = video === null || video === void 0 ? void 0 : video.id;
136
120
  const lastFrame = ((_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1) - 1;
@@ -139,57 +123,51 @@ const usePlayerMethods = () => {
139
123
  if (!videoId) {
140
124
  return null;
141
125
  }
142
- if (timelineImperativeContext.imperativePlaying.current) {
126
+ if (readIsPlaying()) {
143
127
  return;
144
128
  }
145
- const previousFrame = (_b = (_a = timelineImperativeContext.frameRef.current[videoId]) !== null && _a !== void 0 ? _a : window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0;
129
+ const previousFrame = (_b = (_a = frameRef.current[videoId]) !== null && _a !== void 0 ? _a : window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0;
146
130
  const newFrame = Math.max(0, previousFrame - frames);
147
131
  if (previousFrame === newFrame) {
148
132
  return;
149
133
  }
150
- timelineImperativeContext.frameRef.current = {
151
- ...timelineImperativeContext.frameRef.current,
134
+ frameRef.current = {
135
+ ...frameRef.current,
152
136
  [videoId]: newFrame,
153
137
  };
154
138
  setFrame((currentFrames) => currentFrames[videoId] === newFrame
155
139
  ? currentFrames
156
140
  : { ...currentFrames, [videoId]: newFrame });
157
- }, [setFrame, timelineImperativeContext, videoId]);
141
+ }, [frameRef, readIsPlaying, setFrame, videoId]);
158
142
  const frameForward = (0, react_1.useCallback)((frames) => {
159
143
  var _a, _b;
160
144
  if (!videoId) {
161
145
  return null;
162
146
  }
163
- if (timelineImperativeContext.imperativePlaying.current) {
147
+ if (readIsPlaying()) {
164
148
  return;
165
149
  }
166
- const previousFrame = (_b = (_a = timelineImperativeContext.frameRef.current[videoId]) !== null && _a !== void 0 ? _a : window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0;
150
+ const previousFrame = (_b = (_a = frameRef.current[videoId]) !== null && _a !== void 0 ? _a : window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0;
167
151
  const newFrame = Math.min(lastFrame, previousFrame + frames);
168
152
  if (previousFrame === newFrame) {
169
153
  return;
170
154
  }
171
- timelineImperativeContext.frameRef.current = {
172
- ...timelineImperativeContext.frameRef.current,
155
+ frameRef.current = {
156
+ ...frameRef.current,
173
157
  [videoId]: newFrame,
174
158
  };
175
159
  setFrame((currentFrames) => currentFrames[videoId] === newFrame
176
160
  ? currentFrames
177
161
  : { ...currentFrames, [videoId]: newFrame });
178
- }, [lastFrame, setFrame, timelineImperativeContext, videoId]);
162
+ }, [frameRef, lastFrame, readIsPlaying, setFrame, videoId]);
179
163
  const toggle = (0, react_1.useCallback)((e) => {
180
- if (timelineImperativeContext.imperativePlaying.current) {
164
+ if (readIsPlaying()) {
181
165
  pause();
182
166
  }
183
167
  else {
184
168
  play(e);
185
169
  }
186
- }, [pause, play, timelineImperativeContext]);
187
- const isPlaying = (0, react_1.useCallback)(() => {
188
- return timelineImperativeContext.imperativePlaying.current;
189
- }, [timelineImperativeContext]);
190
- const isBuffering = (0, react_1.useCallback)(() => {
191
- return bufferingContext.buffering.current;
192
- }, [bufferingContext.buffering]);
170
+ }, [pause, play, readIsPlaying]);
193
171
  return (0, react_1.useMemo)(() => {
194
172
  return {
195
173
  frameBack,
@@ -199,7 +177,7 @@ const usePlayerMethods = () => {
199
177
  pause,
200
178
  seek,
201
179
  getCurrentFrame,
202
- isPlaying,
180
+ isPlaying: readIsPlaying,
203
181
  isBuffering,
204
182
  pauseAndReturnToPlayStart,
205
183
  toggle,
@@ -209,11 +187,11 @@ const usePlayerMethods = () => {
209
187
  frameBack,
210
188
  frameForward,
211
189
  getCurrentFrame,
212
- isBuffering,
213
- isPlaying,
190
+ readIsPlaying,
214
191
  pause,
215
192
  pauseAndReturnToPlayStart,
216
193
  play,
194
+ isBuffering,
217
195
  seek,
218
196
  toggle,
219
197
  ]);