@remotion/player 4.0.535 → 4.0.536

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.
@@ -30,7 +30,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
30
30
  const setFrameFromPlayback = remotion_1.Internals.Timeline.useTimelineSetFrameWithoutSeek();
31
31
  const sharedAudioContext = (0, react_2.useContext)(remotion_1.Internals.SharedAudioContext);
32
32
  const { setPlayerMuted } = (0, react_2.useContext)(remotion_1.Internals.SetMediaVolumeContext);
33
- const { isBuffering, subscribeBuffering } = (0, react_2.useContext)(remotion_1.Internals.SetTimelineContext);
33
+ const { isBuffering, subscribeBuffering, seek } = (0, react_2.useContext)(remotion_1.Internals.SetTimelineContext);
34
34
  const logLevel = remotion_1.Internals.useLogLevel();
35
35
  // requestAnimationFrame() does not work if the tab is not active.
36
36
  // This means that audio will keep playing even if it has ended.
@@ -112,6 +112,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
112
112
  ]);
113
113
  (0, react_2.useEffect)(() => {
114
114
  var _a;
115
+ var _b;
115
116
  if (!config) {
116
117
  return;
117
118
  }
@@ -147,6 +148,8 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
147
148
  let reqAnimFrameCall = null;
148
149
  let startedTime = performance.now();
149
150
  let framesAdvanced = 0;
151
+ let playbackFrame = getCurrentFrame();
152
+ let lastSeekRevision = (_b = seek === null || seek === void 0 ? void 0 : seek.revision.current) !== null && _b !== void 0 ? _b : null;
150
153
  const cancelQueuedFrame = () => {
151
154
  if (reqAnimFrameCall !== null) {
152
155
  if (reqAnimFrameCall.type === 'raf') {
@@ -163,6 +166,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
163
166
  };
164
167
  const callback = () => {
165
168
  var _a, _b;
169
+ var _c;
166
170
  if (hasBeenStopped) {
167
171
  return;
168
172
  }
@@ -176,7 +180,13 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
176
180
  const time = performance.now() - startedTime;
177
181
  const actualLastFrame = outFrame !== null && outFrame !== void 0 ? outFrame : config.durationInFrames - 1;
178
182
  const actualFirstFrame = inFrame !== null && inFrame !== void 0 ? inFrame : 0;
179
- const currentFrame = getCurrentFrame();
183
+ const seekRevision = (_c = seek === null || seek === void 0 ? void 0 : seek.revision.current) !== null && _c !== void 0 ? _c : null;
184
+ if (seekRevision !== lastSeekRevision) {
185
+ playbackFrame = getCurrentFrame();
186
+ lastSeekRevision = seekRevision;
187
+ }
188
+ // React may not have committed the previous playback update yet.
189
+ const currentFrame = playbackFrame;
180
190
  const { nextFrame, framesToAdvance, hasEnded } = (0, calculate_next_frame_js_1.calculateNextFrame)({
181
191
  time,
182
192
  currentFrame,
@@ -194,7 +204,8 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
194
204
  ? actualLastFrame
195
205
  : actualFirstFrame
196
206
  : nextFrame;
197
- if (frameToDisplay !== getCurrentFrame() && !isBuffering()) {
207
+ if (frameToDisplay !== currentFrame && !isBuffering()) {
208
+ playbackFrame = frameToDisplay;
198
209
  setFrameFromPlayback((c) => ({ ...c, [config.id]: frameToDisplay }));
199
210
  }
200
211
  if (hasEnded) {
@@ -293,6 +304,7 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
293
304
  sharedAudioContext,
294
305
  setPlayerMuted,
295
306
  subscribeBuffering,
307
+ seek,
296
308
  logLevel,
297
309
  muted,
298
310
  ]);
@@ -960,7 +960,7 @@ var usePlayback = ({
960
960
  const setFrameFromPlayback = Internals6.Timeline.useTimelineSetFrameWithoutSeek();
961
961
  const sharedAudioContext = useContext3(Internals6.SharedAudioContext);
962
962
  const { setPlayerMuted } = useContext3(Internals6.SetMediaVolumeContext);
963
- const { isBuffering, subscribeBuffering } = useContext3(Internals6.SetTimelineContext);
963
+ const { isBuffering, subscribeBuffering, seek } = useContext3(Internals6.SetTimelineContext);
964
964
  const logLevel = Internals6.useLogLevel();
965
965
  const isBackgroundedRef = useIsBackgrounded();
966
966
  const lastTimeUpdateTimestamp = useRef4(0);
@@ -1059,6 +1059,8 @@ var usePlayback = ({
1059
1059
  let reqAnimFrameCall = null;
1060
1060
  let startedTime = performance.now();
1061
1061
  let framesAdvanced = 0;
1062
+ let playbackFrame = getCurrentFrame();
1063
+ let lastSeekRevision = seek?.revision.current ?? null;
1062
1064
  const cancelQueuedFrame = () => {
1063
1065
  if (reqAnimFrameCall !== null) {
1064
1066
  if (reqAnimFrameCall.type === "raf") {
@@ -1086,7 +1088,12 @@ var usePlayback = ({
1086
1088
  const time = performance.now() - startedTime;
1087
1089
  const actualLastFrame = outFrame ?? config.durationInFrames - 1;
1088
1090
  const actualFirstFrame = inFrame ?? 0;
1089
- const currentFrame = getCurrentFrame();
1091
+ const seekRevision = seek?.revision.current ?? null;
1092
+ if (seekRevision !== lastSeekRevision) {
1093
+ playbackFrame = getCurrentFrame();
1094
+ lastSeekRevision = seekRevision;
1095
+ }
1096
+ const currentFrame = playbackFrame;
1090
1097
  const { nextFrame, framesToAdvance, hasEnded } = calculateNextFrame({
1091
1098
  time,
1092
1099
  currentFrame,
@@ -1099,7 +1106,8 @@ var usePlayback = ({
1099
1106
  });
1100
1107
  framesAdvanced += framesToAdvance;
1101
1108
  const frameToDisplay = hasEnded && !moveToBeginningWhenEnded ? playbackRate > 0 ? actualLastFrame : actualFirstFrame : nextFrame;
1102
- if (frameToDisplay !== getCurrentFrame() && !isBuffering()) {
1109
+ if (frameToDisplay !== currentFrame && !isBuffering()) {
1110
+ playbackFrame = frameToDisplay;
1103
1111
  setFrameFromPlayback((c) => ({ ...c, [config.id]: frameToDisplay }));
1104
1112
  }
1105
1113
  if (hasEnded) {
@@ -1189,6 +1197,7 @@ var usePlayback = ({
1189
1197
  sharedAudioContext,
1190
1198
  setPlayerMuted,
1191
1199
  subscribeBuffering,
1200
+ seek,
1192
1201
  logLevel,
1193
1202
  muted
1194
1203
  ]);
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.535",
6
+ "version": "4.0.536",
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",
@@ -35,7 +35,7 @@
35
35
  ],
36
36
  "license": "SEE LICENSE IN LICENSE.md",
37
37
  "dependencies": {
38
- "remotion": "4.0.535"
38
+ "remotion": "4.0.536"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.8.0",
@@ -49,7 +49,7 @@
49
49
  "react-dom": "19.2.3",
50
50
  "webpack": "5.105.0",
51
51
  "zod": "4.5.4",
52
- "@remotion/eslint-config-internal": "4.0.535",
52
+ "@remotion/eslint-config-internal": "4.0.536",
53
53
  "eslint": "9.19.0",
54
54
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
55
55
  },
@@ -1,11 +0,0 @@
1
- import type { Context } from 'react';
2
- import React from 'react';
3
- import type { TimelineImperativeContextValue } from 'remotion';
4
- export declare const getTimelineImperativeContext: () => Context<TimelineImperativeContextValue | null>;
5
- export declare const CoreTimelineImperativeContextProvider: React.FC<{
6
- readonly children: React.ReactNode;
7
- readonly value: TimelineImperativeContextValue;
8
- }>;
9
- export declare const TimelineImperativeCompatibilityProvider: React.FC<{
10
- readonly children: React.ReactNode;
11
- }>;
@@ -1,76 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.TimelineImperativeCompatibilityProvider = exports.CoreTimelineImperativeContextProvider = exports.getTimelineImperativeContext = void 0;
37
- const jsx_runtime_1 = require("react/jsx-runtime");
38
- const react_1 = __importStar(require("react"));
39
- const remotion_1 = require("remotion");
40
- const PlayerTimelineImperativeContext = react_1.default.createContext(null);
41
- const getCoreTimelineImperativeContext = () => {
42
- return remotion_1.Internals.TimelineImperativeContext;
43
- };
44
- const getTimelineImperativeContext = () => {
45
- var _a;
46
- return (_a = getCoreTimelineImperativeContext()) !== null && _a !== void 0 ? _a : PlayerTimelineImperativeContext;
47
- };
48
- exports.getTimelineImperativeContext = getTimelineImperativeContext;
49
- const CoreTimelineImperativeContextProvider = ({ children, value }) => {
50
- const TimelineImperativeContext = getCoreTimelineImperativeContext();
51
- if (!TimelineImperativeContext) {
52
- return children;
53
- }
54
- return (jsx_runtime_1.jsx(TimelineImperativeContext.Provider, { value: value, children: children }));
55
- };
56
- exports.CoreTimelineImperativeContextProvider = CoreTimelineImperativeContextProvider;
57
- const LegacyTimelineImperativeContextProvider = ({ children }) => {
58
- const timelineContext = remotion_1.Internals.Timeline.useTimelineContext();
59
- const frameRef = (0, react_1.useRef)(timelineContext.frame);
60
- frameRef.current = timelineContext.frame;
61
- const value = (0, react_1.useMemo)(() => {
62
- return {
63
- frameRef,
64
- imperativePlaying: timelineContext.imperativePlaying,
65
- audioAndVideoTags: timelineContext.audioAndVideoTags,
66
- };
67
- }, [timelineContext.audioAndVideoTags, timelineContext.imperativePlaying]);
68
- return (jsx_runtime_1.jsx(PlayerTimelineImperativeContext.Provider, { value: value, children: children }));
69
- };
70
- const TimelineImperativeCompatibilityProvider = ({ children }) => {
71
- if (getCoreTimelineImperativeContext()) {
72
- return children;
73
- }
74
- return (jsx_runtime_1.jsx(LegacyTimelineImperativeContextProvider, { children: children }));
75
- };
76
- exports.TimelineImperativeCompatibilityProvider = TimelineImperativeCompatibilityProvider;
@@ -1,21 +0,0 @@
1
- import type { SyntheticEvent } from 'react';
2
- import type { PlayerEmitter } from './event-emitter.js';
3
- type UsePlayerMethods = {
4
- frameBack: (frames: number) => void;
5
- frameForward: (frames: number) => void;
6
- isLastFrame: boolean;
7
- isFirstFrame: boolean;
8
- emitter: PlayerEmitter;
9
- playing: boolean;
10
- play: (e?: SyntheticEvent | PointerEvent) => void;
11
- pause: () => void;
12
- pauseAndReturnToPlayStart: () => void;
13
- seek: (newFrame: number) => void;
14
- getCurrentFrame: () => number;
15
- isPlaying: () => boolean;
16
- hasPlayed: boolean;
17
- isBuffering: () => boolean;
18
- toggle: (e?: SyntheticEvent | PointerEvent) => void;
19
- };
20
- export declare const usePlayer: () => UsePlayerMethods;
21
- export {};
@@ -1,195 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.usePlayer = void 0;
4
- const react_1 = require("react");
5
- const remotion_1 = require("remotion");
6
- const emitter_context_js_1 = require("./emitter-context.js");
7
- const usePlayer = () => {
8
- var _a;
9
- const [playing, setPlaying, imperativePlaying] = remotion_1.Internals.Timeline.usePlayingState();
10
- const [hasPlayed, setHasPlayed] = (0, react_1.useState)(false);
11
- const frame = remotion_1.Internals.Timeline.useTimelinePosition();
12
- const playStart = (0, react_1.useRef)(frame);
13
- const setFrame = remotion_1.Internals.Timeline.useTimelineSetFrame();
14
- const setTimelinePosition = remotion_1.Internals.Timeline.useTimelineSetFrame();
15
- const audioContext = (0, react_1.useContext)(remotion_1.Internals.SharedAudioContext);
16
- const audioTagsContext = (0, react_1.useContext)(remotion_1.Internals.SharedAudioTagsContext);
17
- const { audioAndVideoTags } = remotion_1.Internals.useTimelineContext();
18
- const frameRef = (0, react_1.useRef)(frame);
19
- frameRef.current = frame;
20
- const video = remotion_1.Internals.useVideo();
21
- const config = remotion_1.Internals.useUnsafeVideoConfig();
22
- const emitter = (0, react_1.useContext)(emitter_context_js_1.PlayerEventEmitterContext);
23
- const lastFrame = ((_a = config === null || config === void 0 ? void 0 : config.durationInFrames) !== null && _a !== void 0 ? _a : 1) - 1;
24
- const isLastFrame = frame === lastFrame;
25
- const isFirstFrame = frame === 0;
26
- if (!emitter) {
27
- throw new TypeError('Expected Player event emitter context');
28
- }
29
- const bufferingContext = (0, react_1.useContext)(remotion_1.Internals.BufferingContextReact);
30
- if (!bufferingContext) {
31
- throw new Error('Missing the buffering context. Most likely you have a Remotion version mismatch.');
32
- }
33
- const { buffering } = bufferingContext;
34
- const seek = (0, react_1.useCallback)((newFrame) => {
35
- const frameToSeekTo = config
36
- ? remotion_1.Internals.TimelinePosition.clampFrameToCompositionRange(newFrame, config.durationInFrames)
37
- : Math.max(0, newFrame);
38
- if (video === null || video === void 0 ? void 0 : video.id) {
39
- setTimelinePosition((c) => c[video.id] === frameToSeekTo ? c : { ...c, [video.id]: frameToSeekTo });
40
- }
41
- frameRef.current = frameToSeekTo;
42
- emitter.dispatchSeek(frameToSeekTo);
43
- }, [config, emitter, setTimelinePosition, video === null || video === void 0 ? void 0 : video.id]);
44
- const play = (0, react_1.useCallback)((e) => {
45
- if (imperativePlaying.current) {
46
- return;
47
- }
48
- setHasPlayed(true);
49
- if (isLastFrame) {
50
- seek(0);
51
- }
52
- audioContext === null || audioContext === void 0 ? void 0 : audioContext.resume();
53
- /**
54
- * Play silent audio tags to warm them up for autoplay
55
- */
56
- if (audioTagsContext && audioTagsContext.numberOfAudioTags > 0 && e) {
57
- audioTagsContext.playAllAudios();
58
- }
59
- /**
60
- * Play audios and videos directly here so they can benefit from
61
- * being triggered by a click
62
- */
63
- audioAndVideoTags.current.forEach((a) => a.play('player play() was called and playing audio from a click'));
64
- imperativePlaying.current = true;
65
- setPlaying(true);
66
- playStart.current = frameRef.current;
67
- emitter.dispatchPlay();
68
- }, [
69
- imperativePlaying,
70
- isLastFrame,
71
- audioContext,
72
- audioTagsContext,
73
- setPlaying,
74
- emitter,
75
- seek,
76
- audioAndVideoTags,
77
- ]);
78
- const pause = (0, react_1.useCallback)(() => {
79
- if (imperativePlaying.current) {
80
- imperativePlaying.current = false;
81
- setPlaying(false);
82
- emitter.dispatchPause();
83
- audioContext === null || audioContext === void 0 ? void 0 : audioContext.suspend();
84
- }
85
- }, [emitter, imperativePlaying, setPlaying, audioContext]);
86
- const pauseAndReturnToPlayStart = (0, react_1.useCallback)(() => {
87
- if (imperativePlaying.current) {
88
- imperativePlaying.current = false;
89
- frameRef.current = playStart.current;
90
- if (config) {
91
- setTimelinePosition((c) => ({
92
- ...c,
93
- [config.id]: playStart.current,
94
- }));
95
- setPlaying(false);
96
- emitter.dispatchPause();
97
- }
98
- }
99
- }, [config, emitter, imperativePlaying, setPlaying, setTimelinePosition]);
100
- const videoId = video === null || video === void 0 ? void 0 : video.id;
101
- const frameBack = (0, react_1.useCallback)((frames) => {
102
- if (!videoId) {
103
- return null;
104
- }
105
- if (imperativePlaying.current) {
106
- return;
107
- }
108
- setFrame((c) => {
109
- var _a, _b;
110
- const prevFrame = (_b = (_a = c[videoId]) !== null && _a !== void 0 ? _a : window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0;
111
- const newFrame = Math.max(0, prevFrame - frames);
112
- if (prevFrame === newFrame) {
113
- return c;
114
- }
115
- return {
116
- ...c,
117
- [videoId]: newFrame,
118
- };
119
- });
120
- }, [imperativePlaying, setFrame, videoId]);
121
- const frameForward = (0, react_1.useCallback)((frames) => {
122
- if (!videoId) {
123
- return null;
124
- }
125
- if (imperativePlaying.current) {
126
- return;
127
- }
128
- setFrame((c) => {
129
- var _a, _b;
130
- const prevFrame = (_b = (_a = c[videoId]) !== null && _a !== void 0 ? _a : window.remotion_initialFrame) !== null && _b !== void 0 ? _b : 0;
131
- const newFrame = Math.min(lastFrame, prevFrame + frames);
132
- if (prevFrame === newFrame) {
133
- return c;
134
- }
135
- return {
136
- ...c,
137
- [videoId]: newFrame,
138
- };
139
- });
140
- }, [videoId, imperativePlaying, lastFrame, setFrame]);
141
- const toggle = (0, react_1.useCallback)((e) => {
142
- if (imperativePlaying.current) {
143
- pause();
144
- }
145
- else {
146
- play(e);
147
- }
148
- }, [imperativePlaying, pause, play]);
149
- const isPlaying = (0, react_1.useCallback)(() => {
150
- return imperativePlaying.current;
151
- }, [imperativePlaying]);
152
- const getCurrentFrame = (0, react_1.useCallback)(() => {
153
- return frameRef.current;
154
- }, [frameRef]);
155
- const isBuffering = (0, react_1.useCallback)(() => {
156
- return buffering.current;
157
- }, [buffering]);
158
- const returnValue = (0, react_1.useMemo)(() => {
159
- return {
160
- frameBack,
161
- frameForward,
162
- isLastFrame,
163
- emitter,
164
- playing,
165
- play,
166
- pause,
167
- seek,
168
- isFirstFrame,
169
- getCurrentFrame,
170
- isPlaying,
171
- isBuffering,
172
- pauseAndReturnToPlayStart,
173
- hasPlayed,
174
- toggle,
175
- };
176
- }, [
177
- emitter,
178
- frameBack,
179
- frameForward,
180
- hasPlayed,
181
- isFirstFrame,
182
- isLastFrame,
183
- getCurrentFrame,
184
- pause,
185
- pauseAndReturnToPlayStart,
186
- play,
187
- playing,
188
- seek,
189
- toggle,
190
- isPlaying,
191
- isBuffering,
192
- ]);
193
- return returnValue;
194
- };
195
- exports.usePlayer = usePlayer;