@remotion/player 3.3.55 → 3.3.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/esm/calculate-scale.d.ts +1 -1
  2. package/dist/esm/index.d.ts +2 -1
  3. package/dist/esm/test/test-utils.d.ts +2 -2
  4. package/dist/esm/utils/delay.d.ts +1 -1
  5. package/dist/esm/utils/use-cancellable-promises.d.ts +1 -1
  6. package/dist/{tsconfig-cjs.tsbuildinfo → tsconfig-esm.tsbuildinfo} +1 -1
  7. package/dist/tsconfig.tsbuildinfo +1 -1
  8. package/package.json +4 -4
  9. package/dist/esm/MediaVolumeSlider.js +0 -114
  10. package/dist/esm/Player.js +0 -140
  11. package/dist/esm/PlayerControls.js +0 -146
  12. package/dist/esm/PlayerSeekBar.js +0 -142
  13. package/dist/esm/PlayerUI.js +0 -283
  14. package/dist/esm/SharedPlayerContext.js +0 -68
  15. package/dist/esm/Thumbnail.js +0 -39
  16. package/dist/esm/ThumbnailUI.js +0 -82
  17. package/dist/esm/calculate-next-frame.js +0 -24
  18. package/dist/esm/calculate-scale.js +0 -77
  19. package/dist/esm/emitter-context.js +0 -3
  20. package/dist/esm/error-boundary.js +0 -32
  21. package/dist/esm/event-emitter.js +0 -82
  22. package/dist/esm/format-time.js +0 -5
  23. package/dist/esm/icons.js +0 -42
  24. package/dist/esm/index.js +0 -20
  25. package/dist/esm/player-css-classname.js +0 -1
  26. package/dist/esm/player-methods.js +0 -1
  27. package/dist/esm/test/index.test.js +0 -7
  28. package/dist/esm/test/test-utils.js +0 -14
  29. package/dist/esm/test/validate-in-out-frames.test.js +0 -54
  30. package/dist/esm/test/validate-prop.test.js +0 -129
  31. package/dist/esm/use-hover-state.js +0 -23
  32. package/dist/esm/use-playback.js +0 -88
  33. package/dist/esm/use-player.js +0 -128
  34. package/dist/esm/use-thumbnail.js +0 -14
  35. package/dist/esm/use-video-controls-resize.js +0 -35
  36. package/dist/esm/utils/calculate-player-size.js +0 -24
  37. package/dist/esm/utils/cancellable-promise.js +0 -22
  38. package/dist/esm/utils/delay.js +0 -2
  39. package/dist/esm/utils/is-node.js +0 -1
  40. package/dist/esm/utils/preview-size.js +0 -1
  41. package/dist/esm/utils/props-if-has-props.js +0 -1
  42. package/dist/esm/utils/use-cancellable-promises.js +0 -18
  43. package/dist/esm/utils/use-click-prevention-on-double-click.js +0 -42
  44. package/dist/esm/utils/use-element-size.js +0 -93
  45. package/dist/esm/utils/validate-in-out-frame.js +0 -49
  46. package/dist/esm/utils/validate-initial-frame.js +0 -23
  47. package/dist/esm/utils/validate-playbackrate.js +0 -14
  48. package/dist/esm/volume-persistance.js +0 -14
