@remotion/player 4.0.542 → 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 +2 -2
- package/dist/cjs/Player.js +4 -2
- package/dist/cjs/PlayerUI.d.ts +0 -2
- package/dist/cjs/PlayerUI.js +42 -32
- package/dist/cjs/buffer-indicator-state.d.ts +20 -0
- package/dist/cjs/buffer-indicator-state.js +30 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/playback-range-context.d.ts +4 -0
- package/dist/cjs/playback-range-context.js +5 -0
- package/dist/cjs/use-playback.js +150 -75
- package/dist/cjs/use-player-methods.js +16 -7
- package/dist/esm/index.mjs +238 -141
- package/package.json +3 -3
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.
|
|
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.
|
|
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).
|
package/dist/cjs/Player.js
CHANGED
|
@@ -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,
|
|
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
|
/*
|
package/dist/cjs/PlayerUI.d.ts
CHANGED
|
@@ -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;
|
package/dist/cjs/PlayerUI.js
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
setShowBufferState(false);
|
|
257
|
-
if (timeout) {
|
|
266
|
+
unsubscribe();
|
|
267
|
+
if (timeout !== null) {
|
|
258
268
|
clearTimeout(timeout);
|
|
259
269
|
}
|
|
260
|
-
|
|
270
|
+
setBufferIndicator({ type: 'idle' });
|
|
261
271
|
};
|
|
262
|
-
}, [bufferStateDelayInMilliseconds,
|
|
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;
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -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,
|
package/dist/cjs/use-playback.js
CHANGED
|
@@ -11,19 +11,20 @@ const is_backgrounded_js_1 = require("./is-backgrounded.js");
|
|
|
11
11
|
const set_global_time_anchor_js_1 = require("./set-global-time-anchor.js");
|
|
12
12
|
const use_player_methods_js_1 = require("./use-player-methods.js");
|
|
13
13
|
const shouldForceAnchorChange = (newState) => {
|
|
14
|
-
if (newState === '
|
|
15
|
-
return
|
|
14
|
+
if (newState === 'closed') {
|
|
15
|
+
return false;
|
|
16
16
|
}
|
|
17
|
-
if (newState === '
|
|
17
|
+
if (newState === 'suspended' ||
|
|
18
|
+
newState === 'running-to-suspended' ||
|
|
18
19
|
newState === 'interrupted' ||
|
|
19
20
|
newState === 'running' ||
|
|
20
21
|
newState === 'suspended-to-running') {
|
|
21
|
-
return
|
|
22
|
+
return true;
|
|
22
23
|
}
|
|
23
24
|
throw new Error(`Unexpected audio context state: ${newState}`);
|
|
24
25
|
};
|
|
25
26
|
const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, browserMediaControlsBehavior, getCurrentFrame, muted, }) => {
|
|
26
|
-
var _a, _b, _c;
|
|
27
|
+
var _a, _b, _c, _d;
|
|
27
28
|
const config = remotion_1.Internals.useUnsafeVideoConfig();
|
|
28
29
|
const fps = (_a = config === null || config === void 0 ? void 0 : config.fps) !== null && _a !== void 0 ? _a : null;
|
|
29
30
|
const durationInFrames = (_b = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _b !== void 0 ? _b : null;
|
|
@@ -41,43 +42,123 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
|
|
|
41
42
|
// In that case, we use setTimeout() instead.
|
|
42
43
|
const isBackgroundedRef = (0, is_backgrounded_js_1.useIsBackgrounded)();
|
|
43
44
|
const lastTimeUpdateTimestamp = (0, react_2.useRef)(0);
|
|
45
|
+
const seekRevisionAtRender = (_d = seek === null || seek === void 0 ? void 0 : seek.revision.current) !== null && _d !== void 0 ? _d : null;
|
|
46
|
+
const anchorSeekRevision = (0, react_2.useRef)(seekRevisionAtRender);
|
|
47
|
+
const playbackJumpRevision = (0, react_2.useRef)(0);
|
|
48
|
+
const jumpRevision = playbackJumpRevision.current;
|
|
44
49
|
const playbackClockRef = (0, react_2.useRef)(null);
|
|
45
|
-
const
|
|
46
|
-
const anchoredAudioContextRef = (0, react_2.useRef)(null);
|
|
50
|
+
const previousAudioBoundary = (0, react_2.useRef)(null);
|
|
47
51
|
(0, browser_mediasession_js_1.useBrowserMediaSession)({
|
|
48
52
|
browserMediaControlsBehavior,
|
|
49
53
|
playbackRate,
|
|
50
54
|
videoConfig: config,
|
|
51
55
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (!sharedAudioContext) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (!sharedAudioContext.audioContext) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
if (fps === null) {
|
|
62
|
-
return;
|
|
56
|
+
const updateAudioAnchor = (0, react_2.useCallback)(() => {
|
|
57
|
+
if (!(sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.audioContext) || fps === null || muted) {
|
|
58
|
+
return false;
|
|
63
59
|
}
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
let absoluteFrame = getCurrentFrame();
|
|
61
|
+
const clock = playbackClockRef.current;
|
|
62
|
+
if (playing &&
|
|
63
|
+
clock !== null &&
|
|
64
|
+
durationInFrames !== null &&
|
|
65
|
+
clock.compositionId === compositionId &&
|
|
66
|
+
clock.fps === fps &&
|
|
67
|
+
clock.playbackRate === playbackRate) {
|
|
68
|
+
const actualFirstFrame = inFrame !== null && inFrame !== void 0 ? inFrame : 0;
|
|
69
|
+
const actualLastFrame = outFrame !== null && outFrame !== void 0 ? outFrame : durationInFrames - 1;
|
|
70
|
+
const { nextFrame, hasEnded } = (0, calculate_next_frame_js_1.calculateNextFrame)({
|
|
71
|
+
time: performance.now() - clock.startedTime,
|
|
72
|
+
currentFrame: clock.frame,
|
|
73
|
+
playbackSpeed: playbackRate,
|
|
74
|
+
fps,
|
|
75
|
+
actualFirstFrame,
|
|
76
|
+
actualLastFrame,
|
|
77
|
+
framesAdvanced: clock.framesAdvanced,
|
|
78
|
+
shouldLoop: loop,
|
|
79
|
+
});
|
|
80
|
+
absoluteFrame =
|
|
81
|
+
hasEnded && !moveToBeginningWhenEnded
|
|
82
|
+
? playbackRate > 0
|
|
83
|
+
? actualLastFrame
|
|
84
|
+
: actualFirstFrame
|
|
85
|
+
: nextFrame;
|
|
66
86
|
}
|
|
67
87
|
const changed = (0, set_global_time_anchor_js_1.setGlobalTimeAnchor)({
|
|
68
88
|
audioContext: sharedAudioContext.audioContext,
|
|
69
89
|
audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
|
|
70
|
-
absoluteTimeInSeconds:
|
|
90
|
+
absoluteTimeInSeconds: absoluteFrame / fps,
|
|
71
91
|
globalPlaybackRate: playbackRate,
|
|
72
92
|
logLevel,
|
|
73
|
-
force:
|
|
93
|
+
force: true,
|
|
74
94
|
});
|
|
75
95
|
if (changed) {
|
|
76
96
|
sharedAudioContext.audioSyncAnchorEmitter.dispatch('changed');
|
|
77
97
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
return changed;
|
|
99
|
+
}, [
|
|
100
|
+
compositionId,
|
|
101
|
+
durationInFrames,
|
|
102
|
+
fps,
|
|
103
|
+
getCurrentFrame,
|
|
104
|
+
inFrame,
|
|
105
|
+
logLevel,
|
|
106
|
+
loop,
|
|
107
|
+
moveToBeginningWhenEnded,
|
|
108
|
+
muted,
|
|
109
|
+
outFrame,
|
|
110
|
+
playbackRate,
|
|
111
|
+
playing,
|
|
112
|
+
sharedAudioContext,
|
|
113
|
+
]);
|
|
114
|
+
// Re-anchor only at playback boundaries. A late React commit during ordinary
|
|
115
|
+
// playback must not move the audio clock and discard already scheduled audio.
|
|
116
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
117
|
+
var _a;
|
|
118
|
+
const boundary = {
|
|
119
|
+
audioContext: (_a = sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.audioContext) !== null && _a !== void 0 ? _a : null,
|
|
120
|
+
compositionId,
|
|
121
|
+
fps,
|
|
122
|
+
playbackRate,
|
|
123
|
+
muted,
|
|
124
|
+
playing,
|
|
125
|
+
seekRevision: seekRevisionAtRender,
|
|
126
|
+
jumpRevision,
|
|
127
|
+
};
|
|
128
|
+
const previous = previousAudioBoundary.current;
|
|
129
|
+
previousAudioBoundary.current = boundary;
|
|
130
|
+
anchorSeekRevision.current = seekRevisionAtRender;
|
|
131
|
+
if (previous !== null &&
|
|
132
|
+
Object.keys(boundary).every((key) => boundary[key] ===
|
|
133
|
+
previous[key])) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const clock = playbackClockRef.current;
|
|
137
|
+
if (clock !== null && clock.seekRevision !== seekRevisionAtRender) {
|
|
138
|
+
clock.frame = getCurrentFrame();
|
|
139
|
+
clock.seekRevision = seekRevisionAtRender;
|
|
140
|
+
}
|
|
141
|
+
const changed = updateAudioAnchor();
|
|
142
|
+
if (!changed &&
|
|
143
|
+
playing &&
|
|
144
|
+
!muted &&
|
|
145
|
+
(sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext._experimentalKeepAudioContextAlive)) {
|
|
146
|
+
// A changed timebase can invalidate queued audio even at the same anchor.
|
|
147
|
+
sharedAudioContext.audioSyncAnchorEmitter.dispatch('changed');
|
|
148
|
+
}
|
|
149
|
+
}, [
|
|
150
|
+
compositionId,
|
|
151
|
+
fps,
|
|
152
|
+
playbackRate,
|
|
153
|
+
muted,
|
|
154
|
+
sharedAudioContext,
|
|
155
|
+
getCurrentFrame,
|
|
156
|
+
jumpRevision,
|
|
157
|
+
playing,
|
|
158
|
+
seekRevisionAtRender,
|
|
159
|
+
updateAudioAnchor,
|
|
160
|
+
]);
|
|
161
|
+
// Native pauses, resumes and interruptions are clock boundaries too.
|
|
81
162
|
(0, react_1.useLayoutEffect)(() => {
|
|
82
163
|
const audioContext = sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.audioContext;
|
|
83
164
|
if (!audioContext) {
|
|
@@ -91,30 +172,24 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
|
|
|
91
172
|
}
|
|
92
173
|
const callback = () => {
|
|
93
174
|
const newState = sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.getAudioContextState();
|
|
175
|
+
// Native audio can already be playing while its output timestamp still
|
|
176
|
+
// lags. Keep the schedule established before this resume started.
|
|
177
|
+
if (newState === 'running' &&
|
|
178
|
+
(sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.getIsResumingAudioContext())) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
94
181
|
if (newState && shouldForceAnchorChange(newState)) {
|
|
95
|
-
|
|
96
|
-
audioContext,
|
|
97
|
-
audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
|
|
98
|
-
absoluteTimeInSeconds: getCurrentFrame() / fps,
|
|
99
|
-
globalPlaybackRate: playbackRate,
|
|
100
|
-
logLevel,
|
|
101
|
-
force: true,
|
|
102
|
-
});
|
|
103
|
-
if (changed) {
|
|
104
|
-
sharedAudioContext.audioSyncAnchorEmitter.dispatch('changed');
|
|
105
|
-
}
|
|
182
|
+
updateAudioAnchor();
|
|
106
183
|
}
|
|
107
184
|
};
|
|
108
185
|
audioContext === null || audioContext === void 0 ? void 0 : audioContext.addEventListener('statechange', callback);
|
|
109
186
|
return () => {
|
|
110
187
|
audioContext === null || audioContext === void 0 ? void 0 : audioContext.removeEventListener('statechange', callback);
|
|
111
188
|
};
|
|
112
|
-
}, [fps, getCurrentFrame,
|
|
189
|
+
}, [fps, getCurrentFrame, muted, sharedAudioContext, updateAudioAnchor]);
|
|
113
190
|
(0, react_2.useEffect)(() => {
|
|
114
191
|
var _a, _b;
|
|
115
192
|
var _c;
|
|
116
|
-
const wasMuted = previousMutedRef.current;
|
|
117
|
-
previousMutedRef.current = muted;
|
|
118
193
|
if (fps === null || durationInFrames === null || compositionId === null) {
|
|
119
194
|
playbackClockRef.current = null;
|
|
120
195
|
return;
|
|
@@ -139,41 +214,17 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
|
|
|
139
214
|
compositionId,
|
|
140
215
|
startedTime: performance.now(),
|
|
141
216
|
framesAdvanced: 0,
|
|
217
|
+
frame: getCurrentFrame(),
|
|
218
|
+
seekRevision: (_c = seek === null || seek === void 0 ? void 0 : seek.revision.current) !== null && _c !== void 0 ? _c : null,
|
|
142
219
|
fps,
|
|
143
220
|
playbackRate,
|
|
144
221
|
}
|
|
145
222
|
: previousClock;
|
|
223
|
+
clock.frame = remotion_1.Internals.Timeline.clampFrameToCompositionRange(clock.frame, durationInFrames);
|
|
146
224
|
playbackClockRef.current = clock;
|
|
147
|
-
if ((sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext._experimentalKeepAudioContextAlive) &&
|
|
148
|
-
sharedAudioContext.audioContext &&
|
|
149
|
-
!muted) {
|
|
150
|
-
const didUnmute = wasMuted && !muted;
|
|
151
|
-
const didReplaceAudioContext = anchoredAudioContextRef.current !== sharedAudioContext.audioContext;
|
|
152
|
-
const shouldRescheduleAudio = shouldRestartClock || didUnmute || didReplaceAudioContext;
|
|
153
|
-
// The native clock keeps running through pauses and muted playback.
|
|
154
|
-
// These transitions need an exact anchor, as does a replacement context
|
|
155
|
-
// with its own time origin. Other effect re-runs use the drift tolerance
|
|
156
|
-
// so duration changes do not introduce frame-quantized audio shifts.
|
|
157
|
-
const changed = (0, set_global_time_anchor_js_1.setGlobalTimeAnchor)({
|
|
158
|
-
audioContext: sharedAudioContext.audioContext,
|
|
159
|
-
audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
|
|
160
|
-
absoluteTimeInSeconds: getCurrentFrame() / fps,
|
|
161
|
-
globalPlaybackRate: playbackRate,
|
|
162
|
-
logLevel,
|
|
163
|
-
force: shouldRescheduleAudio,
|
|
164
|
-
});
|
|
165
|
-
anchoredAudioContextRef.current = sharedAudioContext.audioContext;
|
|
166
|
-
// A changed timebase can invalidate queued audio even if the anchor
|
|
167
|
-
// happens to remain numerically equal (for example at frame zero).
|
|
168
|
-
if (changed || shouldRescheduleAudio) {
|
|
169
|
-
sharedAudioContext.audioSyncAnchorEmitter.dispatch('changed');
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
225
|
let hasBeenStopped = false;
|
|
173
226
|
let audioContextFailed = false;
|
|
174
227
|
let reqAnimFrameCall = null;
|
|
175
|
-
let playbackFrame = getCurrentFrame();
|
|
176
|
-
let lastSeekRevision = (_c = seek === null || seek === void 0 ? void 0 : seek.revision.current) !== null && _c !== void 0 ? _c : null;
|
|
177
228
|
let unsubscribeBuffering = null;
|
|
178
229
|
const cancelQueuedFrame = () => {
|
|
179
230
|
if (reqAnimFrameCall !== null) {
|
|
@@ -214,12 +265,21 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
|
|
|
214
265
|
const actualLastFrame = outFrame !== null && outFrame !== void 0 ? outFrame : durationInFrames - 1;
|
|
215
266
|
const actualFirstFrame = inFrame !== null && inFrame !== void 0 ? inFrame : 0;
|
|
216
267
|
const seekRevision = (_c = seek === null || seek === void 0 ? void 0 : seek.revision.current) !== null && _c !== void 0 ? _c : null;
|
|
217
|
-
if (seekRevision !==
|
|
218
|
-
|
|
219
|
-
|
|
268
|
+
if (seekRevision !== clock.seekRevision) {
|
|
269
|
+
clock.frame = getCurrentFrame();
|
|
270
|
+
clock.seekRevision = seekRevision;
|
|
271
|
+
if (anchorSeekRevision.current !== seekRevision) {
|
|
272
|
+
// A same-frame seek may not cause a React commit. It still needs
|
|
273
|
+
// an exact anchor before advancing playback from that position.
|
|
274
|
+
updateAudioAnchor();
|
|
275
|
+
anchorSeekRevision.current = seekRevision;
|
|
276
|
+
if (previousAudioBoundary.current !== null) {
|
|
277
|
+
previousAudioBoundary.current.seekRevision = seekRevision;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
220
280
|
}
|
|
221
281
|
// React may not have committed the previous playback update yet.
|
|
222
|
-
const currentFrame =
|
|
282
|
+
const currentFrame = clock.frame;
|
|
223
283
|
const { nextFrame, framesToAdvance, hasEnded } = (0, calculate_next_frame_js_1.calculateNextFrame)({
|
|
224
284
|
time,
|
|
225
285
|
currentFrame,
|
|
@@ -237,10 +297,23 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
|
|
|
237
297
|
? actualLastFrame
|
|
238
298
|
: actualFirstFrame
|
|
239
299
|
: nextFrame;
|
|
300
|
+
const didJump = frameToDisplay !== currentFrame + framesToAdvance;
|
|
301
|
+
if (didJump) {
|
|
302
|
+
// Re-anchor after the jump's target frame commits.
|
|
303
|
+
playbackJumpRevision.current++;
|
|
304
|
+
}
|
|
305
|
+
clock.frame = frameToDisplay;
|
|
240
306
|
if (frameToDisplay !== currentFrame) {
|
|
241
|
-
playbackFrame = frameToDisplay;
|
|
242
307
|
setFrameFromPlayback((c) => ({ ...c, [compositionId]: frameToDisplay }));
|
|
243
308
|
}
|
|
309
|
+
else if (didJump) {
|
|
310
|
+
// A jump can land on the same frame without a React commit.
|
|
311
|
+
updateAudioAnchor();
|
|
312
|
+
if (previousAudioBoundary.current !== null) {
|
|
313
|
+
previousAudioBoundary.current.jumpRevision =
|
|
314
|
+
playbackJumpRevision.current;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
244
317
|
if (hasEnded) {
|
|
245
318
|
stop();
|
|
246
319
|
pause();
|
|
@@ -288,14 +361,16 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
|
|
|
288
361
|
if (hasBeenStopped) {
|
|
289
362
|
return;
|
|
290
363
|
}
|
|
364
|
+
// The context clock may have advanced while the timeline was
|
|
365
|
+
// stalled, especially with _experimentalKeepAudioContextAlive.
|
|
366
|
+
clock.startedTime = performance.now();
|
|
367
|
+
clock.framesAdvanced = 0;
|
|
368
|
+
updateAudioAnchor();
|
|
291
369
|
if (!muted &&
|
|
292
370
|
!audioContextFailed &&
|
|
293
371
|
(sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext._experimentalKeepAudioContextAlive)) {
|
|
294
372
|
sharedAudioContext.resume();
|
|
295
373
|
}
|
|
296
|
-
// Buffered media became reachable; start a fresh clock.
|
|
297
|
-
clock.startedTime = performance.now();
|
|
298
|
-
clock.framesAdvanced = 0;
|
|
299
374
|
queueNextFrame();
|
|
300
375
|
});
|
|
301
376
|
return;
|
|
@@ -349,8 +424,8 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
|
|
|
349
424
|
setPlayerMuted,
|
|
350
425
|
subscribeBuffering,
|
|
351
426
|
seek,
|
|
352
|
-
logLevel,
|
|
353
427
|
muted,
|
|
428
|
+
updateAudioAnchor,
|
|
354
429
|
]);
|
|
355
430
|
(0, react_2.useEffect)(() => {
|
|
356
431
|
const now = performance.now();
|