@remotion/player 4.0.541 → 4.0.543

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/LICENSE.md CHANGED
@@ -42,8 +42,8 @@ Support is provided on a best-we-can-do basis via GitHub Issues and Discord.
42
42
 
43
43
  You are required to obtain a Company License to use Remotion if you are not within the group of entities eligible for a Free License. This license will enable you to use Remotion for the allowed use cases specified in the Free License, and give you access to prioritized support (read the [Support Policy](https://www.remotion.dev/docs/support)).
44
44
 
45
- Visit [remotion.pro](https://www.remotion.pro/license) for pricing and to buy a license.
45
+ Visit [remotion.dev](https://www.remotion.dev/docs/license/pricing) for pricing and to buy a license.
46
46
 
47
47
  ### FAQs
48
48
 
49
- Are you not sure whether you need a Company License because of an edge case? Here are some [frequently asked questions](https://www.remotion.pro/faq).
49
+ Are you not sure whether you need a Company License because of an edge case? Here are some [frequently asked questions](https://www.remotion.dev/docs/license/faq).
@@ -42,6 +42,7 @@ const react_1 = __importStar(require("react"));
42
42
  const remotion_1 = require("remotion");
43
43
  const no_react_1 = require("remotion/no-react");
44
44
  const EmitterProvider_js_1 = require("./EmitterProvider.js");
45
+ const playback_range_context_js_1 = require("./playback-range-context.js");
45
46
  const player_css_classname_js_1 = require("./player-css-classname.js");
46
47
  const PlayerUI_js_1 = __importDefault(require("./PlayerUI.js"));
47
48
  const SharedPlayerContext_js_1 = require("./SharedPlayerContext.js");
@@ -252,6 +253,7 @@ const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps,
252
253
  remotion_1.Internals.CSSUtils.injectCSS(remotion_1.Internals.CSSUtils.makeDefaultPreviewCSS(`.${(0, player_css_classname_js_1.playerCssClassname)(overrideInternalClassName)}`, '#fff'));
253
254
  }, [overrideInternalClassName]);
254
255
  }
256
+ const playbackRange = (0, react_1.useMemo)(() => ({ inFrame: inFrame !== null && inFrame !== void 0 ? inFrame : null, outFrame: outFrame !== null && outFrame !== void 0 ? outFrame : null }), [inFrame, outFrame]);
255
257
  const actualInputProps = (0, react_1.useMemo)(() => inputProps !== null && inputProps !== void 0 ? inputProps : {}, [inputProps]);
256
258
  const browserMediaControlsBehavior = (0, react_1.useMemo)(() => {
257
259
  return (passedBrowserMediaControlsBehavior !== null && passedBrowserMediaControlsBehavior !== void 0 ? passedBrowserMediaControlsBehavior : {
@@ -260,8 +262,8 @@ const PlayerFn = ({ durationInFrames, compositionHeight, compositionWidth, fps,
260
262
  }, [passedBrowserMediaControlsBehavior]);
261
263
  const player = ((0, jsx_runtime_1.jsx)(remotion_1.Internals.IsPlayerContextProvider, { children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.SetTimelineContext.Provider, { value: setTimelineContextValue, children: (0, jsx_runtime_1.jsx)(SharedPlayerContext_js_1.SharedPlayerContexts, { timelineContext: timelineContextValue, playbackRateContext: playbackRateContextValue, preservePitch: preservePitch, component: component, compositionHeight: compositionHeight, compositionWidth: compositionWidth, durationInFrames: durationInFrames, fps: fps, numberOfSharedAudioTags: numberOfSharedAudioTags, initiallyMuted: initiallyMuted, logLevel: logLevel, audioLatencyHint: audioLatencyHint, preferredEffectBackend: preferredEffectBackend, sampleRate: sampleRate, _experimentalKeepAudioContextAlive: _experimentalKeepAudioContextAlive, volumePersistenceKey: volumePersistenceKey, initialVolume: initialVolume, inputProps: actualInputProps, audioEnabled: true, children: (0, jsx_runtime_1.jsx)(EmitterProvider_js_1.PlayerEmitterProvider, { currentPlaybackRate: currentPlaybackRate, children: (0, 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'
262
264
  ? clickToPlay
263
- : 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) }) }) }) }) }));
264
- return ((0, jsx_runtime_1.jsx)(remotion_1.Internals.DefaultPremountContext.Provider, { value: defaultPremountInSeconds, children: onTimelineSequenceChange ? ((0, jsx_runtime_1.jsx)(remotion_1.Internals.SequenceRegistrationContext.Provider, { value: true, children: (0, jsx_runtime_1.jsxs)(remotion_1.Internals.SequenceManagerProvider, { children: [(0, jsx_runtime_1.jsx)(TimelineSequenceObserverComponent, { onTimelineSequenceChange: onTimelineSequenceChange }), player] }) })) : (player) }));
265
+ : 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, 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) }) }) }) }) }));
266
+ return ((0, jsx_runtime_1.jsx)(playback_range_context_js_1.PlaybackRangeContext.Provider, { value: playbackRange, children: (0, jsx_runtime_1.jsx)(remotion_1.Internals.DefaultPremountContext.Provider, { value: defaultPremountInSeconds, children: onTimelineSequenceChange ? ((0, jsx_runtime_1.jsx)(remotion_1.Internals.SequenceRegistrationContext.Provider, { value: true, children: (0, jsx_runtime_1.jsxs)(remotion_1.Internals.SequenceManagerProvider, { children: [(0, jsx_runtime_1.jsx)(TimelineSequenceObserverComponent, { onTimelineSequenceChange: onTimelineSequenceChange }), player] }) })) : (player) }) }));
265
267
  };