@@ -1,82 +0,0 @@
1
- export class PlayerEmitter {
2
- constructor() {
3
- this.listeners = {
4
- ended: [],
5
- error: [],
6
- pause: [],
7
- play: [],
8
- ratechange: [],
9
- seeked: [],
10
- timeupdate: [],
11
- frameupdate: [],
12
- fullscreenchange: [],
13
- };
14
- }
15
- addEventListener(name, callback) {
16
- this.listeners[name].push(callback);
17
- }
18
- removeEventListener(name, callback) {
19
- this.listeners[name] = this.listeners[name].filter((l) => l !== callback);
20
- }
21
- dispatchEvent(dispatchName, context) {
22
- this.listeners[dispatchName].forEach((callback) => {
23
- callback({ detail: context });
24
- });
25
- }
26
- dispatchSeek(frame) {
27
- this.dispatchEvent('seeked', {
28
- frame,
29
- });
30
- }
31
- dispatchPause() {
32
- this.dispatchEvent('pause', undefined);
33
- }
34
- dispatchPlay() {
35
- this.dispatchEvent('play', undefined);
36
- }
37
- dispatchEnded() {
38
- this.dispatchEvent('ended', undefined);
39
- }
40
- dispatchRatechange(playbackRate) {
41
- this.dispatchEvent('ratechange', {
42
- playbackRate,
43
- });
44
- }
45
- dispatchError(error) {
46
- this.dispatchEvent('error', {
47
- error,
48
- });
49
- }
50
- dispatchTimeUpdate(event) {
51
- this.dispatchEvent('timeupdate', event);
52
- }
53
- dispatchFrameUpdate(event) {
54
- this.dispatchEvent('frameupdate', event);
55
- }
56
- dispatchFullscreenChangeUpdate(event) {
57
- this.dispatchEvent('fullscreenchange', event);
58
- }
59
- }
60
- export class ThumbnailEmitter {
61
- constructor() {
62
- this.listeners = {
63
- error: [],
64
- };
65
- }
66
- addEventListener(name, callback) {
67
- this.listeners[name].push(callback);
68
- }
69
- removeEventListener(name, callback) {
70
- this.listeners[name] = this.listeners[name].filter((l) => l !== callback);
71
- }
72
- dispatchEvent(dispatchName, context) {
73
- this.listeners[dispatchName].forEach((callback) => {
74
- callback({ detail: context });
75
- });
76
- }
77
- dispatchError(error) {
78
- this.dispatchEvent('error', {
79
- error,
80
- });
81
- }
82
- }
@@ -1,5 +0,0 @@
1
- export const formatTime = (timeInSeconds) => {
2
- const minutes = Math.floor(timeInSeconds / 60);
3
- const seconds = Math.floor(timeInSeconds - minutes * 60);
4
- return `${String(minutes)}:${String(seconds).padStart(2, '0')}`;
5
- };
package/dist/esm/icons.js DELETED
@@ -1,42 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- export const ICON_SIZE = 25;
3
- export const fullscreenIconSize = 16;
4
- const rotate = {
5
- transform: `rotate(90deg)`,
6
- };
7
- export const PlayIcon = () => {
8
- return (_jsx("svg", { width: ICON_SIZE, height: ICON_SIZE, viewBox: "-100 -100 400 400", style: rotate, children: _jsx("path", { fill: "#fff", stroke: "#fff", strokeWidth: "100", strokeLinejoin: "round", d: "M 2 172 a 196 100 0 0 0 195 5 A 196 240 0 0 0 100 2.259 A 196 240 0 0 0 2 172 z" }) }));
9
- };
10
- export const PauseIcon = () => {
11
- return (_jsxs("svg", { viewBox: "0 0 100 100", width: ICON_SIZE, height: ICON_SIZE, children: [_jsx("rect", { x: "25", y: "20", width: "20", height: "60", fill: "#fff", ry: "5", rx: "5" }), _jsx("rect", { x: "55", y: "20", width: "20", height: "60", fill: "#fff", ry: "5", rx: "5" })] }));
12
- };
13
- export const FullscreenIcon = ({ isFullscreen, }) => {
14
- const strokeWidth = 6;
15
- const viewSize = 32;
16
- const out = isFullscreen ? 0 : strokeWidth / 2;
17
- const middleInset = isFullscreen ? strokeWidth * 1.6 : strokeWidth / 2;
18
- const inset = isFullscreen ? strokeWidth * 1.6 : strokeWidth * 2;
19
- return (_jsxs("svg", { viewBox: `0 0 ${viewSize} ${viewSize}`, height: fullscreenIconSize, width: fullscreenIconSize, children: [_jsx("path", { d: `
20
- M ${out} ${inset}
21
- L ${middleInset} ${middleInset}
22
- L ${inset} ${out}
23
- `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" }), _jsx("path", { d: `
24
- M ${viewSize - out} ${inset}
25
- L ${viewSize - middleInset} ${middleInset}
26
- L ${viewSize - inset} ${out}
27
- `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" }), _jsx("path", { d: `
28
- M ${out} ${viewSize - inset}
29
- L ${middleInset} ${viewSize - middleInset}
30
- L ${inset} ${viewSize - out}
31
- `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" }), _jsx("path", { d: `
32
- M ${viewSize - out} ${viewSize - inset}
33
- L ${viewSize - middleInset} ${viewSize - middleInset}
34
- L ${viewSize - inset} ${viewSize - out}
35
- `, stroke: "#fff", strokeWidth: strokeWidth, fill: "none" })] }));
36
- };
37
- export const VolumeOffIcon = () => {
38
- return (_jsx("svg", { width: ICON_SIZE, height: ICON_SIZE, viewBox: "0 0 24 24", children: _jsx("path", { d: "M3.63 3.63a.996.996 0 000 1.41L7.29 8.7 7 9H4c-.55 0-1 .45-1 1v4c0 .55.45 1 1 1h3l3.29 3.29c.63.63 1.71.18 1.71-.71v-4.17l4.18 4.18c-.49.37-1.02.68-1.6.91-.36.15-.58.53-.58.92 0 .72.73 1.18 1.39.91.8-.33 1.55-.77 2.22-1.31l1.34 1.34a.996.996 0 101.41-1.41L5.05 3.63c-.39-.39-1.02-.39-1.42 0zM19 12c0 .82-.15 1.61-.41 2.34l1.53 1.53c.56-1.17.88-2.48.88-3.87 0-3.83-2.4-7.11-5.78-8.4-.59-.23-1.22.23-1.22.86v.19c0 .38.25.71.61.85C17.18 6.54 19 9.06 19 12zm-8.71-6.29l-.17.17L12 7.76V6.41c0-.89-1.08-1.33-1.71-.7zM16.5 12A4.5 4.5 0 0014 7.97v1.79l2.48 2.48c.01-.08.02-.16.02-.24z", fill: "#fff" }) }));
39
- };
40
- export const VolumeOnIcon = () => {
41
- return (_jsx("svg", { width: ICON_SIZE, height: ICON_SIZE, viewBox: "0 0 24 24", children: _jsx("path", { d: "M3 10v4c0 .55.45 1 1 1h3l3.29 3.29c.63.63 1.71.18 1.71-.71V6.41c0-.89-1.08-1.34-1.71-.71L7 9H4c-.55 0-1 .45-1 1zm13.5 2A4.5 4.5 0 0014 7.97v8.05c1.48-.73 2.5-2.25 2.5-4.02zM14 4.45v.2c0 .38.25.71.6.85C17.18 6.53 19 9.06 19 12s-1.82 5.47-4.4 6.5c-.36.14-.6.47-.6.85v.2c0 .63.63 1.07 1.21.85C18.6 19.11 21 15.84 21 12s-2.4-7.11-5.79-8.4c-.58-.23-1.21.22-1.21.85z", fill: "#fff" }) }));
42
- };
package/dist/esm/index.js DELETED
@@ -1,20 +0,0 @@
1
- import { calculateCanvasTransformation, calculateScale } from './calculate-scale.js';
2
- import { PlayerEventEmitterContext } from './emitter-context.js';
3
- import { PlayerEmitter } from './event-emitter.js';
4
- import { useHoverState } from './use-hover-state.js';
5
- import { usePlayback } from './use-playback.js';
6
- import { usePlayer } from './use-player.js';
7
- import { updateAllElementsSizes, useElementSize } from './utils/use-element-size.js';
8
- export { Player } from './Player.js';
9
- export { Thumbnail } from './Thumbnail.js';
10
- export const PlayerInternals = {
11
- PlayerEventEmitterContext,
12
- PlayerEmitter,
13
- usePlayer,
14
- usePlayback,
15
- useElementSize,
16
- calculateCanvasTransformation,
17
- useHoverState,
18
- updateAllElementsSizes,
19
- calculateScale,
20
- };
@@ -1 +0,0 @@
1
- export const PLAYER_CSS_CLASSNAME = '__remotion-player';
@@ -1 +0,0 @@
1
- export {};
@@ -1,7 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { usePlayer } from '../use-player.js';
3
- test('It should throw an error if not being used inside a RemotionRoot', () => {
4
- expect(() => {
5
- usePlayer();
6
- }).toThrow();
7
- });
@@ -1,14 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { render } from '@testing-library/react';
3
- const HelloWorld = () => {
4
- return _jsx("div", { children: "Hello World" });
5
- };
6
- const AllTheProviders = ({ children }) => {
7
- // overwriting console.error console does not gets poluted with all the errors
8
- // eslint-disable-next-line @typescript-eslint/no-empty-function
9
- window.console.error = () => { };
10
- return _jsx("div", { children: children });
11
- };
12
- const customRender = (ui, options) => render(ui, { wrapper: AllTheProviders, ...options });
13
- export * from '@testing-library/react';
14
- export { customRender as render, HelloWorld };
@@ -1,54 +0,0 @@
1
- import { expect, test } from 'vitest';
2
- import { validateInOutFrames } from '../utils/validate-in-out-frame.js';
3
- test('Validate in out frames', () => {
4
- expect(() => validateInOutFrames({
5
- durationInFrames: 200,
6
- inFrame: 201,
7
- outFrame: undefined,
8
- })).toThrow(/inFrame must be less than \(durationInFrames - 1\)/);
9
- expect(() => validateInOutFrames({
10
- durationInFrames: 200,
11
- inFrame: 199,
12
- outFrame: 201,
13
- })).toThrow(/outFrame must be less than \(durationInFrames - 1\)/);
14
- expect(() => validateInOutFrames({
15
- durationInFrames: 200,
16
- inFrame: -10,
17
- outFrame: null,
18
- })).toThrow(/inFrame must be greater than 0, but is -10/);
19
- expect(() => validateInOutFrames({
20
- durationInFrames: 200,
21
- inFrame: null,
22
- outFrame: -10,
23
- })).toThrow(/outFrame must be greater than 0, but is -10/);
24
- expect(() => validateInOutFrames({
25
- durationInFrames: 200,
26
- inFrame: 1.5,
27
- outFrame: null,
28
- })).toThrow(/"inFrame" must be an integer, but is 1.5/);
29
- expect(() => validateInOutFrames({
30
- durationInFrames: 200,
31
- inFrame: 20,
32
- outFrame: 20,
33
- })).toThrow(/outFrame must be greater than inFrame, but is 20/);
34
- expect(() => validateInOutFrames({
35
- durationInFrames: 200,
36
- inFrame: 21,
37
- outFrame: 20,
38
- })).toThrow(/outFrame must be greater than inFrame, but is 20 <= 21/);
39
- expect(() => validateInOutFrames({
40
- durationInFrames: 200,
41
- inFrame: null,
42
- outFrame: 20,
43
- })).not.toThrow();
44
- expect(() => validateInOutFrames({
45
- durationInFrames: 200,
46
- inFrame: null,
47
- outFrame: null,
48
- })).not.toThrow();
49
- expect(() => validateInOutFrames({
50
- durationInFrames: 200,
51
- inFrame: 10,
52
- outFrame: 20,
53
- })).not.toThrow();
54
- });
@@ -1,129 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Composition } from 'remotion';
3
- import { expect, test } from 'vitest';
4
- import { Player } from '../index.js';
5
- import { HelloWorld, render } from './test-utils.js';
6
- test('no compositionWidth should give errors', () => {
7
- try {
8
- render(_jsx(Player
9
- // @ts-expect-error
10
- , {
11
- // @ts-expect-error
12
- compositionWidth: null, errorFallback: () => 'something went wrong', compositionHeight: 400, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true }));
13
- }
14
- catch (e) {
15
- expect(e.message).toMatch(/'compositionWidth' must be a number but got 'object' instead/);
16
- }
17
- });
18
- test('no compositionHeight should give errors', () => {
19
- try {
20
- render(_jsx(Player, { compositionWidth: 400, errorFallback: () => 'something went wrong',
21
- // @ts-expect-error
22
- compositionHeight: undefined, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true }));
23
- }
24
- catch (e) {
25
- expect(e.message).toMatch(/'compositionHeight' must be a number but got 'undefined' instead/);
26
- }
27
- });
28
- test('No fps should give errors', () => {
29
- try {
30
- render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong',
31
- // @ts-expect-error
32
- fps: null, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true }));
33
- }
34
- catch (e) {
35
- expect(e.message).toMatch(/"fps" must be a number, but you passed a value of type object/);
36
- }
37
- try {
38
- render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong',
39
- // @ts-expect-error
40
- fps: undefined, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true }));
41
- }
42
- catch (e) {
43
- expect(e.message).toMatch(/"fps" must be a number, but you passed a value of type undefined/);
44
- }
45
- });
46
- test('No durationInFrames should give errors', () => {
47
- try {
48
- render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong', fps: 30,
49
- // @ts-expect-error
50
- durationInFrames: undefined, component: HelloWorld, controls: true, showVolumeControls: true }));
51
- }
52
- catch (e) {
53
- expect(e.message).toMatch(/durationInFrames` must be a number, but is undefined/);
54
- }
55
- });
56
- test('Invalid playbackRate should give error', () => {
57
- try {
58
- render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true, playbackRate: -5 }));
59
- }
60
- catch (e) {
61
- expect(e.message).toMatch(/The lowest possible playback rate is -4. You passed: -5/);
62
- }
63
- });
64
- test('playbackRate of 0 should not be possible', () => {
65
- try {
66
- render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true, playbackRate: 0 }));
67
- }
68
- catch (e) {
69
- expect(e.message).toMatch(/A playback rate of 0 is not supported./);
70
- }
71
- });
72
- test('playbackRate of wrong type should not be possible', () => {
73
- try {
74
- render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true,
75
- // @ts-expect-error
76
- playbackRate: 'hi' }));
77
- }
78
- catch (e) {
79
- expect(e.message).toMatch(/A playback rate of 0 is not supported./);
80
- }
81
- });
82
- test('playbackRate of undefined should be okay', () => {
83
- render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: HelloWorld, controls: true, showVolumeControls: true }));
84
- expect(true).toBe(true);
85
- });
86
- test('passing in <Composition /> instance should not be possible', () => {
87
- expect(() => {
88
- render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500, component: Composition, controls: true, showVolumeControls: true, inputProps: {
89
- id: 'HelloWorld',
90
- width: 500,
91
- height: 400,
92
- fps: 30,
93
- durationInFrames: 500,
94
- component: HelloWorld,
95
- } }));
96
- }).toThrow(/'component' must not be the 'Composition' component\. Pass your own React/);
97
- });
98
- test('passing in <Composition /> instance should not be possible', () => {
99
- expect(() => {
100
- render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, fps: 30, durationInFrames: 500,
101
- // @ts-expect-error
102
- component: _jsx(Composition, { durationInFrames: 30, fps: 30, height: 10, width: 10, id: "hello", component: HelloWorld }), controls: true, showVolumeControls: true, inputProps: {
103
- id: 'HelloWorld',
104
- width: 500,
105
- height: 400,
106
- fps: 30,
107
- durationInFrames: 500,
108
- component: HelloWorld,
109
- } }));
110
- }).toThrow(/'component' should not be an instance of <Composition\/>\. Pass the React component dir/);
111
- });
112
- test.each([
113
- ['controls'],
114
- ['loop'],
115
- ['autoPlay'],
116
- ['showVolumeControls'],
117
- ['allowFullscreen'],
118
- ['clickToPlay'],
119
- ['doubleClickToFullscreen'],
120
- ])('No durationInFrames should give errors %s', (a) => {
121
- const props = {};
122
- props[a] = 'hey';
123
- try {
124
- render(_jsx(Player, { compositionWidth: 500, compositionHeight: 400, errorFallback: () => 'something went wrong', fps: 30, durationInFrames: 100, component: HelloWorld, ...props }));
125
- }
126
- catch (e) {
127
- expect(e.message).toMatch(`'${a}' must be a boolean or undefined but got 'string' instead`);
128
- }
129
- });
@@ -1,23 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- export const useHoverState = (ref) => {
3
- const [hovered, stetHovered] = useState(false);
4
- useEffect(() => {
5
- const { current } = ref;
6
- if (!current) {
7
- return;
8
- }
9
- const onHover = () => {
10
- stetHovered(true);
11
- };
12
- const onLeave = () => {
13
- stetHovered(false);
14
- };
15
- current.addEventListener('mouseenter', onHover);
16
- current.addEventListener('mouseleave', onLeave);
17
- return () => {
18
- current.removeEventListener('mouseenter', onHover);
19
- current.removeEventListener('mouseenter', onLeave);
20
- };
21
- }, [ref]);
22
- return hovered;
23
- };
@@ -1,88 +0,0 @@
1
- import { useEffect, useRef } from 'react';
2
- import { Internals } from 'remotion';
3
- import { calculateNextFrame } from './calculate-next-frame.js';
4
- import { usePlayer } from './use-player.js';
5
- export const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, }) => {
6
- const frame = Internals.Timeline.useTimelinePosition();
7
- const config = Internals.useUnsafeVideoConfig();
8
- const { playing, pause, emitter } = usePlayer();
9
- const setFrame = Internals.Timeline.useTimelineSetFrame();
10
- const frameRef = useRef(frame);
11
- frameRef.current = frame;
12
- const lastTimeUpdateEvent = useRef(null);
13
- useEffect(() => {
14
- if (!config) {
15
- return;
16
- }
17
- if (!playing) {
18
- return;
19
- }
20
- let hasBeenStopped = false;
21
- let reqAnimFrameCall = null;
22
- const startedTime = performance.now();
23
- let framesAdvanced = 0;
24
- const stop = () => {
25
- hasBeenStopped = true;
26
- if (reqAnimFrameCall !== null) {
27
- cancelAnimationFrame(reqAnimFrameCall);
28
- }
29
- };
30
- const callback = () => {
31
- const time = performance.now() - startedTime;
32
- const actualLastFrame = outFrame !== null && outFrame !== void 0 ? outFrame : config.durationInFrames - 1;
33
- const actualFirstFrame = inFrame !== null && inFrame !== void 0 ? inFrame : 0;
34
- const { nextFrame, framesToAdvance, hasEnded } = calculateNextFrame({
35
- time,
36
- currentFrame: frameRef.current,
37
- playbackSpeed: playbackRate,
38
- fps: config.fps,
39
- actualFirstFrame,
40
- actualLastFrame,
41
- framesAdvanced,
42
- shouldLoop: loop,
43
- });
44
- framesAdvanced += framesToAdvance;
45
- if (nextFrame !== frameRef.current &&
46
- (!hasEnded || moveToBeginningWhenEnded)) {
47
- setFrame(nextFrame);
48
- }
49
- if (hasEnded) {
50
- stop();
51
- pause();
52
- emitter.dispatchEnded();
53
- return;
54
- }
55
- if (!hasBeenStopped) {
56
- reqAnimFrameCall = requestAnimationFrame(callback);
57
- }
58
- };
59
- reqAnimFrameCall = requestAnimationFrame(callback);
60
- return () => {
61
- stop();
62
- };
63
- }, [
64
- config,
65
- loop,
66
- pause,
67
- playing,
68
- setFrame,
69
- emitter,
70
- playbackRate,
71
- inFrame,
72
- outFrame,
73
- moveToBeginningWhenEnded,
74
- ]);
75
- useEffect(() => {
76
- const interval = setInterval(() => {
77
- if (lastTimeUpdateEvent.current === frameRef.current) {
78
- return;
79
- }
80
- emitter.dispatchTimeUpdate({ frame: frameRef.current });
81
- lastTimeUpdateEvent.current = frameRef.current;
82
- }, 250);
83
- return () => clearInterval(interval);
84
- }, [emitter]);
85
- useEffect(() => {
86
- emitter.dispatchFrameUpdate({ frame });
87
- }, [emitter, frame]);
88
- };
@@ -1,128 +0,0 @@
1
- import { useCallback, useContext, useMemo, useRef, useState } from 'react';
2
- import { Internals } from 'remotion';
3
- import { PlayerEventEmitterContext } from './emitter-context.js';
4
- export const usePlayer = () => {
5
- var _a;
6
- const [playing, setPlaying, imperativePlaying] = Internals.Timeline.usePlayingState();
7
- const [hasPlayed, setHasPlayed] = useState(false);
8
- const frame = Internals.Timeline.useTimelinePosition();
9
- const playStart = useRef(frame);
10
- const setFrame = Internals.Timeline.useTimelineSetFrame();
11
- const setTimelinePosition = Internals.Timeline.useTimelineSetFrame();
12
- const audioContext = useContext(Internals.SharedAudioContext);
13
- const { audioAndVideoTags } = useContext(Internals.Timeline.TimelineContext);
14
- const frameRef = useRef();
15
- frameRef.current = frame;
16
- const video = Internals.useVideo();
17
- const config = Internals.useUnsafeVideoConfig();
18
- const emitter = useContext(PlayerEventEmitterContext);
19
- const lastFrame = ((_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1) - 1;
20
- const isLastFrame = frame === lastFrame;
21
- const isFirstFrame = frame === 0;
22
- if (!emitter) {
23
- throw new TypeError('Expected Player event emitter context');
24
- }
25
- const seek = useCallback((newFrame) => {
26
- setTimelinePosition(newFrame);
27
- emitter.dispatchSeek(newFrame);
28
- }, [emitter, setTimelinePosition]);
29
- const play = useCallback((e) => {
30
- if (imperativePlaying.current) {
31
- return;
32
- }
33
- setHasPlayed(true);
34
- if (isLastFrame) {
35
- seek(0);
36
- }
37
- /**
38
- * Play silent audio tags to warm them up for autoplay
39
- */
40
- if (audioContext && audioContext.numberOfAudioTags > 0 && e) {
41
- audioContext.playAllAudios();
42
- }
43
- /**
44
- * Play audios and videos directly here so they can benefit from
45
- * being triggered by a click
46
- */
47
- audioAndVideoTags.current.forEach((a) => a.play());
48
- imperativePlaying.current = true;
49
- setPlaying(true);
50
- playStart.current = frameRef.current;
51
- emitter.dispatchPlay();
52
- }, [
53
- imperativePlaying,
54
- isLastFrame,
55
- audioContext,
56
- setPlaying,
57
- emitter,
58
- seek,
59
- audioAndVideoTags,
60
- ]);
61
- const pause = useCallback(() => {
62
- if (imperativePlaying.current) {
63
- imperativePlaying.current = false;
64
- setPlaying(false);
65
- emitter.dispatchPause();
66
- }
67
- }, [emitter, imperativePlaying, setPlaying]);
68
- const pauseAndReturnToPlayStart = useCallback(() => {
69
- if (imperativePlaying.current) {
70
- imperativePlaying.current = false;
71
- setTimelinePosition(playStart.current);
72
- setPlaying(false);
73
- emitter.dispatchPause();
74
- }
75
- }, [emitter, imperativePlaying, setPlaying, setTimelinePosition]);
76
- const hasVideo = Boolean(video);
77
- const frameBack = useCallback((frames) => {
78
- if (!hasVideo) {
79
- return null;
80
- }
81
- if (imperativePlaying.current) {
82
- return;
83
- }
84
- setFrame((f) => {
85
- return Math.max(0, f - frames);
86
- });
87
- }, [hasVideo, imperativePlaying, setFrame]);
88
- const frameForward = useCallback((frames) => {
89
- if (!hasVideo) {
90
- return null;
91
- }
92
- if (imperativePlaying.current) {
93
- return;
94
- }
95
- setFrame((f) => Math.min(lastFrame, f + frames));
96
- }, [hasVideo, imperativePlaying, lastFrame, setFrame]);
97
- const returnValue = useMemo(() => {
98
- return {
99
- frameBack,
100
- frameForward,
101
- isLastFrame,
102
- emitter,
103
- playing,
104
- play,
105
- pause,
106
- seek,
107
- isFirstFrame,
108
- getCurrentFrame: () => frameRef.current,
109
- isPlaying: () => imperativePlaying.current,
110
- pauseAndReturnToPlayStart,
111
- hasPlayed,
112
- };
113
- }, [
114
- frameBack,
115
- frameForward,
116
- isLastFrame,
117
- emitter,
118
- playing,
119
- play,
120
- pause,
121
- seek,
122
- isFirstFrame,
123
- pauseAndReturnToPlayStart,
124
- imperativePlaying,
125
- hasPlayed,
126
- ]);
127
- return returnValue;
128
- };
@@ -1,14 +0,0 @@
1
- import { useContext, useMemo } from 'react';
2
- import { ThumbnailEmitterContext } from './emitter-context.js';
3
- export const useThumbnail = () => {
4
- const emitter = useContext(ThumbnailEmitterContext);
5
- if (!emitter) {
6
- throw new TypeError('Expected Player event emitter context');
7
- }
8
- const returnValue = useMemo(() => {
9
- return {
10
- emitter,
11
- };
12
- }, [emitter]);
13
- return returnValue;
14
- };
@@ -1,35 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { fullscreenIconSize, ICON_SIZE } from './icons.js';
3
- import { VOLUME_SLIDER_WIDTH } from './MediaVolumeSlider.js';
4
- export const X_SPACER = 10;
5
- export const X_PADDING = 12;
6
- export const useVideoControlsResize = ({ allowFullscreen: allowFullScreen, playerWidth, }) => {
7
- const resizeInfo = useMemo(() => {
8
- const playPauseIconSize = ICON_SIZE;
9
- const volumeIconSize = ICON_SIZE;
10
- const _fullscreenIconSize = allowFullScreen ? fullscreenIconSize : 0;
11
- const elementsSize = volumeIconSize +
12
- playPauseIconSize +
13
- _fullscreenIconSize +
14
- X_PADDING * 2 +
15
- X_SPACER * 2;
16
- const maxTimeLabelWidth = playerWidth - elementsSize;
17
- const maxTimeLabelWidthWithoutNegativeValue = Math.max(maxTimeLabelWidth, 0);
18
- const availableTimeLabelWidthIfVolumeOpen = maxTimeLabelWidthWithoutNegativeValue - VOLUME_SLIDER_WIDTH;
19
- // If max label width is lower than the volume width
20
- // then it means we need to take it's width as the max label width
21
- // otherwise we took the available width when volume open
22
- const computedLabelWidth = availableTimeLabelWidthIfVolumeOpen < VOLUME_SLIDER_WIDTH
23
- ? maxTimeLabelWidthWithoutNegativeValue
24
- : availableTimeLabelWidthIfVolumeOpen;
25
- const minWidthForHorizontalDisplay = computedLabelWidth + elementsSize + VOLUME_SLIDER_WIDTH;
26
- const displayVerticalVolumeSlider = playerWidth < minWidthForHorizontalDisplay;
27
- return {
28
- maxTimeLabelWidth: maxTimeLabelWidthWithoutNegativeValue === 0
29
- ? null
30
- : maxTimeLabelWidthWithoutNegativeValue,
31
- displayVerticalVolumeSlider,
32
- };
33
- }, [allowFullScreen, playerWidth]);
34
- return resizeInfo;
35
- };