@remotion/player 4.0.0-lambda.3 → 4.0.0-newpaths.13
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 +8 -8
- package/README.md +1 -1
- package/dist/MediaVolumeSlider.d.ts +4 -1
- package/dist/MediaVolumeSlider.js +80 -55
- package/dist/Player.d.ts +20 -15
- package/dist/Player.js +24 -70
- package/dist/PlayerControls.d.ts +29 -2
- package/dist/PlayerControls.js +66 -15
- package/dist/PlayerSeekBar.d.ts +4 -0
- package/dist/PlayerSeekBar.js +35 -11
- package/dist/PlayerUI.d.ts +18 -9
- package/dist/PlayerUI.js +118 -76
- package/dist/SharedPlayerContext.d.ts +14 -0
- package/dist/SharedPlayerContext.js +72 -0
- package/dist/Thumbnail.d.ts +20 -0
- package/dist/Thumbnail.js +42 -0
- package/dist/ThumbnailUI.d.ts +11 -0
- package/dist/ThumbnailUI.js +107 -0
- package/dist/calculate-next-frame.d.ts +0 -0
- package/dist/calculate-next-frame.js +0 -0
- package/dist/calculate-scale.d.ts +30 -5
- package/dist/calculate-scale.js +65 -4
- package/dist/cjs/MediaVolumeSlider.d.ts +5 -0
- package/dist/cjs/MediaVolumeSlider.js +118 -0
- package/dist/cjs/Player.d.ts +43 -0
- package/dist/cjs/Player.js +143 -0
- package/dist/cjs/PlayerControls.d.ts +41 -0
- package/dist/cjs/PlayerControls.js +152 -0
- package/dist/cjs/PlayerSeekBar.d.ts +8 -0
- package/dist/cjs/PlayerSeekBar.js +146 -0
- package/dist/cjs/PlayerUI.d.ts +38 -0
- package/dist/cjs/PlayerUI.js +308 -0
- package/dist/cjs/SharedPlayerContext.d.ts +14 -0
- package/dist/cjs/SharedPlayerContext.js +72 -0
- package/dist/cjs/Thumbnail.d.ts +20 -0
- package/dist/cjs/Thumbnail.js +42 -0
- package/dist/cjs/ThumbnailUI.d.ts +11 -0
- package/dist/cjs/ThumbnailUI.js +107 -0
- package/dist/cjs/calculate-next-frame.d.ts +14 -0
- package/dist/cjs/calculate-next-frame.js +28 -0
- package/dist/cjs/calculate-scale.d.ts +39 -0
- package/dist/cjs/calculate-scale.js +85 -0
- package/dist/cjs/emitter-context.d.ts +4 -0
- package/dist/cjs/emitter-context.js +9 -0
- package/dist/cjs/error-boundary.d.ts +19 -0
- package/dist/cjs/error-boundary.js +39 -0
- package/dist/cjs/event-emitter.d.ts +66 -0
- package/dist/cjs/event-emitter.js +87 -0
- package/dist/cjs/format-time.d.ts +1 -0
- package/dist/cjs/format-time.js +9 -0
- package/dist/cjs/icons.d.ts +10 -0
- package/dist/cjs/icons.js +50 -0
- package/dist/cjs/index.d.ts +61 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/player-css-classname.d.ts +1 -0
- package/dist/cjs/player-css-classname.js +4 -0
- package/dist/cjs/player-methods.d.ts +24 -0
- package/dist/cjs/player-methods.js +2 -0
- package/dist/cjs/test/index.test.d.ts +1 -0
- package/dist/cjs/test/index.test.js +9 -0
- package/dist/cjs/test/test-utils.d.ts +6 -0
- package/dist/cjs/test/test-utils.js +32 -0
- package/dist/cjs/test/validate-in-out-frames.test.d.ts +1 -0
- package/dist/cjs/test/validate-in-out-frames.test.js +56 -0
- package/dist/cjs/test/validate-prop.test.d.ts +1 -0
- package/dist/cjs/test/validate-prop.test.js +131 -0
- package/dist/cjs/use-hover-state.d.ts +1 -0
- package/dist/cjs/use-hover-state.js +27 -0
- package/dist/cjs/use-playback.d.ts +7 -0
- package/dist/cjs/use-playback.js +92 -0
- package/dist/cjs/use-player.d.ts +19 -0
- package/dist/cjs/use-player.js +132 -0
- package/dist/cjs/use-thumbnail.d.ts +6 -0
- package/dist/cjs/use-thumbnail.js +18 -0
- package/dist/cjs/use-video-controls-resize.d.ts +7 -0
- package/dist/cjs/use-video-controls-resize.js +36 -0
- package/dist/cjs/utils/calculate-player-size.d.ts +9 -0
- package/dist/cjs/utils/calculate-player-size.js +29 -0
- package/dist/cjs/utils/cancellable-promise.d.ts +5 -0
- package/dist/cjs/utils/cancellable-promise.js +26 -0
- package/dist/cjs/utils/delay.d.ts +1 -0
- package/dist/cjs/utils/delay.js +6 -0
- package/dist/cjs/utils/is-node.d.ts +1 -0
- package/dist/cjs/utils/is-node.js +4 -0
- package/dist/cjs/utils/preview-size.d.ts +8 -0
- package/dist/cjs/utils/preview-size.js +2 -0
- package/dist/cjs/utils/props-if-has-props.d.ts +5 -0
- package/dist/cjs/utils/props-if-has-props.js +2 -0
- package/dist/cjs/utils/use-cancellable-promises.d.ts +7 -0
- package/dist/cjs/utils/use-cancellable-promises.js +21 -0
- package/dist/cjs/utils/use-click-prevention-on-double-click.d.ts +3 -0
- package/dist/cjs/utils/use-click-prevention-on-double-click.js +45 -0
- package/dist/cjs/utils/use-element-size.d.ts +16 -0
- package/dist/cjs/utils/use-element-size.js +98 -0
- package/dist/cjs/utils/validate-in-out-frame.d.ts +6 -0
- package/dist/cjs/utils/validate-in-out-frame.js +54 -0
- package/dist/cjs/utils/validate-initial-frame.d.ts +4 -0
- package/dist/cjs/utils/validate-initial-frame.js +27 -0
- package/dist/cjs/utils/validate-playbackrate.d.ts +1 -0
- package/dist/cjs/utils/validate-playbackrate.js +18 -0
- package/dist/cjs/volume-persistance.d.ts +2 -0
- package/dist/cjs/volume-persistance.js +19 -0
- package/dist/emitter-context.d.ts +2 -1
- package/dist/emitter-context.js +2 -1
- package/dist/error-boundary.d.ts +0 -0
- package/dist/error-boundary.js +0 -0
- package/dist/esm/MediaVolumeSlider.d.ts +5 -0
- package/dist/esm/MediaVolumeSlider.js +114 -0
- package/dist/esm/Player.d.ts +43 -0
- package/dist/esm/Player.js +136 -0
- package/dist/esm/PlayerControls.d.ts +41 -0
- package/dist/esm/PlayerControls.js +148 -0
- package/dist/esm/PlayerSeekBar.d.ts +8 -0
- package/dist/esm/PlayerSeekBar.js +142 -0
- package/dist/esm/PlayerUI.d.ts +38 -0
- package/dist/esm/PlayerUI.js +283 -0
- package/dist/esm/SharedPlayerContext.d.ts +14 -0
- package/dist/esm/SharedPlayerContext.js +68 -0
- package/dist/esm/Thumbnail.d.ts +20 -0
- package/dist/esm/Thumbnail.js +35 -0
- package/dist/esm/ThumbnailUI.d.ts +11 -0
- package/dist/esm/ThumbnailUI.js +82 -0
- package/dist/esm/calculate-next-frame.d.ts +14 -0
- package/dist/esm/calculate-next-frame.js +24 -0
- package/dist/esm/calculate-scale.d.ts +39 -0
- package/dist/esm/calculate-scale.js +77 -0
- package/dist/esm/emitter-context.d.ts +4 -0
- package/dist/esm/emitter-context.js +3 -0
- package/dist/esm/error-boundary.d.ts +19 -0
- package/dist/esm/error-boundary.js +32 -0
- package/dist/esm/event-emitter.d.ts +66 -0
- package/dist/esm/event-emitter.js +82 -0
- package/dist/esm/format-time.d.ts +1 -0
- package/dist/esm/format-time.js +5 -0
- package/dist/esm/icons.d.ts +10 -0
- package/dist/esm/icons.js +42 -0
- package/dist/esm/index.d.ts +61 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/player-css-classname.d.ts +1 -0
- package/dist/esm/player-css-classname.js +1 -0
- package/dist/esm/player-methods.d.ts +24 -0
- package/dist/esm/player-methods.js +1 -0
- package/dist/esm/test/index.test.d.ts +1 -0
- package/dist/esm/test/index.test.js +7 -0
- package/dist/esm/test/test-utils.d.ts +6 -0
- package/dist/esm/test/test-utils.js +14 -0
- package/dist/esm/test/validate-in-out-frames.test.d.ts +1 -0
- package/dist/esm/test/validate-in-out-frames.test.js +54 -0
- package/dist/esm/test/validate-prop.test.d.ts +1 -0
- package/dist/esm/test/validate-prop.test.js +129 -0
- package/dist/esm/use-hover-state.d.ts +1 -0
- package/dist/esm/use-hover-state.js +23 -0
- package/dist/esm/use-playback.d.ts +7 -0
- package/dist/esm/use-playback.js +88 -0
- package/dist/esm/use-player.d.ts +19 -0
- package/dist/esm/use-player.js +128 -0
- package/dist/esm/use-thumbnail.d.ts +6 -0
- package/dist/esm/use-thumbnail.js +14 -0
- package/dist/esm/use-video-controls-resize.d.ts +7 -0
- package/dist/esm/use-video-controls-resize.js +32 -0
- package/dist/esm/utils/calculate-player-size.d.ts +9 -0
- package/dist/esm/utils/calculate-player-size.js +25 -0
- package/dist/esm/utils/cancellable-promise.d.ts +5 -0
- package/dist/esm/utils/cancellable-promise.js +22 -0
- package/dist/esm/utils/delay.d.ts +1 -0
- package/dist/esm/utils/delay.js +2 -0
- package/dist/esm/utils/is-node.d.ts +1 -0
- package/dist/esm/utils/is-node.js +1 -0
- package/dist/esm/utils/preview-size.d.ts +8 -0
- package/dist/esm/utils/preview-size.js +1 -0
- package/dist/esm/utils/props-if-has-props.d.ts +5 -0
- package/dist/esm/utils/props-if-has-props.js +1 -0
- package/dist/esm/utils/use-cancellable-promises.d.ts +7 -0
- package/dist/esm/utils/use-cancellable-promises.js +18 -0
- package/dist/esm/utils/use-click-prevention-on-double-click.d.ts +3 -0
- package/dist/esm/utils/use-click-prevention-on-double-click.js +42 -0
- package/dist/esm/utils/use-element-size.d.ts +16 -0
- package/dist/esm/utils/use-element-size.js +93 -0
- package/dist/esm/utils/validate-in-out-frame.d.ts +6 -0
- package/dist/esm/utils/validate-in-out-frame.js +49 -0
- package/dist/esm/utils/validate-initial-frame.d.ts +4 -0
- package/dist/esm/utils/validate-initial-frame.js +23 -0
- package/dist/esm/utils/validate-playbackrate.d.ts +1 -0
- package/dist/esm/utils/validate-playbackrate.js +14 -0
- package/dist/esm/volume-persistance.d.ts +2 -0
- package/dist/esm/volume-persistance.js +14 -0
- package/dist/event-emitter.d.ts +33 -9
- package/dist/event-emitter.js +33 -1
- package/dist/format-time.d.ts +0 -0
- package/dist/format-time.js +0 -0
- package/dist/icons.d.ts +2 -1
- package/dist/icons.js +7 -7
- package/dist/index.d.ts +25 -9
- package/dist/index.js +5 -2
- package/dist/player-css-classname.d.ts +0 -1
- package/dist/player-css-classname.js +1 -2
- package/dist/player-methods.d.ts +8 -4
- package/dist/player-methods.js +0 -0
- package/dist/test/index.test.d.ts +0 -0
- package/dist/test/index.test.js +3 -2
- package/dist/test/test-utils.d.ts +2 -2
- package/dist/test/test-utils.js +0 -0
- package/dist/test/validate-in-out-frames.test.d.ts +1 -0
- package/dist/test/validate-in-out-frames.test.js +56 -0
- package/dist/test/validate-prop.test.d.ts +0 -0
- package/dist/test/validate-prop.test.js +24 -23
- package/dist/tsconfig-cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/use-hover-state.d.ts +0 -0
- package/dist/use-hover-state.js +0 -0
- package/dist/use-playback.d.ts +4 -1
- package/dist/use-playback.js +7 -3
- package/dist/use-player.d.ts +8 -3
- package/dist/use-player.js +23 -4
- package/dist/use-thumbnail.d.ts +6 -0
- package/dist/use-thumbnail.js +18 -0
- package/dist/use-video-controls-resize.d.ts +7 -0
- package/dist/use-video-controls-resize.js +36 -0
- package/dist/utils/calculate-player-size.d.ts +2 -2
- package/dist/utils/calculate-player-size.js +0 -0
- package/dist/utils/cancellable-promise.d.ts +0 -0
- package/dist/utils/cancellable-promise.js +0 -0
- package/dist/utils/delay.d.ts +0 -0
- package/dist/utils/delay.js +0 -0
- package/dist/utils/is-node.d.ts +0 -0
- package/dist/utils/is-node.js +0 -0
- package/dist/utils/preview-size.d.ts +8 -1
- package/dist/utils/preview-size.js +0 -0
- package/dist/utils/props-if-has-props.d.ts +5 -0
- package/dist/utils/props-if-has-props.js +2 -0
- package/dist/utils/use-cancellable-promises.d.ts +1 -1
- package/dist/utils/use-cancellable-promises.js +0 -0
- package/dist/utils/use-click-prevention-on-double-click.d.ts +1 -1
- package/dist/utils/use-click-prevention-on-double-click.js +0 -0
- package/dist/utils/use-element-size.d.ts +4 -0
- package/dist/utils/use-element-size.js +8 -0
- package/dist/utils/validate-in-out-frame.d.ts +6 -0
- package/dist/utils/validate-in-out-frame.js +54 -0
- package/dist/utils/validate-initial-frame.d.ts +4 -0
- package/dist/utils/validate-initial-frame.js +27 -0
- package/dist/utils/validate-playbackrate.d.ts +0 -0
- package/dist/utils/validate-playbackrate.js +0 -0
- package/dist/volume-persistance.d.ts +0 -0
- package/dist/volume-persistance.js +0 -0
- package/package.json +26 -17
- package/dist/MediaVolumeSlider.d.ts.map +0 -1
- package/dist/MediaVolumeSlider.js.map +0 -1
- package/dist/Player.d.ts.map +0 -1
- package/dist/Player.js.map +0 -1
- package/dist/PlayerControls.d.ts.map +0 -1
- package/dist/PlayerControls.js.map +0 -1
- package/dist/PlayerSeekBar.d.ts.map +0 -1
- package/dist/PlayerSeekBar.js.map +0 -1
- package/dist/PlayerUI.d.ts.map +0 -1
- package/dist/PlayerUI.js.map +0 -1
- package/dist/calculate-next-frame.d.ts.map +0 -1
- package/dist/calculate-next-frame.js.map +0 -1
- package/dist/calculate-scale.d.ts.map +0 -1
- package/dist/calculate-scale.js.map +0 -1
- package/dist/emitter-context.d.ts.map +0 -1
- package/dist/emitter-context.js.map +0 -1
- package/dist/error-boundary.d.ts.map +0 -1
- package/dist/error-boundary.js.map +0 -1
- package/dist/event-emitter.d.ts.map +0 -1
- package/dist/event-emitter.js.map +0 -1
- package/dist/format-time.d.ts.map +0 -1
- package/dist/format-time.js.map +0 -1
- package/dist/icons.d.ts.map +0 -1
- package/dist/icons.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/player-css-classname.d.ts.map +0 -1
- package/dist/player-css-classname.js.map +0 -1
- package/dist/player-methods.d.ts.map +0 -1
- package/dist/player-methods.js.map +0 -1
- package/dist/test/index.test.d.ts.map +0 -1
- package/dist/test/index.test.js.map +0 -1
- package/dist/test/test-utils.d.ts.map +0 -1
- package/dist/test/test-utils.js.map +0 -1
- package/dist/test/validate-prop.test.d.ts.map +0 -1
- package/dist/test/validate-prop.test.js.map +0 -1
- package/dist/use-hover-state.d.ts.map +0 -1
- package/dist/use-hover-state.js.map +0 -1
- package/dist/use-playback.d.ts.map +0 -1
- package/dist/use-playback.js.map +0 -1
- package/dist/use-player.d.ts.map +0 -1
- package/dist/use-player.js.map +0 -1
- package/dist/utils/browser-supports-fullscreen.d.ts +0 -11
- package/dist/utils/browser-supports-fullscreen.d.ts.map +0 -1
- package/dist/utils/browser-supports-fullscreen.js +0 -5
- package/dist/utils/browser-supports-fullscreen.js.map +0 -1
- package/dist/utils/calculate-player-size.d.ts.map +0 -1
- package/dist/utils/calculate-player-size.js.map +0 -1
- package/dist/utils/cancellable-promise.d.ts.map +0 -1
- package/dist/utils/cancellable-promise.js.map +0 -1
- package/dist/utils/delay.d.ts.map +0 -1
- package/dist/utils/delay.js.map +0 -1
- package/dist/utils/is-node.d.ts.map +0 -1
- package/dist/utils/is-node.js.map +0 -1
- package/dist/utils/preview-size.d.ts.map +0 -1
- package/dist/utils/preview-size.js.map +0 -1
- package/dist/utils/use-cancellable-promises.d.ts.map +0 -1
- package/dist/utils/use-cancellable-promises.js.map +0 -1
- package/dist/utils/use-click-prevention-on-double-click.d.ts.map +0 -1
- package/dist/utils/use-click-prevention-on-double-click.js.map +0 -1
- package/dist/utils/use-element-size.d.ts.map +0 -1
- package/dist/utils/use-element-size.js.map +0 -1
- package/dist/utils/validate-playbackrate.d.ts.map +0 -1
- package/dist/utils/validate-playbackrate.js.map +0 -1
- package/dist/volume-persistance.d.ts.map +0 -1
- package/dist/volume-persistance.js.map +0 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
+
import { Internals, interpolate } from 'remotion';
|
|
4
|
+
import { useHoverState } from './use-hover-state';
|
|
5
|
+
import { usePlayer } from './use-player';
|
|
6
|
+
import { useElementSize } from './utils/use-element-size';
|
|
7
|
+
const getFrameFromX = (clientX, durationInFrames, width) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const pos = clientX;
|
|
10
|
+
const frame = Math.round(interpolate(pos, [0, width], [0, (_a = durationInFrames - 1) !== null && _a !== void 0 ? _a : 0], {
|
|
11
|
+
extrapolateLeft: 'clamp',
|
|
12
|
+
extrapolateRight: 'clamp',
|
|
13
|
+
}));
|
|
14
|
+
return frame;
|
|
15
|
+
};
|
|
16
|
+
const BAR_HEIGHT = 5;
|
|
17
|
+
const KNOB_SIZE = 12;
|
|
18
|
+
const VERTICAL_PADDING = 4;
|
|
19
|
+
const containerStyle = {
|
|
20
|
+
userSelect: 'none',
|
|
21
|
+
paddingTop: VERTICAL_PADDING,
|
|
22
|
+
paddingBottom: VERTICAL_PADDING,
|
|
23
|
+
boxSizing: 'border-box',
|
|
24
|
+
cursor: 'pointer',
|
|
25
|
+
position: 'relative',
|
|
26
|
+
touchAction: 'none',
|
|
27
|
+
};
|
|
28
|
+
const barBackground = {
|
|
29
|
+
height: BAR_HEIGHT,
|
|
30
|
+
backgroundColor: 'rgba(255, 255, 255, 0.25)',
|
|
31
|
+
width: '100%',
|
|
32
|
+
borderRadius: BAR_HEIGHT / 2,
|
|
33
|
+
};
|
|
34
|
+
const findBodyInWhichDivIsLocated = (div) => {
|
|
35
|
+
let current = div;
|
|
36
|
+
while (current.parentElement) {
|
|
37
|
+
current = current.parentElement;
|
|
38
|
+
}
|
|
39
|
+
return current;
|
|
40
|
+
};
|
|
41
|
+
export const PlayerSeekBar = ({ durationInFrames, onSeekEnd, onSeekStart, inFrame, outFrame }) => {
|
|
42
|
+
const containerRef = useRef(null);
|
|
43
|
+
const barHovered = useHoverState(containerRef);
|
|
44
|
+
const size = useElementSize(containerRef, {
|
|
45
|
+
triggerOnWindowResize: true,
|
|
46
|
+
shouldApplyCssTransforms: true,
|
|
47
|
+
});
|
|
48
|
+
const { seek, play, pause, playing } = usePlayer();
|
|
49
|
+
const frame = Internals.Timeline.useTimelinePosition();
|
|
50
|
+
const [dragging, setDragging] = useState({
|
|
51
|
+
dragging: false,
|
|
52
|
+
});
|
|
53
|
+
const onPointerDown = useCallback((e) => {
|
|
54
|
+
if (!size) {
|
|
55
|
+
throw new Error('Player has no size');
|
|
56
|
+
}
|
|
57
|
+
const _frame = getFrameFromX(e.clientX - size.left, durationInFrames, size.width);
|
|
58
|
+
pause();
|
|
59
|
+
seek(_frame);
|
|
60
|
+
setDragging({
|
|
61
|
+
dragging: true,
|
|
62
|
+
wasPlaying: playing,
|
|
63
|
+
});
|
|
64
|
+
onSeekStart();
|
|
65
|
+
}, [size, durationInFrames, pause, seek, playing, onSeekStart]);
|
|
66
|
+
const onPointerMove = useCallback((e) => {
|
|
67
|
+
var _a;
|
|
68
|
+
if (!size) {
|
|
69
|
+
throw new Error('Player has no size');
|
|
70
|
+
}
|
|
71
|
+
if (!dragging.dragging) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const _frame = getFrameFromX(e.clientX - ((_a = size === null || size === void 0 ? void 0 : size.left) !== null && _a !== void 0 ? _a : 0), durationInFrames, size.width);
|
|
75
|
+
seek(_frame);
|
|
76
|
+
}, [dragging.dragging, durationInFrames, seek, size]);
|
|
77
|
+
const onPointerUp = useCallback(() => {
|
|
78
|
+
setDragging({
|
|
79
|
+
dragging: false,
|
|
80
|
+
});
|
|
81
|
+
if (!dragging.dragging) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (dragging.wasPlaying) {
|
|
85
|
+
play();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
pause();
|
|
89
|
+
}
|
|
90
|
+
onSeekEnd();
|
|
91
|
+
}, [dragging, onSeekEnd, pause, play]);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (!dragging.dragging) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const body = findBodyInWhichDivIsLocated(containerRef.current);
|
|
97
|
+
body.addEventListener('pointermove', onPointerMove);
|
|
98
|
+
body.addEventListener('pointerup', onPointerUp);
|
|
99
|
+
return () => {
|
|
100
|
+
body.removeEventListener('pointermove', onPointerMove);
|
|
101
|
+
body.removeEventListener('pointerup', onPointerUp);
|
|
102
|
+
};
|
|
103
|
+
}, [dragging.dragging, onPointerMove, onPointerUp]);
|
|
104
|
+
const knobStyle = useMemo(() => {
|
|
105
|
+
var _a;
|
|
106
|
+
return {
|
|
107
|
+
height: KNOB_SIZE,
|
|
108
|
+
width: KNOB_SIZE,
|
|
109
|
+
borderRadius: KNOB_SIZE / 2,
|
|
110
|
+
position: 'absolute',
|
|
111
|
+
top: VERTICAL_PADDING - KNOB_SIZE / 2 + 5 / 2,
|
|
112
|
+
backgroundColor: 'white',
|
|
113
|
+
left: Math.max(0, (frame / Math.max(1, durationInFrames - 1)) * ((_a = size === null || size === void 0 ? void 0 : size.width) !== null && _a !== void 0 ? _a : 0) -
|
|
114
|
+
KNOB_SIZE / 2),
|
|
115
|
+
boxShadow: '0 0 2px black',
|
|
116
|
+
opacity: Number(barHovered),
|
|
117
|
+
};
|
|
118
|
+
}, [barHovered, durationInFrames, frame, size]);
|
|
119
|
+
const fillStyle = useMemo(() => {
|
|
120
|
+
return {
|
|
121
|
+
height: BAR_HEIGHT,
|
|
122
|
+
backgroundColor: 'rgba(255, 255, 255, 1)',
|
|
123
|
+
width: ((frame - (inFrame !== null && inFrame !== void 0 ? inFrame : 0)) / (durationInFrames - 1)) * 100 + '%',
|
|
124
|
+
marginLeft: ((inFrame !== null && inFrame !== void 0 ? inFrame : 0) / (durationInFrames - 1)) * 100 + '%',
|
|
125
|
+
borderRadius: BAR_HEIGHT / 2,
|
|
126
|
+
};
|
|
127
|
+
}, [durationInFrames, frame, inFrame]);
|
|
128
|
+
const active = useMemo(() => {
|
|
129
|
+
return {
|
|
130
|
+
height: BAR_HEIGHT,
|
|
131
|
+
backgroundColor: 'rgba(255, 255, 255, 0.25)',
|
|
132
|
+
width: (((outFrame !== null && outFrame !== void 0 ? outFrame : durationInFrames - 1) - (inFrame !== null && inFrame !== void 0 ? inFrame : 0)) /
|
|
133
|
+
(durationInFrames - 1)) *
|
|
134
|
+
100 +
|
|
135
|
+
'%',
|
|
136
|
+
marginLeft: ((inFrame !== null && inFrame !== void 0 ? inFrame : 0) / (durationInFrames - 1)) * 100 + '%',
|
|
137
|
+
borderRadius: BAR_HEIGHT / 2,
|
|
138
|
+
position: 'absolute',
|
|
139
|
+
};
|
|
140
|
+
}, [durationInFrames, inFrame, outFrame]);
|
|
141
|
+
return (_jsxs("div", { ref: containerRef, onPointerDown: onPointerDown, style: containerStyle, children: [_jsxs("div", { style: barBackground, children: [_jsx("div", { style: active }), _jsx("div", { style: fillStyle })] }), _jsx("div", { style: knobStyle })] }));
|
|
142
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PlayerRef } from './player-methods';
|
|
3
|
+
import type { RenderFullscreenButton, RenderPlayPauseButton } from './PlayerControls';
|
|
4
|
+
export declare type ErrorFallback = (info: {
|
|
5
|
+
error: Error;
|
|
6
|
+
}) => React.ReactNode;
|
|
7
|
+
export declare type RenderLoading = (canvas: {
|
|
8
|
+
height: number;
|
|
9
|
+
width: number;
|
|
10
|
+
}) => React.ReactNode;
|
|
11
|
+
export declare type RenderPoster = RenderLoading;
|
|
12
|
+
declare const _default: React.ForwardRefExoticComponent<{
|
|
13
|
+
controls: boolean;
|
|
14
|
+
loop: boolean;
|
|
15
|
+
autoPlay: boolean;
|
|
16
|
+
allowFullscreen: boolean;
|
|
17
|
+
inputProps: unknown;
|
|
18
|
+
showVolumeControls: boolean;
|
|
19
|
+
style?: React.CSSProperties | undefined;
|
|
20
|
+
clickToPlay: boolean;
|
|
21
|
+
doubleClickToFullscreen: boolean;
|
|
22
|
+
spaceKeyToPlayOrPause: boolean;
|
|
23
|
+
errorFallback: ErrorFallback;
|
|
24
|
+
playbackRate: number;
|
|
25
|
+
renderLoading: RenderLoading | undefined;
|
|
26
|
+
renderPoster: RenderLoading | undefined;
|
|
27
|
+
className: string | undefined;
|
|
28
|
+
moveToBeginningWhenEnded: boolean;
|
|
29
|
+
showPosterWhenPaused: boolean;
|
|
30
|
+
showPosterWhenEnded: boolean;
|
|
31
|
+
showPosterWhenUnplayed: boolean;
|
|
32
|
+
inFrame: number | null;
|
|
33
|
+
outFrame: number | null;
|
|
34
|
+
initiallyShowControls: number | boolean;
|
|
35
|
+
renderPlayPauseButton: RenderPlayPauseButton | null;
|
|
36
|
+
renderFullscreen: RenderFullscreenButton | null;
|
|
37
|
+
} & React.RefAttributes<PlayerRef>>;
|
|
38
|
+
export default _default;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { forwardRef, Suspense, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
3
|
+
import { Internals } from 'remotion';
|
|
4
|
+
import { calculateCanvasTransformation, calculateContainerStyle, calculateOuter, calculateOuterStyle, } from './calculate-scale';
|
|
5
|
+
import { ErrorBoundary } from './error-boundary';
|
|
6
|
+
import { PLAYER_CSS_CLASSNAME } from './player-css-classname';
|
|
7
|
+
import { Controls } from './PlayerControls';
|
|
8
|
+
import { useHoverState } from './use-hover-state';
|
|
9
|
+
import { usePlayback } from './use-playback';
|
|
10
|
+
import { usePlayer } from './use-player';
|
|
11
|
+
import { IS_NODE } from './utils/is-node';
|
|
12
|
+
import { useClickPreventionOnDoubleClick } from './utils/use-click-prevention-on-double-click';
|
|
13
|
+
import { useElementSize } from './utils/use-element-size';
|
|
14
|
+
const reactVersion = React.version.split('.')[0];
|
|
15
|
+
if (reactVersion === '0') {
|
|
16
|
+
throw new Error(`Version ${reactVersion} of "react" is not supported by Remotion`);
|
|
17
|
+
}
|
|
18
|
+
const doesReactVersionSupportSuspense = parseInt(reactVersion, 10) >= 18;
|
|
19
|
+
const PlayerUI = ({ controls, style, loop, autoPlay, allowFullscreen, inputProps, clickToPlay, showVolumeControls, doubleClickToFullscreen, spaceKeyToPlayOrPause, errorFallback, playbackRate, renderLoading, renderPoster, className, moveToBeginningWhenEnded, showPosterWhenUnplayed, showPosterWhenEnded, showPosterWhenPaused, inFrame, outFrame, initiallyShowControls, renderFullscreen: renderFullscreenButton, renderPlayPauseButton, }, ref) => {
|
|
20
|
+
var _a, _b, _c, _d, _e;
|
|
21
|
+
const config = Internals.useUnsafeVideoConfig();
|
|
22
|
+
const video = Internals.useVideo();
|
|
23
|
+
const container = useRef(null);
|
|
24
|
+
const hovered = useHoverState(container);
|
|
25
|
+
const canvasSize = useElementSize(container, {
|
|
26
|
+
triggerOnWindowResize: false,
|
|
27
|
+
shouldApplyCssTransforms: false,
|
|
28
|
+
});
|
|
29
|
+
const [hasPausedToResume, setHasPausedToResume] = useState(false);
|
|
30
|
+
const [shouldAutoplay, setShouldAutoPlay] = useState(autoPlay);
|
|
31
|
+
const [isFullscreen, setIsFullscreen] = useState(() => false);
|
|
32
|
+
const [seeking, setSeeking] = useState(false);
|
|
33
|
+
usePlayback({
|
|
34
|
+
loop,
|
|
35
|
+
playbackRate,
|
|
36
|
+
moveToBeginningWhenEnded,
|
|
37
|
+
inFrame,
|
|
38
|
+
outFrame,
|
|
39
|
+
});
|
|
40
|
+
const player = usePlayer();
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (hasPausedToResume && !player.playing) {
|
|
43
|
+
setHasPausedToResume(false);
|
|
44
|
+
player.play();
|
|
45
|
+
}
|
|
46
|
+
}, [hasPausedToResume, player]);
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const { current } = container;
|
|
49
|
+
if (!current) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const onFullscreenChange = () => {
|
|
53
|
+
setIsFullscreen(document.fullscreenElement === current ||
|
|
54
|
+
document.webkitFullscreenElement === current);
|
|
55
|
+
};
|
|
56
|
+
document.addEventListener('fullscreenchange', onFullscreenChange);
|
|
57
|
+
document.addEventListener('webkitfullscreenchange', onFullscreenChange);
|
|
58
|
+
return () => {
|
|
59
|
+
document.removeEventListener('fullscreenchange', onFullscreenChange);
|
|
60
|
+
document.removeEventListener('webkitfullscreenchange', onFullscreenChange);
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
63
|
+
const toggle = useCallback((e) => {
|
|
64
|
+
if (player.isPlaying()) {
|
|
65
|
+
player.pause();
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
player.play(e);
|
|
69
|
+
}
|
|
70
|
+
}, [player]);
|
|
71
|
+
const requestFullscreen = useCallback(() => {
|
|
72
|
+
if (!allowFullscreen) {
|
|
73
|
+
throw new Error('allowFullscreen is false');
|
|
74
|
+
}
|
|
75
|
+
const supportsFullScreen = document.fullscreenEnabled || document.webkitFullscreenEnabled;
|
|
76
|
+
if (!supportsFullScreen) {
|
|
77
|
+
throw new Error('Browser doesnt support fullscreen');
|
|
78
|
+
}
|
|
79
|
+
if (!container.current) {
|
|
80
|
+
throw new Error('No player ref found');
|
|
81
|
+
}
|
|
82
|
+
if (container.current.webkitRequestFullScreen) {
|
|
83
|
+
container.current.webkitRequestFullScreen();
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
container.current.requestFullscreen();
|
|
87
|
+
}
|
|
88
|
+
}, [allowFullscreen]);
|
|
89
|
+
const exitFullscreen = useCallback(() => {
|
|
90
|
+
if (document.webkitExitFullscreen) {
|
|
91
|
+
document.webkitExitFullscreen();
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
document.exitFullscreen();
|
|
95
|
+
}
|
|
96
|
+
}, []);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
const { current } = container;
|
|
99
|
+
if (!current) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const fullscreenChange = () => {
|
|
103
|
+
var _a;
|
|
104
|
+
const element = (_a = document.webkitFullscreenElement) !== null && _a !== void 0 ? _a : document.fullscreenElement;
|
|
105
|
+
if (element && element === container.current) {
|
|
106
|
+
player.emitter.dispatchFullscreenChangeUpdate({
|
|
107
|
+
isFullscreen: true,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
player.emitter.dispatchFullscreenChangeUpdate({
|
|
112
|
+
isFullscreen: false,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
current.addEventListener('webkitfullscreenchange', fullscreenChange);
|
|
117
|
+
current.addEventListener('fullscreenchange', fullscreenChange);
|
|
118
|
+
return () => {
|
|
119
|
+
current.removeEventListener('webkitfullscreenchange', fullscreenChange);
|
|
120
|
+
current.removeEventListener('fullscreenchange', fullscreenChange);
|
|
121
|
+
};
|
|
122
|
+
}, [player.emitter]);
|
|
123
|
+
const durationInFrames = (_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1;
|
|
124
|
+
const layout = useMemo(() => {
|
|
125
|
+
if (!config || !canvasSize) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return calculateCanvasTransformation({
|
|
129
|
+
canvasSize,
|
|
130
|
+
compositionHeight: config.height,
|
|
131
|
+
compositionWidth: config.width,
|
|
132
|
+
previewSize: 'auto',
|
|
133
|
+
});
|
|
134
|
+
}, [canvasSize, config]);
|
|
135
|
+
const scale = (_b = layout === null || layout === void 0 ? void 0 : layout.scale) !== null && _b !== void 0 ? _b : 1;
|
|
136
|
+
const { setMediaVolume, setMediaMuted } = useContext(Internals.SetMediaVolumeContext);
|
|
137
|
+
const { mediaMuted, mediaVolume } = useContext(Internals.MediaVolumeContext);
|
|
138
|
+
useImperativeHandle(ref, () => {
|
|
139
|
+
const methods = {
|
|
140
|
+
play: player.play,
|
|
141
|
+
pause: player.pause,
|
|
142
|
+
toggle,
|
|
143
|
+
getContainerNode: () => container.current,
|
|
144
|
+
getCurrentFrame: player.getCurrentFrame,
|
|
145
|
+
isPlaying: () => player.playing,
|
|
146
|
+
seekTo: (f) => {
|
|
147
|
+
const lastFrame = durationInFrames - 1;
|
|
148
|
+
const frameToSeekTo = Math.max(0, Math.min(lastFrame, f));
|
|
149
|
+
if (player.isPlaying()) {
|
|
150
|
+
const pauseToResume = frameToSeekTo !== lastFrame || loop;
|
|
151
|
+
setHasPausedToResume(pauseToResume);
|
|
152
|
+
player.pause();
|
|
153
|
+
}
|
|
154
|
+
if (frameToSeekTo === lastFrame && !loop) {
|
|
155
|
+
player.emitter.dispatchEnded();
|
|
156
|
+
}
|
|
157
|
+
player.seek(frameToSeekTo);
|
|
158
|
+
},
|
|
159
|
+
isFullscreen: () => isFullscreen,
|
|
160
|
+
requestFullscreen,
|
|
161
|
+
exitFullscreen,
|
|
162
|
+
getVolume: () => {
|
|
163
|
+
if (mediaMuted) {
|
|
164
|
+
return 0;
|
|
165
|
+
}
|
|
166
|
+
return mediaVolume;
|
|
167
|
+
},
|
|
168
|
+
setVolume: (vol) => {
|
|
169
|
+
if (typeof vol !== 'number') {
|
|
170
|
+
throw new TypeError(`setVolume() takes a number, got value of type ${typeof vol}`);
|
|
171
|
+
}
|
|
172
|
+
if (isNaN(vol)) {
|
|
173
|
+
throw new TypeError(`setVolume() got a number that is NaN. Volume must be between 0 and 1.`);
|
|
174
|
+
}
|
|
175
|
+
if (vol < 0 || vol > 1) {
|
|
176
|
+
throw new TypeError(`setVolume() got a number that is out of range. Must be between 0 and 1, got ${typeof vol}`);
|
|
177
|
+
}
|
|
178
|
+
setMediaVolume(vol);
|
|
179
|
+
},
|
|
180
|
+
isMuted: () => mediaMuted || mediaVolume === 0,
|
|
181
|
+
mute: () => {
|
|
182
|
+
setMediaMuted(true);
|
|
183
|
+
},
|
|
184
|
+
unmute: () => {
|
|
185
|
+
setMediaMuted(false);
|
|
186
|
+
},
|
|
187
|
+
getScale: () => scale,
|
|
188
|
+
};
|
|
189
|
+
return Object.assign(player.emitter, methods);
|
|
190
|
+
}, [
|
|
191
|
+
durationInFrames,
|
|
192
|
+
exitFullscreen,
|
|
193
|
+
isFullscreen,
|
|
194
|
+
loop,
|
|
195
|
+
mediaMuted,
|
|
196
|
+
mediaVolume,
|
|
197
|
+
player,
|
|
198
|
+
requestFullscreen,
|
|
199
|
+
setMediaMuted,
|
|
200
|
+
setMediaVolume,
|
|
201
|
+
toggle,
|
|
202
|
+
scale,
|
|
203
|
+
]);
|
|
204
|
+
const VideoComponent = video ? video.component : null;
|
|
205
|
+
const outerStyle = useMemo(() => {
|
|
206
|
+
return calculateOuterStyle({ canvasSize, config, style });
|
|
207
|
+
}, [canvasSize, config, style]);
|
|
208
|
+
const outer = useMemo(() => {
|
|
209
|
+
return calculateOuter({ config, layout, scale });
|
|
210
|
+
}, [config, layout, scale]);
|
|
211
|
+
const containerStyle = useMemo(() => {
|
|
212
|
+
return calculateContainerStyle({ canvasSize, config, layout, scale });
|
|
213
|
+
}, [canvasSize, config, layout, scale]);
|
|
214
|
+
const onError = useCallback((error) => {
|
|
215
|
+
player.pause();
|
|
216
|
+
// Pay attention to `this context`
|
|
217
|
+
player.emitter.dispatchError(error);
|
|
218
|
+
}, [player]);
|
|
219
|
+
const onFullscreenButtonClick = useCallback((e) => {
|
|
220
|
+
e.stopPropagation();
|
|
221
|
+
requestFullscreen();
|
|
222
|
+
}, [requestFullscreen]);
|
|
223
|
+
const onExitFullscreenButtonClick = useCallback((e) => {
|
|
224
|
+
e.stopPropagation();
|
|
225
|
+
exitFullscreen();
|
|
226
|
+
}, [exitFullscreen]);
|
|
227
|
+
const onSingleClick = useCallback((e) => {
|
|
228
|
+
toggle(e);
|
|
229
|
+
}, [toggle]);
|
|
230
|
+
const onSeekStart = useCallback(() => {
|
|
231
|
+
setSeeking(true);
|
|
232
|
+
}, []);
|
|
233
|
+
const onSeekEnd = useCallback(() => {
|
|
234
|
+
setSeeking(false);
|
|
235
|
+
}, []);
|
|
236
|
+
const onDoubleClick = useCallback(() => {
|
|
237
|
+
if (isFullscreen) {
|
|
238
|
+
exitFullscreen();
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
requestFullscreen();
|
|
242
|
+
}
|
|
243
|
+
}, [exitFullscreen, isFullscreen, requestFullscreen]);
|
|
244
|
+
const [handleClick, handleDoubleClick] = useClickPreventionOnDoubleClick(onSingleClick, onDoubleClick, doubleClickToFullscreen);
|
|
245
|
+
useEffect(() => {
|
|
246
|
+
if (shouldAutoplay) {
|
|
247
|
+
player.play();
|
|
248
|
+
setShouldAutoPlay(false);
|
|
249
|
+
}
|
|
250
|
+
}, [shouldAutoplay, player]);
|
|
251
|
+
const loadingMarkup = useMemo(() => {
|
|
252
|
+
return renderLoading
|
|
253
|
+
? renderLoading({
|
|
254
|
+
height: outerStyle.height,
|
|
255
|
+
width: outerStyle.width,
|
|
256
|
+
})
|
|
257
|
+
: null;
|
|
258
|
+
}, [outerStyle.height, outerStyle.width, renderLoading]);
|
|
259
|
+
if (!config) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
const poster = renderPoster
|
|
263
|
+
? renderPoster({
|
|
264
|
+
height: outerStyle.height,
|
|
265
|
+
width: outerStyle.width,
|
|
266
|
+
})
|
|
267
|
+
: null;
|
|
268
|
+
if (poster === undefined) {
|
|
269
|
+
throw new TypeError('renderPoster() must return a React element, but undefined was returned');
|
|
270
|
+
}
|
|
271
|
+
const shouldShowPoster = poster &&
|
|
272
|
+
[
|
|
273
|
+
showPosterWhenPaused && !player.isPlaying() && !seeking,
|
|
274
|
+
showPosterWhenEnded && player.isLastFrame && !player.isPlaying(),
|
|
275
|
+
showPosterWhenUnplayed && !player.hasPlayed && !player.isPlaying(),
|
|
276
|
+
].some(Boolean);
|
|
277
|
+
const content = (_jsxs(_Fragment, { children: [_jsx("div", { style: outer, onClick: clickToPlay ? handleClick : undefined, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, children: _jsx("div", { style: containerStyle, className: PLAYER_CSS_CLASSNAME, children: VideoComponent ? (_jsx(ErrorBoundary, { onError: onError, errorFallback: errorFallback, children: _jsx(VideoComponent, { ...((_c = video === null || video === void 0 ? void 0 : video.defaultProps) !== null && _c !== void 0 ? _c : {}), ...((_d = inputProps) !== null && _d !== void 0 ? _d : {}) }) })) : null }) }), shouldShowPoster ? (_jsx("div", { style: outer, onClick: clickToPlay ? handleClick : undefined, onDoubleClick: doubleClickToFullscreen ? handleDoubleClick : undefined, children: poster })) : null, controls ? (_jsx(Controls, { fps: config.fps, durationInFrames: config.durationInFrames, hovered: hovered, player: player, onFullscreenButtonClick: onFullscreenButtonClick, isFullscreen: isFullscreen, allowFullscreen: allowFullscreen, showVolumeControls: showVolumeControls, onExitFullscreenButtonClick: onExitFullscreenButtonClick, spaceKeyToPlayOrPause: spaceKeyToPlayOrPause, onSeekEnd: onSeekEnd, onSeekStart: onSeekStart, inFrame: inFrame, outFrame: outFrame, initiallyShowControls: initiallyShowControls, playerWidth: (_e = canvasSize === null || canvasSize === void 0 ? void 0 : canvasSize.width) !== null && _e !== void 0 ? _e : 0, renderFullscreenButton: renderFullscreenButton, renderPlayPauseButton: renderPlayPauseButton })) : null] }));
|
|
278
|
+
if (IS_NODE && !doesReactVersionSupportSuspense) {
|
|
279
|
+
return (_jsx("div", { ref: container, style: outerStyle, className: className, children: content }));
|
|
280
|
+
}
|
|
281
|
+
return (_jsx("div", { ref: container, style: outerStyle, className: className, children: _jsx(Suspense, { fallback: loadingMarkup, children: content }) }));
|
|
282
|
+
};
|
|
283
|
+
export default forwardRef(PlayerUI);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ComponentType, LazyExoticComponent } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { TimelineContextValue } from 'remotion';
|
|
4
|
+
export declare const SharedPlayerContexts: React.FC<{
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
timelineContext: TimelineContextValue;
|
|
7
|
+
inputProps?: unknown;
|
|
8
|
+
fps: number;
|
|
9
|
+
compositionWidth: number;
|
|
10
|
+
compositionHeight: number;
|
|
11
|
+
durationInFrames: number;
|
|
12
|
+
component: LazyExoticComponent<ComponentType<unknown>>;
|
|
13
|
+
numberOfSharedAudioTags: number;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import { Internals } from 'remotion';
|
|
4
|
+
import { getPreferredVolume, persistVolume } from './volume-persistance';
|
|
5
|
+
export const SharedPlayerContexts = ({ children, timelineContext, inputProps, fps, compositionHeight, compositionWidth, durationInFrames, component, numberOfSharedAudioTags, }) => {
|
|
6
|
+
const compositionManagerContext = useMemo(() => {
|
|
7
|
+
return {
|
|
8
|
+
compositions: [
|
|
9
|
+
{
|
|
10
|
+
component: component,
|
|
11
|
+
durationInFrames,
|
|
12
|
+
height: compositionHeight,
|
|
13
|
+
width: compositionWidth,
|
|
14
|
+
fps,
|
|
15
|
+
id: 'player-comp',
|
|
16
|
+
props: inputProps,
|
|
17
|
+
nonce: 777,
|
|
18
|
+
scale: 1,
|
|
19
|
+
folderName: null,
|
|
20
|
+
defaultProps: undefined,
|
|
21
|
+
parentFolderName: null,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
folders: [],
|
|
25
|
+
registerFolder: () => undefined,
|
|
26
|
+
unregisterFolder: () => undefined,
|
|
27
|
+
currentComposition: 'player-comp',
|
|
28
|
+
registerComposition: () => undefined,
|
|
29
|
+
registerSequence: () => undefined,
|
|
30
|
+
sequences: [],
|
|
31
|
+
setCurrentComposition: () => undefined,
|
|
32
|
+
unregisterComposition: () => undefined,
|
|
33
|
+
unregisterSequence: () => undefined,
|
|
34
|
+
registerAsset: () => undefined,
|
|
35
|
+
unregisterAsset: () => undefined,
|
|
36
|
+
currentCompositionMetadata: null,
|
|
37
|
+
setCurrentCompositionMetadata: () => undefined,
|
|
38
|
+
assets: [],
|
|
39
|
+
setClipRegion: () => undefined,
|
|
40
|
+
};
|
|
41
|
+
}, [
|
|
42
|
+
component,
|
|
43
|
+
durationInFrames,
|
|
44
|
+
compositionHeight,
|
|
45
|
+
compositionWidth,
|
|
46
|
+
fps,
|
|
47
|
+
inputProps,
|
|
48
|
+
]);
|
|
49
|
+
const [mediaMuted, setMediaMuted] = useState(false);
|
|
50
|
+
const [mediaVolume, setMediaVolume] = useState(getPreferredVolume());
|
|
51
|
+
const mediaVolumeContextValue = useMemo(() => {
|
|
52
|
+
return {
|
|
53
|
+
mediaMuted,
|
|
54
|
+
mediaVolume,
|
|
55
|
+
};
|
|
56
|
+
}, [mediaMuted, mediaVolume]);
|
|
57
|
+
const setMediaVolumeAndPersist = useCallback((vol) => {
|
|
58
|
+
setMediaVolume(vol);
|
|
59
|
+
persistVolume(vol);
|
|
60
|
+
}, []);
|
|
61
|
+
const setMediaVolumeContextValue = useMemo(() => {
|
|
62
|
+
return {
|
|
63
|
+
setMediaMuted,
|
|
64
|
+
setMediaVolume: setMediaVolumeAndPersist,
|
|
65
|
+
};
|
|
66
|
+
}, [setMediaVolumeAndPersist]);
|
|
67
|
+
return (_jsx(Internals.CanUseRemotionHooksProvider, { children: _jsx(Internals.Timeline.TimelineContext.Provider, { value: timelineContext, children: _jsx(Internals.CompositionManager.Provider, { value: compositionManagerContext, children: _jsx(Internals.PrefetchProvider, { children: _jsx(Internals.DurationsContextProvider, { children: _jsx(Internals.MediaVolumeContext.Provider, { value: mediaVolumeContextValue, children: _jsx(Internals.SetMediaVolumeContext.Provider, { value: setMediaVolumeContextValue, children: _jsx(Internals.SharedAudioContextProvider, { numberOfAudioTags: numberOfSharedAudioTags, children: children }) }) }) }) }) }) }) }));
|
|
68
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CSSProperties, MutableRefObject } from 'react';
|
|
2
|
+
import type { CompProps } from 'remotion';
|
|
3
|
+
import type { ThumbnailMethods } from './player-methods';
|
|
4
|
+
import type { ErrorFallback, RenderLoading } from './PlayerUI';
|
|
5
|
+
import type { PropsIfHasProps } from './utils/props-if-has-props';
|
|
6
|
+
declare type ThumbnailProps<T> = PropsIfHasProps<T> & CompProps<T> & {
|
|
7
|
+
frameToDisplay: number;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
durationInFrames: number;
|
|
10
|
+
compositionWidth: number;
|
|
11
|
+
compositionHeight: number;
|
|
12
|
+
inputProps?: unknown;
|
|
13
|
+
fps: number;
|
|
14
|
+
errorFallback?: ErrorFallback;
|
|
15
|
+
renderLoading?: RenderLoading;
|
|
16
|
+
className?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const ThumbnailFn: <T>({ frameToDisplay, style, inputProps, compositionHeight, compositionWidth, durationInFrames, fps, className, errorFallback, renderLoading, ...componentProps }: ThumbnailProps<T>, ref: MutableRefObject<ThumbnailMethods>) => JSX.Element;
|
|
19
|
+
export declare const Thumbnail: <T>(props: ThumbnailProps<T> & import("react").RefAttributes<ThumbnailMethods>) => React.ReactElement | null;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
3
|
+
import { Internals, random } from 'remotion';
|
|
4
|
+
import { ThumbnailEmitterContext } from './emitter-context';
|
|
5
|
+
import { ThumbnailEmitter } from './event-emitter';
|
|
6
|
+
import { SharedPlayerContexts } from './SharedPlayerContext';
|
|
7
|
+
import ThumbnailUI from './ThumbnailUI';
|
|
8
|
+
export const ThumbnailFn = ({ frameToDisplay, style, inputProps, compositionHeight, compositionWidth, durationInFrames, fps, className, errorFallback = () => '⚠️', renderLoading, ...componentProps }, ref) => {
|
|
9
|
+
const [thumbnailId] = useState(() => String(random(null)));
|
|
10
|
+
const rootRef = useRef(null);
|
|
11
|
+
const timelineState = useMemo(() => {
|
|
12
|
+
return {
|
|
13
|
+
playing: false,
|
|
14
|
+
frame: frameToDisplay,
|
|
15
|
+
rootId: thumbnailId,
|
|
16
|
+
imperativePlaying: {
|
|
17
|
+
current: false,
|
|
18
|
+
},
|
|
19
|
+
playbackRate: 1,
|
|
20
|
+
setPlaybackRate: () => {
|
|
21
|
+
throw new Error('thumbnail');
|
|
22
|
+
},
|
|
23
|
+
audioAndVideoTags: { current: [] },
|
|
24
|
+
};
|
|
25
|
+
}, [frameToDisplay, thumbnailId]);
|
|
26
|
+
useImperativeHandle(ref, () => rootRef.current, []);
|
|
27
|
+
const Component = Internals.useLazyComponent(componentProps);
|
|
28
|
+
const [emitter] = useState(() => new ThumbnailEmitter());
|
|
29
|
+
const passedInputProps = useMemo(() => {
|
|
30
|
+
return inputProps !== null && inputProps !== void 0 ? inputProps : {};
|
|
31
|
+
}, [inputProps]);
|
|
32
|
+
return (_jsx(Internals.IsPlayerContextProvider, { children: _jsx(SharedPlayerContexts, { timelineContext: timelineState, component: Component, compositionHeight: compositionHeight, compositionWidth: compositionWidth, durationInFrames: durationInFrames, fps: fps, inputProps: inputProps, numberOfSharedAudioTags: 0, children: _jsx(ThumbnailEmitterContext.Provider, { value: emitter, children: _jsx(ThumbnailUI, { className: className, errorFallback: errorFallback, inputProps: passedInputProps, renderLoading: renderLoading, style: style }) }) }) }));
|
|
33
|
+
};
|
|
34
|
+
const forward = forwardRef;
|
|
35
|
+
export const Thumbnail = forward(ThumbnailFn);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ThumbnailMethods } from './player-methods';
|
|
3
|
+
import type { ErrorFallback, RenderLoading } from './PlayerUI';
|
|
4
|
+
declare const _default: React.ForwardRefExoticComponent<{
|
|
5
|
+
inputProps: unknown;
|
|
6
|
+
style?: React.CSSProperties | undefined;
|
|
7
|
+
errorFallback: ErrorFallback;
|
|
8
|
+
renderLoading: RenderLoading | undefined;
|
|
9
|
+
className: string | undefined;
|
|
10
|
+
} & React.RefAttributes<ThumbnailMethods>>;
|
|
11
|
+
export default _default;
|