remotion 4.0.485 → 4.0.487

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.
@@ -5,6 +5,7 @@ const react_1 = require("react");
5
5
  const use_audio_frame_js_1 = require("./audio/use-audio-frame.js");
6
6
  const buffer_until_first_frame_js_1 = require("./buffer-until-first-frame.js");
7
7
  const buffering_js_1 = require("./buffering.js");
8
+ const get_media_sync_action_js_1 = require("./get-media-sync-action.js");
8
9
  const log_level_context_js_1 = require("./log-level-context.js");
9
10
  const log_js_1 = require("./log.js");
10
11
  const media_tag_current_time_timestamp_js_1 = require("./media-tag-current-time-timestamp.js");
@@ -144,7 +145,7 @@ const useMediaPlayback = ({ mediaRef, src, mediaType, playbackRate: localPlaybac
144
145
  }, [mediaRef, playbackRate, preservePitch]);
145
146
  (0, react_1.useEffect)(() => {
146
147
  var _a, _b;
147
- var _c;
148
+ var _c, _d;
148
149
  const tagName = mediaType === 'audio' ? '<Html5Audio>' : '<Html5Video>';
149
150
  if (!mediaRef.current) {
150
151
  throw new Error(`No ${mediaType} ref found`);
@@ -152,107 +153,94 @@ const useMediaPlayback = ({ mediaRef, src, mediaType, playbackRate: localPlaybac
152
153
  if (!src) {
153
154
  throw new Error(`No 'src' attribute was passed to the ${tagName} element.`);
154
155
  }
155
- const { duration } = mediaRef.current;
156
- const shouldBeTime = !Number.isNaN(duration) && Number.isFinite(duration)
157
- ? Math.min(duration, desiredUnclampedTime)
158
- : desiredUnclampedTime;
159
- const mediaTagTime = mediaTagCurrentTime.current.time;
160
- const rvcTime = (_c = (_a = rvcCurrentTime.current) === null || _a === void 0 ? void 0 : _a.time) !== null && _c !== void 0 ? _c : null;
161
- const isVariableFpsVideo = isVariableFpsVideoMap.current[src];
162
- const timeShiftMediaTag = Math.abs(shouldBeTime - mediaTagTime);
163
- const timeShiftRvcTag = rvcTime ? Math.abs(shouldBeTime - rvcTime) : null;
164
- const mostRecentTimeshift = ((_b = rvcCurrentTime.current) === null || _b === void 0 ? void 0 : _b.lastUpdate) &&
165
- rvcCurrentTime.current.time > mediaTagCurrentTime.current.lastUpdate
166
- ? timeShiftRvcTag
167
- : timeShiftMediaTag;
168
- const timeShift = timeShiftRvcTag && !isVariableFpsVideo
169
- ? mostRecentTimeshift
170
- : timeShiftMediaTag;
171
- if (timeShift > acceptableTimeShiftButLessThanDuration &&
172
- lastSeekDueToShift.current !== shouldBeTime) {
173
- // If scrubbing around, adjust timing
174
- // or if time shift is bigger than 0.45sec
156
+ const { current } = mediaRef;
157
+ const action = (0, get_media_sync_action_js_1.getMediaSyncAction)({
158
+ duration: current.duration,
159
+ currentTime: current.currentTime,
160
+ paused: current.paused,
161
+ ended: current.ended,
162
+ desiredUnclampedTime,
163
+ mediaTagTime: mediaTagCurrentTime.current.time,
164
+ mediaTagLastUpdate: mediaTagCurrentTime.current.lastUpdate,
165
+ rvcTime: (_c = (_a = rvcCurrentTime.current) === null || _a === void 0 ? void 0 : _a.time) !== null && _c !== void 0 ? _c : null,
166
+ rvcLastUpdate: (_d = (_b = rvcCurrentTime.current) === null || _b === void 0 ? void 0 : _b.lastUpdate) !== null && _d !== void 0 ? _d : null,
167
+ isVariableFpsVideo: Boolean(isVariableFpsVideoMap.current[src]),
168
+ acceptableTimeShift: acceptableTimeShiftButLessThanDuration,
169
+ lastSeekDueToShift: lastSeekDueToShift.current,
170
+ playing,
171
+ playbackRate,
172
+ mediaTagBufferingOrStalled: isMediaTagBuffering || isBuffering(),
173
+ playerBuffering: buffering.buffering.current,
174
+ absoluteFrame,
175
+ onlyWarnForMediaSeekingError,
176
+ isPremounting,
177
+ isPostmounting,
178
+ pauseWhenBuffering,
179
+ });
180
+ if (action.type === 'none') {
181
+ return;
182
+ }
183
+ if (action.type === 'seek-due-to-shift') {
175
184
  lastSeek.current = (0, seek_js_1.seek)({
176
- mediaRef: mediaRef.current,
177
- time: shouldBeTime,
185
+ mediaRef: current,
186
+ time: action.shouldBeTime,
178
187
  logLevel,
179
- why: `because time shift is too big. shouldBeTime = ${shouldBeTime}, isTime = ${mediaTagTime}, requestVideoCallbackTime = ${rvcTime}, timeShift = ${timeShift}${isVariableFpsVideo ? ', isVariableFpsVideo = true' : ''}, isPremounting = ${isPremounting}, isPostmounting = ${isPostmounting}, pauseWhenBuffering = ${pauseWhenBuffering}`,
188
+ why: action.why,
180
189
  mountTime,
181
190
  });
182
191
  lastSeekDueToShift.current = lastSeek.current;
183
- if (playing) {
184
- if (playbackRate > 0) {
185
- bufferUntilFirstFrame(shouldBeTime);
186
- }
187
- if (mediaRef.current.paused) {
188
- (0, play_and_handle_not_allowed_error_js_1.playAndHandleNotAllowedError)({
189
- mediaRef,
190
- mediaType,
191
- onAutoPlayError,
192
- logLevel,
193
- mountTime,
194
- reason: 'player is playing but media tag is paused, and just seeked',
195
- isPlayer: env.isPlayer,
196
- });
197
- }
192
+ if (action.bufferUntilFirstFrame) {
193
+ bufferUntilFirstFrame(action.shouldBeTime);
198
194
  }
199
- if (!onlyWarnForMediaSeekingError) {
200
- (0, warn_about_non_seekable_media_js_1.warnAboutNonSeekableMedia)(mediaRef.current, onlyWarnForMediaSeekingError ? 'console-warning' : 'console-error');
201
- }
202
- return;
203
- }
204
- const seekThreshold = playing ? 0.15 : 0.01;
205
- // Only perform a seek if the time is not already the same.
206
- // Chrome rounds to 6 digits, so 0.033333333 -> 0.033333,
207
- // therefore a threshold is allowed.
208
- // Refer to the https://github.com/remotion-dev/video-buffering-example
209
- // which is fixed by only seeking conditionally.
210
- const makesSenseToSeek = Math.abs(mediaRef.current.currentTime - shouldBeTime) > seekThreshold;
211
- const isMediaTagBufferingOrStalled = isMediaTagBuffering || isBuffering();
212
- const isSomethingElseBuffering = buffering.buffering.current && !isMediaTagBufferingOrStalled;
213
- if (!playing || isSomethingElseBuffering) {
214
- if (makesSenseToSeek) {
215
- lastSeek.current = (0, seek_js_1.seek)({
216
- mediaRef: mediaRef.current,
217
- time: shouldBeTime,
195
+ if (action.playReason !== null) {
196
+ (0, play_and_handle_not_allowed_error_js_1.playAndHandleNotAllowedError)({
197
+ mediaRef,
198
+ mediaType,
199
+ onAutoPlayError,
218
200
  logLevel,
219
- why: `not playing or something else is buffering. time offset is over seek threshold (${seekThreshold})`,
220
201
  mountTime,
202
+ reason: action.playReason,
203
+ isPlayer: env.isPlayer,
221
204
  });
222
205
  }
206
+ if (action.warnAboutNonSeekable) {
207
+ (0, warn_about_non_seekable_media_js_1.warnAboutNonSeekableMedia)(current, 'console-error');
208
+ }
223
209
  return;
224
210
  }
225
- if (!playing || buffering.buffering.current) {
226
- return;
227
- }
228
- // We now assured we are in playing state and not buffering
229
- const pausedCondition = mediaRef.current.paused && !mediaRef.current.ended;
230
- const firstFrameCondition = absoluteFrame === 0;
231
- if (pausedCondition || firstFrameCondition) {
232
- const reason = pausedCondition
233
- ? 'media tag is paused'
234
- : 'absolute frame is 0';
235
- if (makesSenseToSeek) {
211
+ if (action.type === 'seek-if-not-playing') {
212
+ if (action.why !== null) {
236
213
  lastSeek.current = (0, seek_js_1.seek)({
237
- mediaRef: mediaRef.current,
238
- time: shouldBeTime,
214
+ mediaRef: current,
215
+ time: action.shouldBeTime,
239
216
  logLevel,
240
- why: `is over timeshift threshold (threshold = ${seekThreshold}) and ${reason}`,
217
+ why: action.why,
241
218
  mountTime,
242
219
  });
243
220
  }
244
- (0, play_and_handle_not_allowed_error_js_1.playAndHandleNotAllowedError)({
245
- mediaRef,
246
- mediaType,
247
- onAutoPlayError,
221
+ return;
222
+ }
223
+ // action.type === 'play-and-seek'
224
+ if (action.why !== null) {
225
+ lastSeek.current = (0, seek_js_1.seek)({
226
+ mediaRef: current,
227
+ time: action.shouldBeTime,
248
228
  logLevel,
229
+ why: action.why,
249
230
  mountTime,
250
- reason: `player is playing and ${reason}`,
251
- isPlayer: env.isPlayer,
252
231
  });
253
- if (!isVariableFpsVideo && playbackRate > 0) {
254
- bufferUntilFirstFrame(shouldBeTime);
255
- }
232
+ }
233
+ (0, play_and_handle_not_allowed_error_js_1.playAndHandleNotAllowedError)({
234
+ mediaRef,
235
+ mediaType,
236
+ onAutoPlayError,
237
+ logLevel,
238
+ mountTime,
239
+ reason: action.playReason,
240
+ isPlayer: env.isPlayer,
241
+ });
242
+ if (action.bufferUntilFirstFrame) {
243
+ bufferUntilFirstFrame(action.shouldBeTime);
256
244
  }
257
245
  }, [
258
246
  absoluteFrame,
@@ -2,7 +2,7 @@ import type { RefObject } from 'react';
2
2
  export declare const useRequestVideoCallbackTime: ({ mediaRef, mediaType, lastSeek, onVariableFpsVideoDetected, }: {
3
3
  mediaRef: RefObject<HTMLAudioElement | HTMLVideoElement | null>;
4
4
  mediaType: "audio" | "video";
5
- lastSeek: import("react").MutableRefObject<number | null>;
5
+ lastSeek: RefObject<number | null>;
6
6
  onVariableFpsVideoDetected: () => void;
7
7
  }) => RefObject<{
8
8
  time: number;
@@ -3,4 +3,4 @@
3
3
  * @see [Documentation](https://remotion.dev/docs/version)
4
4
  * @returns {string} The current version of the remotion package
5
5
  */
6
- export declare const VERSION = "4.0.485";
6
+ export declare const VERSION = "4.0.487";
@@ -7,4 +7,4 @@ exports.VERSION = void 0;
7
7
  * @see [Documentation](https://remotion.dev/docs/version)
8
8
  * @returns {string} The current version of the remotion package
9
9
  */
10
- exports.VERSION = '4.0.485';
10
+ exports.VERSION = '4.0.487';
@@ -39,7 +39,7 @@ export declare function useRemotionContexts(): {
39
39
  listenForResume: (callback: () => void) => {
40
40
  remove: () => void;
41
41
  };
42
- buffering: React.MutableRefObject<boolean>;
42
+ buffering: React.RefObject<boolean>;
43
43
  } | null;
44
44
  logLevelContext: import("./log-level-context.js").LoggingContextValue;
45
45
  };