@remotion/player 4.0.290 → 4.0.292

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.
@@ -13,7 +13,6 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
13
13
  const frame = remotion_1.Internals.Timeline.useTimelinePosition();
14
14
  const { playing, pause, emitter } = (0, use_player_js_1.usePlayer)();
15
15
  const setFrame = remotion_1.Internals.Timeline.useTimelineSetFrame();
16
- const buffering = (0, react_1.useRef)(null);
17
16
  // requestAnimationFrame() does not work if the tab is not active.
18
17
  // This means that audio will keep playing even if it has ended.
19
18
  // In that case, we use setTimeout() instead.
@@ -29,18 +28,6 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
29
28
  videoConfig: config,
30
29
  });
31
30
  // complete code for media session API
32
- (0, react_1.useEffect)(() => {
33
- const onBufferClear = context.listenForBuffering(() => {
34
- buffering.current = performance.now();
35
- });
36
- const onResumeClear = context.listenForResume(() => {
37
- buffering.current = null;
38
- });
39
- return () => {
40
- onBufferClear.remove();
41
- onResumeClear.remove();
42
- };
43
- }, [context]);
44
31
  (0, react_1.useEffect)(() => {
45
32
  if (!config) {
46
33
  return;
@@ -67,6 +54,9 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
67
54
  cancelQueuedFrame();
68
55
  };
69
56
  const callback = () => {
57
+ if (hasBeenStopped) {
58
+ return;
59
+ }
70
60
  const time = performance.now() - startedTime;
71
61
  const actualLastFrame = outFrame !== null && outFrame !== void 0 ? outFrame : config.durationInFrames - 1;
72
62
  const actualFirstFrame = inFrame !== null && inFrame !== void 0 ? inFrame : 0;
@@ -92,20 +82,15 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
92
82
  emitter.dispatchEnded();
93
83
  return;
94
84
  }
95
- if (!hasBeenStopped) {
96
- queueNextFrame();
97
- }
85
+ queueNextFrame();
98
86
  };
99
87
  const queueNextFrame = () => {
100
- if (buffering.current) {
88
+ if (context.buffering.current) {
101
89
  const stopListening = context.listenForResume(() => {
102
90
  stopListening.remove();
103
- if (hasBeenStopped) {
104
- return;
105
- }
106
91
  startedTime = performance.now();
107
92
  framesAdvanced = 0;
108
- callback();
93
+ queueNextFrame();
109
94
  });
110
95
  return;
111
96
  }
@@ -115,10 +100,9 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
115
100
  // Note: Most likely, this will not be 1000 / fps, but the browser will throttle it to ~1/sec.
116
101
  id: setTimeout(callback, 1000 / config.fps),
117
102
  };
103
+ return;
118
104
  }
119
- else {
120
- reqAnimFrameCall = { type: 'raf', id: requestAnimationFrame(callback) };
121
- }
105
+ reqAnimFrameCall = { type: 'raf', id: requestAnimationFrame(callback) };
122
106
  };
123
107
  queueNextFrame();
124
108
  const onVisibilityChange = () => {
@@ -148,7 +132,6 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
148
132
  moveToBeginningWhenEnded,
149
133
  isBackgroundedRef,
150
134
  getCurrentFrame,
151
- buffering,
152
135
  context,
153
136
  ]);