266
268
  const forward = react_1.forwardRef;
267
269
  /*
@@ -36,8 +36,6 @@ declare const _default: React.ForwardRefExoticComponent<{
36
36
  readonly showPosterWhenUnplayed: boolean;
37
37
  readonly showPosterWhenBuffering: boolean;
38
38
  readonly showPosterWhenBufferingAndPaused: boolean;
39
- readonly inFrame: number | null;
40
- readonly outFrame: number | null;
41
39
  readonly initiallyShowControls: number | boolean;
42
40
  readonly renderPlayPauseButton: RenderPlayPauseButton | null;
43
41
  readonly renderFullscreen: RenderFullscreenButton | null;
@@ -36,10 +36,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const jsx_runtime_1 = require("react/jsx-runtime");
37
37
  const react_1 = __importStar(require("react"));
38
38
  const remotion_1 = require("remotion");
39
+ const buffer_indicator_state_js_1 = require("./buffer-indicator-state.js");
39
40
  const calculate_scale_js_1 = require("./calculate-scale.js");
40
41
  const canvas_overlay_context_js_1 = require("./canvas-overlay-context.js");
41
42
  const error_boundary_js_1 = require("./error-boundary.js");
42
43
  const license_blacklist_js_1 = require("./license-blacklist.js");
44
+ const playback_range_context_js_1 = require("./playback-range-context.js");
43
45
  const player_css_classname_js_1 = require("./player-css-classname.js");
44
46
  const PlayerControls_js_1 = require("./PlayerControls.js");
45
47
  const use_playback_js_1 = require("./use-playback.js");
@@ -52,8 +54,9 @@ if (reactVersion === '0') {
52
54
  throw new Error(`Version ${reactVersion} of "react" is not supported by Remotion`);
53
55
  }
54
56
  const doesReactVersionSupportSuspense = parseInt(reactVersion, 10) >= 18;
55
- const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps, clickToPlay, showVolumeControls, doubleClickToFullscreen, spaceKeyToPlayOrPause, errorFallback, playbackRate, renderLoading, renderPoster, className, moveToBeginningWhenEnded, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, showPosterWhenBuffering, showPosterWhenBufferingAndPaused, inFrame, outFrame, initiallyShowControls, renderFullscreen: renderFullscreenButton, renderPlayPauseButton, renderMuteButton, renderVolumeSlider, renderCustomControls, alwaysShowControls, showPlaybackRateControl, posterFillMode, bufferStateDelayInMilliseconds, hideControlsWhenPointerDoesntMove, overflowVisible, browserMediaControlsBehavior, overrideInternalClassName, noSuspense, }, ref) => {
57
+ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps, clickToPlay, showVolumeControls, doubleClickToFullscreen, spaceKeyToPlayOrPause, errorFallback, playbackRate, renderLoading, renderPoster, className, moveToBeginningWhenEnded, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, showPosterWhenBuffering, showPosterWhenBufferingAndPaused, initiallyShowControls, renderFullscreen: renderFullscreenButton, renderPlayPauseButton, renderMuteButton, renderVolumeSlider, renderCustomControls, alwaysShowControls, showPlaybackRateControl, posterFillMode, bufferStateDelayInMilliseconds, hideControlsWhenPointerDoesntMove, overflowVisible, browserMediaControlsBehavior, overrideInternalClassName, noSuspense, }, ref) => {
56
58
  var _a, _b, _c;
59
+ const { inFrame, outFrame } = (0, react_1.useContext)(playback_range_context_js_1.PlaybackRangeContext);
57
60
  const config = remotion_1.Internals.useUnsafeVideoConfig();
58
61
  const video = remotion_1.Internals.useVideo();
59
62
  const container = (0, react_1.useRef)(null);
@@ -220,46 +223,53 @@ const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps
220
223
  }
221
224
  player.emitter.dispatchScaleChange(scale);
222
225
  }, [player.emitter, scale]);
223
- const [showBufferIndicator, setShowBufferState] = (0, react_1.useState)(false);
226
+ const { subscribeBuffering, isBuffering } = (0, react_1.useContext)(remotion_1.Internals.SetTimelineContext);
227
+ const [bufferIndicator, setBufferIndicator] = (0, react_1.useState)({
228
+ type: 'idle',
229
+ });
230
+ const showBufferIndicator = bufferIndicator.type === 'showing';
224
231
  (0, react_1.useEffect)(() => {
232
+ let current = { type: 'idle' };
225
233
  let timeout = null;
226
- let stopped = false;
227
- const onBuffer = () => {
228
- stopped = false;
229
- requestAnimationFrame(() => {
230
- if (bufferStateDelayInMilliseconds === 0) {
231
- setShowBufferState(true);
232
- }
233
- else {
234
- timeout = setTimeout(() => {
235
- if (!stopped) {
236
- setShowBufferState(true);
237
- }
238
- }, bufferStateDelayInMilliseconds);
239
- }
240
- });
234
+ const dispatch = (event) => {
235
+ const { state: next, effect } = (0, buffer_indicator_state_js_1.reduceBufferIndicator)(current, event);
236
+ if (effect === 'start-timer') {
237
+ timeout = setTimeout(() => {
238
+ timeout = null;
239
+ dispatch({ type: 'delay-elapsed' });
240
+ }, bufferStateDelayInMilliseconds);
241
+ }
242
+ else if (effect === 'clear-timer' && timeout !== null) {
243
+ clearTimeout(timeout);
244
+ timeout = null;
245
+ }
246
+ if (next.type !== current.type) {
247
+ current = next;
248
+ setBufferIndicator(next);
249
+ }
241
250
  };
242
- const onResume = () => {
243
- requestAnimationFrame(() => {
244
- stopped = true;
245
- setShowBufferState(false);
246
- if (timeout) {
247
- clearTimeout(timeout);
251
+ const unsubscribe = subscribeBuffering((state) => {
252
+ dispatch(state.buffering
253
+ ? {
254
+ type: 'buffer-start',
255
+ delayInMilliseconds: bufferStateDelayInMilliseconds,
248
256
  }
257
+ : { type: 'buffer-end' });
258
+ });
259
+ if (isBuffering()) {
260
+ dispatch({
261
+ type: 'buffer-start',
262
+ delayInMilliseconds: bufferStateDelayInMilliseconds,
249
263
  });
250
- };
251
- player.emitter.addEventListener('waiting', onBuffer);
252
- player.emitter.addEventListener('resume', onResume);
264
+ }
253
265
  return () => {
254
- player.emitter.removeEventListener('waiting', onBuffer);
255
- player.emitter.removeEventListener('resume', onResume);
256
- setShowBufferState(false);
257
- if (timeout) {
266
+ unsubscribe();
267
+ if (timeout !== null) {
258
268
  clearTimeout(timeout);
259
269
  }
260
- stopped = true;
270
+ setBufferIndicator({ type: 'idle' });
261
271
  };
262
- }, [bufferStateDelayInMilliseconds, player.emitter]);
272
+ }, [bufferStateDelayInMilliseconds, isBuffering, subscribeBuffering]);
263
273
  (0, react_1.useImperativeHandle)(ref, () => {
264
274
  const methods = {
265
275
  play,
@@ -0,0 +1,20 @@
1
+ export type BufferIndicatorState = {
2
+ type: 'idle';
3
+ } | {
4
+ type: 'pending';
5
+ } | {
6
+ type: 'showing';
7
+ };
8
+ export type BufferIndicatorEvent = {
9
+ type: 'buffer-start';
10
+ delayInMilliseconds: number;
11
+ } | {
12
+ type: 'buffer-end';
13
+ } | {
14
+ type: 'delay-elapsed';
15
+ };
16
+ export type BufferIndicatorEffect = 'start-timer' | 'clear-timer' | null;
17
+ export declare const reduceBufferIndicator: (state: BufferIndicatorState, event: BufferIndicatorEvent) => {
18
+ state: BufferIndicatorState;
19
+ effect: BufferIndicatorEffect;
20
+ };
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reduceBufferIndicator = void 0;
4
+ const reduceBufferIndicator = (state, event) => {
5
+ switch (event.type) {
6
+ case 'buffer-start':
7
+ if (state.type !== 'idle') {
8
+ return { state, effect: null };
9
+ }
10
+ return event.delayInMilliseconds === 0
11
+ ? { state: { type: 'showing' }, effect: null }
12
+ : { state: { type: 'pending' }, effect: 'start-timer' };
13
+ case 'buffer-end':
14
+ if (state.type === 'idle') {
15
+ return { state, effect: null };
16
+ }
17
+ return {
18
+ state: { type: 'idle' },
19
+ effect: state.type === 'pending' ? 'clear-timer' : null,
20
+ };
21
+ case 'delay-elapsed':
22
+ return state.type === 'pending'
23
+ ? { state: { type: 'showing' }, effect: null }
24
+ : { state, effect: null };
25
+ default:
26
+ throw new Error('Unhandled buffer indicator event: ' +
27
+ JSON.stringify(event));
28
+ }
29
+ };
30
+ exports.reduceBufferIndicator = reduceBufferIndicator;
@@ -8,6 +8,15 @@ const calculateNextFrame = ({ time, currentFrame: startFrame, playbackSpeed, fps
8
8
  const isCurrentFrameOutside = startFrame > actualLastFrame || startFrame < actualFirstFrame;
9
9
  const isNextFrameOutside = nextFrame > actualLastFrame || nextFrame < actualFirstFrame;
10
10
  const hasEnded = !shouldLoop && isNextFrameOutside && !isCurrentFrameOutside;
11
+ if (shouldLoop && isNextFrameOutside && !isCurrentFrameOutside) {
12
+ const playbackRange = actualLastFrame - actualFirstFrame + 1;
13
+ const frameWithinRange = (nextFrame - actualFirstFrame) % playbackRange;
14
+ return {
15
+ nextFrame: actualFirstFrame + ((frameWithinRange + playbackRange) % playbackRange),
16
+ framesToAdvance,
17
+ hasEnded,
18
+ };
19
+ }
11
20
  if (playbackSpeed > 0) {
12
21
  // Play forwards
13
22
  if (isNextFrameOutside) {
@@ -30,6 +30,10 @@ export declare const PlayerInternals: {
30
30
  readonly children: React.ReactNode;
31
31
  readonly currentPlaybackRate: number | null;
32
32
  }>;
33
+ PlaybackRangeContext: import("react").Context<{
34
+ readonly inFrame: number | null;
35
+ readonly outFrame: number | null;
36
+ }>;
33
37
  BufferingIndicator: import("react").FC<{
34
38
  readonly type: 'player' | 'studio';
35
39
  readonly color?: string;
package/dist/cjs/index.js CHANGED
@@ -8,6 +8,7 @@ const canvas_overlay_context_js_1 = require("./canvas-overlay-context.js");
8
8
  const emitter_context_js_1 = require("./emitter-context.js");
9
9
  const EmitterProvider_js_1 = require("./EmitterProvider.js");
10
10
  const event_emitter_js_1 = require("./event-emitter.js");
11
+ const playback_range_context_js_1 = require("./playback-range-context.js");
11
12
  const PlayerControls_js_1 = require("./PlayerControls.js");
12
13
  const timeline_sequence_observer_context_js_1 = require("./timeline-sequence-observer-context.js");
13
14
  const use_hover_state_js_1 = require("./use-hover-state.js");
@@ -28,6 +29,7 @@ exports.PlayerInternals = {
28
29
  useHoverState: use_hover_state_js_1.useHoverState,
29
30
  updateAllElementsSizes: use_element_size_js_1.updateAllElementsSizes,
30
31
  PlayerEmitterProvider: EmitterProvider_js_1.PlayerEmitterProvider,
32
+ PlaybackRangeContext: playback_range_context_js_1.PlaybackRangeContext,
31
33
  BufferingIndicator: BufferingIndicator_js_1.BufferingIndicator,
32
34
  PlayerControls: PlayerControls_js_1.Controls,
33
35
  TimelineSequenceObserverContext: timeline_sequence_observer_context_js_1.TimelineSequenceObserverContext,
@@ -0,0 +1,4 @@
1
+ export declare const PlaybackRangeContext: import("react").Context<{
2
+ readonly inFrame: number | null;
3
+ readonly outFrame: number | null;
4
+ }>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlaybackRangeContext = void 0;
4
+ const react_1 = require("react");
5
+ exports.PlaybackRangeContext = (0, react_1.createContext)({ inFrame: null, outFrame: null });