154
137
  (0, react_1.useEffect)(() => {
@@ -881,7 +881,6 @@ var usePlayback = ({
881
881
  const frame = Internals6.Timeline.useTimelinePosition();
882
882
  const { playing, pause, emitter } = usePlayer();
883
883
  const setFrame = Internals6.Timeline.useTimelineSetFrame();
884
- const buffering = useRef4(null);
885
884
  const isBackgroundedRef = useIsBackgrounded();
886
885
  const lastTimeUpdateEvent = useRef4(null);
887
886
  const context = useContext4(Internals6.BufferingContextReact);
@@ -893,18 +892,6 @@ var usePlayback = ({
893
892
  playbackRate,
894
893
  videoConfig: config
895
894
  });
896
- useEffect6(() => {
897
- const onBufferClear = context.listenForBuffering(() => {
898
- buffering.current = performance.now();
899
- });
900
- const onResumeClear = context.listenForResume(() => {
901
- buffering.current = null;
902
- });
903
- return () => {
904
- onBufferClear.remove();
905
- onResumeClear.remove();
906
- };
907
- }, [context]);
908
895
  useEffect6(() => {
909
896
  if (!config) {
910
897
  return;
@@ -930,6 +917,9 @@ var usePlayback = ({
930
917
  cancelQueuedFrame();
931
918
  };
932
919
  const callback = () => {
920
+ if (hasBeenStopped) {
921
+ return;
922
+ }
933
923
  const time = performance.now() - startedTime;
934
924
  const actualLastFrame = outFrame ?? config.durationInFrames - 1;
935
925
  const actualFirstFrame = inFrame ?? 0;
@@ -954,20 +944,15 @@ var usePlayback = ({
954
944
  emitter.dispatchEnded();
955
945
  return;
956
946
  }
957
- if (!hasBeenStopped) {
958
- queueNextFrame();
959
- }
947
+ queueNextFrame();
960
948
  };
961
949
  const queueNextFrame = () => {
962
- if (buffering.current) {
950
+ if (context.buffering.current) {
963
951
  const stopListening = context.listenForResume(() => {
964
952
  stopListening.remove();
965
- if (hasBeenStopped) {
966
- return;
967
- }
968
953
  startedTime = performance.now();
969
954
  framesAdvanced = 0;
970
- callback();
955
+ queueNextFrame();
971
956
  });
972
957
  return;
973
958
  }
@@ -976,9 +961,9 @@ var usePlayback = ({
976
961
  type: "timeout",
977
962
  id: setTimeout(callback, 1000 / config.fps)
978
963
  };
979
- } else {
980
- reqAnimFrameCall = { type: "raf", id: requestAnimationFrame(callback) };
964
+ return;
981
965
  }
966
+ reqAnimFrameCall = { type: "raf", id: requestAnimationFrame(callback) };
982
967
  };
983
968
  queueNextFrame();
984
969
  const onVisibilityChange = () => {
@@ -1006,7 +991,6 @@ var usePlayback = ({
1006
991
  moveToBeginningWhenEnded,
1007
992
  isBackgroundedRef,
1008
993
  getCurrentFrame,
1009
- buffering,
1010
994
  context
1011
995
  ]);
1012
996
  useEffect6(() => {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/player"
4
4
  },
5
5
  "name": "@remotion/player",
6
- "version": "4.0.290",
6
+ "version": "4.0.292",
7
7
  "description": "React component for embedding a Remotion preview into your app",
8
8
  "main": "dist/cjs/index.js",
9
9
  "types": "dist/cjs/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "license": "SEE LICENSE IN LICENSE.md",
30
30
  "dependencies": {
31
- "remotion": "4.0.290"
31
+ "remotion": "4.0.292"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": ">=16.8.0",
@@ -43,7 +43,7 @@
43
43
  "webpack": "5.96.1",
44
44
  "zod": "3.22.3",
45
45
  "eslint": "9.19.0",
46
- "@remotion/eslint-config-internal": "4.0.290"
46
+ "@remotion/eslint-config-internal": "4.0.292"
47
47
  },
48
48
  "keywords": [
49
49
  "remotion",
@@ -1,171 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePlayback = void 0;
4
- /* eslint-disable @typescript-eslint/no-use-before-define */
5
- const react_1 = require("react");
6
- const react_dom_1 = require("react-dom");
7
- const remotion_1 = require("remotion");
8
- const browser_mediasession_js_1 = require("./browser-mediasession.js");
9
- const calculate_next_frame_js_1 = require("./calculate-next-frame.js");
10
- const is_backgrounded_js_1 = require("./is-backgrounded.js");
11
- const use_player_js_1 = require("./use-player.js");
12
- const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, browserMediaControlsBehavior, getCurrentFrame, }) => {
13
- const config = remotion_1.Internals.useUnsafeVideoConfig();
14
- const frame = remotion_1.Internals.Timeline.useTimelinePosition();
15
- const { playing, pause, emitter } = (0, use_player_js_1.usePlayer)();
16
- const setFrame = remotion_1.Internals.Timeline.useTimelineSetFrame();
17
- const buffering = (0, react_1.useRef)(null);
18
- // requestAnimationFrame() does not work if the tab is not active.
19
- // This means that audio will keep playing even if it has ended.
20
- // In that case, we use setTimeout() instead.
21
- const isBackgroundedRef = (0, is_backgrounded_js_1.useIsBackgrounded)();
22
- const lastTimeUpdateEvent = (0, react_1.useRef)(null);
23
- const context = (0, react_1.useContext)(remotion_1.Internals.BufferingContextReact);
24
- if (!context) {
25
- throw new Error('Missing the buffering context. Most likely you have a Remotion version mismatch.');
26
- }
27
- (0, browser_mediasession_js_1.useBrowserMediaSession)({
28
- browserMediaControlsBehavior,
29
- playbackRate,
30
- videoConfig: config,
31
- });
32
- // complete code for media session API
33
- (0, react_1.useEffect)(() => {
34
- const onBufferClear = context.listenForBuffering(() => {
35
- buffering.current = performance.now();
36
- });
37
- const onResumeClear = context.listenForResume(() => {
38
- buffering.current = null;
39
- });
40
- return () => {
41
- onBufferClear.remove();
42
- onResumeClear.remove();
43
- };
44
- }, [context]);
45
- (0, react_1.useEffect)(() => {
46
- if (!config) {
47
- return;
48
- }
49
- if (!playing) {
50
- return;
51
- }
52
- let hasBeenStopped = false;
53
- let reqAnimFrameCall = null;
54
- let startedTime = performance.now();
55
- let framesAdvanced = 0;
56
- const cancelQueuedFrame = () => {
57
- if (reqAnimFrameCall !== null) {
58
- if (reqAnimFrameCall.type === 'raf') {
59
- cancelAnimationFrame(reqAnimFrameCall.id);
60
- }
61
- else {
62
- clearTimeout(reqAnimFrameCall.id);
63
- }
64
- }
65
- };
66
- const stop = () => {
67
- hasBeenStopped = true;
68
- cancelQueuedFrame();
69
- };
70
- const callback = () => {
71
- const time = performance.now() - startedTime;
72
- const actualLastFrame = outFrame !== null && outFrame !== void 0 ? outFrame : config.durationInFrames - 1;
73
- const actualFirstFrame = inFrame !== null && inFrame !== void 0 ? inFrame : 0;
74
- const currentFrame = getCurrentFrame();
75
- const { nextFrame, framesToAdvance, hasEnded } = (0, calculate_next_frame_js_1.calculateNextFrame)({
76
- time,
77
- currentFrame,
78
- playbackSpeed: playbackRate,
79
- fps: config.fps,
80
- actualFirstFrame,
81
- actualLastFrame,
82
- framesAdvanced,
83
- shouldLoop: loop,
84
- });
85
- framesAdvanced += framesToAdvance;
86
- if (nextFrame !== getCurrentFrame() &&
87
- (!hasEnded || moveToBeginningWhenEnded)) {
88
- (0, react_dom_1.flushSync)(() => {
89
- setFrame((c) => ({ ...c, [config.id]: nextFrame }));
90
- });
91
- }
92
- if (hasEnded) {
93
- stop();
94
- pause();
95
- emitter.dispatchEnded();
96
- return;
97
- }
98
- if (!hasBeenStopped) {
99
- queueNextFrame();
100
- }
101
- };
102
- const queueNextFrame = () => {
103
- if (buffering.current) {
104
- const stopListening = context.listenForResume(() => {
105
- stopListening.remove();
106
- if (hasBeenStopped) {
107
- return;
108
- }
109
- startedTime = performance.now();
110
- framesAdvanced = 0;
111
- callback();
112
- });
113
- return;
114
- }
115
- if (isBackgroundedRef.current) {
116
- reqAnimFrameCall = {
117
- type: 'timeout',
118
- // Note: Most likely, this will not be 1000 / fps, but the browser will throttle it to ~1/sec.
119
- id: setTimeout(callback, 1000 / config.fps),
120
- };
121
- }
122
- else {
123
- reqAnimFrameCall = { type: 'raf', id: requestAnimationFrame(callback) };
124
- }
125
- };
126
- queueNextFrame();
127
- const onVisibilityChange = () => {
128
- if (document.visibilityState === 'visible') {
129
- return;
130
- }
131
- // If tab goes into the background, cancel requestAnimationFrame() and update immediately.
132
- // , so the transition to setTimeout() can be fulfilled.
133
- cancelQueuedFrame();
134
- callback();
135
- };
136
- window.addEventListener('visibilitychange', onVisibilityChange);
137
- return () => {
138
- window.removeEventListener('visibilitychange', onVisibilityChange);
139
- stop();
140
- };
141
- }, [
142
- config,
143
- loop,
144
- pause,
145
- playing,
146
- setFrame,
147
- emitter,
148
- playbackRate,
149
- inFrame,
150
- outFrame,
151
- moveToBeginningWhenEnded,
152
- isBackgroundedRef,
153
- getCurrentFrame,
154
- buffering,
155
- context,
156
- ]);
157
- (0, react_1.useEffect)(() => {
158
- const interval = setInterval(() => {
159
- if (lastTimeUpdateEvent.current === getCurrentFrame()) {
160
- return;
161
- }
162
- emitter.dispatchTimeUpdate({ frame: getCurrentFrame() });
163
- lastTimeUpdateEvent.current = getCurrentFrame();
164
- }, 250);
165
- return () => clearInterval(interval);
166
- }, [emitter, getCurrentFrame]);
167
- (0, react_1.useEffect)(() => {
168
- emitter.dispatchFrameUpdate({ frame });
169
- }, [emitter, frame]);
170
- };
171
- exports.usePlayback = usePlayback;