@remotion/player 4.0.541 → 4.0.543

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.
@@ -505,6 +505,10 @@ var PlayerEmitterProvider = ({ children, currentPlaybackRate }) => {
505
505
  });
506
506
  };
507
507
 
508
+ // src/playback-range-context.ts
509
+ import { createContext as createContext3 } from "react";
510
+ var PlaybackRangeContext = createContext3({ inFrame: null, outFrame: null });
511
+
508
512
  // src/PlayerControls.tsx
509
513
  import { useCallback as useCallback7, useEffect as useEffect7, useMemo as useMemo9, useRef as useRef5, useState as useState9 } from "react";
510
514
 
@@ -1031,6 +1035,8 @@ var usePlayerMethods = () => {
1031
1035
  const videoId = video?.id ?? null;
1032
1036
  const videoDurationInFrames = video?.durationInFrames ?? null;
1033
1037
  const config = Internals5.useUnsafeVideoConfig();
1038
+ const { inFrame, outFrame } = useContext2(PlaybackRangeContext);
1039
+ const playbackRate = useContext2(Internals5.PlaybackRateContext)?.playbackRate ?? 1;
1034
1040
  const emitter = useContext2(PlayerEventEmitterContext);
1035
1041
  const playStart = useRef3(0);
1036
1042
  const fallbackFrame = useRef3(null);
@@ -1065,9 +1071,11 @@ var usePlayerMethods = () => {
1065
1071
  if (readIsPlaying()) {
1066
1072
  return;
1067
1073
  }
1068
- const lastFrameForPlayback = (config?.durationInFrames ?? 1) - 1;
1069
- if (getCurrentFrame() === lastFrameForPlayback) {
1070
- seek(0);
1074
+ const rangeStart = inFrame ?? 0;
1075
+ const rangeEnd = outFrame ?? (config?.durationInFrames ?? 1) - 1;
1076
+ const reverse = playbackRate < 0;
1077
+ if (getCurrentFrame() === (reverse ? rangeStart : rangeEnd)) {
1078
+ seek(reverse ? rangeEnd : rangeStart);
1071
1079
  }
1072
1080
  if (!muted) {
1073
1081
  if (isAutoPlayAttempt) {
@@ -1088,6 +1096,9 @@ var usePlayerMethods = () => {
1088
1096
  audioContext,
1089
1097
  audioTagsContext,
1090
1098
  config?.durationInFrames,
1099
+ inFrame,
1100
+ outFrame,
1101
+ playbackRate,
1091
1102
  emitter,
1092
1103
  getCurrentFrame,
1093
1104
  muted,
@@ -1858,7 +1869,7 @@ var TimelineSequenceObserverContext = React8.createContext(null);
1858
1869
 
1859
1870
  // src/use-playback.ts
1860
1871
  import { useLayoutEffect as useLayoutEffect2 } from "react";
1861
- import { useContext as useContext3, useEffect as useEffect10, useRef as useRef8 } from "react";
1872
+ import { useCallback as useCallback8, useContext as useContext3, useEffect as useEffect10, useRef as useRef8 } from "react";
1862
1873
  import { Internals as Internals10 } from "remotion";
1863
1874
 
1864
1875
  // src/browser-mediasession.ts
@@ -1991,6 +2002,15 @@ var calculateNextFrame = ({
1991
2002
  const isCurrentFrameOutside = startFrame > actualLastFrame || startFrame < actualFirstFrame;
1992
2003
  const isNextFrameOutside = nextFrame > actualLastFrame || nextFrame < actualFirstFrame;
1993
2004
  const hasEnded = !shouldLoop && isNextFrameOutside && !isCurrentFrameOutside;
2005
+ if (shouldLoop && isNextFrameOutside && !isCurrentFrameOutside) {
2006
+ const playbackRange = actualLastFrame - actualFirstFrame + 1;
2007
+ const frameWithinRange = (nextFrame - actualFirstFrame) % playbackRange;
2008
+ return {
2009
+ nextFrame: actualFirstFrame + (frameWithinRange + playbackRange) % playbackRange,
2010
+ framesToAdvance,
2011
+ hasEnded
2012
+ };
2013
+ }
1994
2014
  if (playbackSpeed > 0) {
1995
2015
  if (isNextFrameOutside) {
1996
2016
  return {
@@ -2055,12 +2075,12 @@ var setGlobalTimeAnchor = ({
2055
2075
 
2056
2076
  // src/use-playback.ts
2057
2077
  var shouldForceAnchorChange = (newState) => {
2058
- if (newState === "suspended" || newState === "running-to-suspended") {
2059
- return true;
2060
- }
2061
- if (newState === "closed" || newState === "interrupted" || newState === "running" || newState === "suspended-to-running") {
2078
+ if (newState === "closed") {
2062
2079
  return false;
2063
2080
  }
2081
+ if (newState === "suspended" || newState === "running-to-suspended" || newState === "interrupted" || newState === "running" || newState === "suspended-to-running") {
2082
+ return true;
2083
+ }
2064
2084
  throw new Error(`Unexpected audio context state: ${newState}`);
2065
2085
  };
2066
2086
  var usePlayback = ({
@@ -2087,39 +2107,103 @@ var usePlayback = ({
2087
2107
  const logLevel = Internals10.useLogLevel();
2088
2108
  const isBackgroundedRef = useIsBackgrounded();
2089
2109
  const lastTimeUpdateTimestamp = useRef8(0);
2110
+ const seekRevisionAtRender = seek?.revision.current ?? null;
2111
+ const anchorSeekRevision = useRef8(seekRevisionAtRender);
2112
+ const playbackJumpRevision = useRef8(0);
2113
+ const jumpRevision = playbackJumpRevision.current;
2090
2114
  const playbackClockRef = useRef8(null);
2091
- const previousMutedRef = useRef8(muted);
2092
- const anchoredAudioContextRef = useRef8(null);
2115
+ const previousAudioBoundary = useRef8(null);
2093
2116
  useBrowserMediaSession({
2094
2117
  browserMediaControlsBehavior,
2095
2118
  playbackRate,
2096
2119
  videoConfig: config
2097
2120
  });
2098
- useLayoutEffect2(() => {
2099
- if (!sharedAudioContext) {
2100
- return;
2101
- }
2102
- if (!sharedAudioContext.audioContext) {
2103
- return;
2104
- }
2105
- if (fps === null) {
2106
- return;
2121
+ const updateAudioAnchor = useCallback8(() => {
2122
+ if (!sharedAudioContext?.audioContext || fps === null || muted) {
2123
+ return false;
2107
2124
  }
2108
- if (muted) {
2109
- return;
2125
+ let absoluteFrame = getCurrentFrame();
2126
+ const clock = playbackClockRef.current;
2127
+ if (playing && clock !== null && durationInFrames !== null && clock.compositionId === compositionId && clock.fps === fps && clock.playbackRate === playbackRate) {
2128
+ const actualFirstFrame = inFrame ?? 0;
2129
+ const actualLastFrame = outFrame ?? durationInFrames - 1;
2130
+ const { nextFrame, hasEnded } = calculateNextFrame({
2131
+ time: performance.now() - clock.startedTime,
2132
+ currentFrame: clock.frame,
2133
+ playbackSpeed: playbackRate,
2134
+ fps,
2135
+ actualFirstFrame,
2136
+ actualLastFrame,
2137
+ framesAdvanced: clock.framesAdvanced,
2138
+ shouldLoop: loop
2139
+ });
2140
+ absoluteFrame = hasEnded && !moveToBeginningWhenEnded ? playbackRate > 0 ? actualLastFrame : actualFirstFrame : nextFrame;
2110
2141
  }
2111
2142
  const changed = setGlobalTimeAnchor({
2112
2143
  audioContext: sharedAudioContext.audioContext,
2113
2144
  audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
2114
- absoluteTimeInSeconds: frame / fps,
2145
+ absoluteTimeInSeconds: absoluteFrame / fps,
2115
2146
  globalPlaybackRate: playbackRate,
2116
2147
  logLevel,
2117
- force: false
2148
+ force: true
2118
2149
  });
2119
2150
  if (changed) {
2120
2151
  sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
2121
2152
  }
2122
- }, [fps, frame, logLevel, playbackRate, sharedAudioContext, muted]);
2153
+ return changed;
2154
+ }, [
2155
+ compositionId,
2156
+ durationInFrames,
2157
+ fps,
2158
+ getCurrentFrame,
2159
+ inFrame,
2160
+ logLevel,
2161
+ loop,
2162
+ moveToBeginningWhenEnded,
2163
+ muted,
2164
+ outFrame,
2165
+ playbackRate,
2166
+ playing,
2167
+ sharedAudioContext
2168
+ ]);
2169
+ useLayoutEffect2(() => {
2170
+ const boundary = {
2171
+ audioContext: sharedAudioContext?.audioContext ?? null,
2172
+ compositionId,
2173
+ fps,
2174
+ playbackRate,
2175
+ muted,
2176
+ playing,
2177
+ seekRevision: seekRevisionAtRender,
2178
+ jumpRevision
2179
+ };
2180
+ const previous = previousAudioBoundary.current;
2181
+ previousAudioBoundary.current = boundary;
2182
+ anchorSeekRevision.current = seekRevisionAtRender;
2183
+ if (previous !== null && Object.keys(boundary).every((key) => boundary[key] === previous[key])) {
2184
+ return;
2185
+ }
2186
+ const clock = playbackClockRef.current;
2187
+ if (clock !== null && clock.seekRevision !== seekRevisionAtRender) {
2188
+ clock.frame = getCurrentFrame();
2189
+ clock.seekRevision = seekRevisionAtRender;
2190
+ }
2191
+ const changed = updateAudioAnchor();
2192
+ if (!changed && playing && !muted && sharedAudioContext?._experimentalKeepAudioContextAlive) {
2193
+ sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
2194
+ }
2195
+ }, [
2196
+ compositionId,
2197
+ fps,
2198
+ playbackRate,
2199
+ muted,
2200
+ sharedAudioContext,
2201
+ getCurrentFrame,
2202
+ jumpRevision,
2203
+ playing,
2204
+ seekRevisionAtRender,
2205
+ updateAudioAnchor
2206
+ ]);
2123
2207
  useLayoutEffect2(() => {
2124
2208
  const audioContext = sharedAudioContext?.audioContext;
2125
2209
  if (!audioContext) {
@@ -2133,28 +2217,19 @@ var usePlayback = ({
2133
2217
  }
2134
2218
  const callback = () => {
2135
2219
  const newState = sharedAudioContext?.getAudioContextState();
2220
+ if (newState === "running" && sharedAudioContext?.getIsResumingAudioContext()) {
2221
+ return;
2222
+ }
2136
2223
  if (newState && shouldForceAnchorChange(newState)) {
2137
- const changed = setGlobalTimeAnchor({
2138
- audioContext,
2139
- audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
2140
- absoluteTimeInSeconds: getCurrentFrame() / fps,
2141
- globalPlaybackRate: playbackRate,
2142
- logLevel,
2143
- force: true
2144
- });
2145
- if (changed) {
2146
- sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
2147
- }
2224
+ updateAudioAnchor();
2148
2225
  }
2149
2226
  };
2150
2227
  audioContext?.addEventListener("statechange", callback);
2151
2228
  return () => {
2152
2229
  audioContext?.removeEventListener("statechange", callback);
2153
2230
  };
2154
- }, [fps, getCurrentFrame, logLevel, muted, playbackRate, sharedAudioContext]);
2231
+ }, [fps, getCurrentFrame, muted, sharedAudioContext, updateAudioAnchor]);
2155
2232
  useEffect10(() => {
2156
- const wasMuted = previousMutedRef.current;
2157
- previousMutedRef.current = muted;
2158
2233
  if (fps === null || durationInFrames === null || compositionId === null) {
2159
2234
  playbackClockRef.current = null;
2160
2235
  return;
@@ -2173,32 +2248,17 @@ var usePlayback = ({
2173
2248
  compositionId,
2174
2249
  startedTime: performance.now(),
2175
2250
  framesAdvanced: 0,
2251
+ frame: getCurrentFrame(),
2252
+ seekRevision: seek?.revision.current ?? null,
2176
2253
  fps,
2177
2254
  playbackRate
2178
2255
  } : previousClock;
2256
+ clock.frame = Internals10.Timeline.clampFrameToCompositionRange(clock.frame, durationInFrames);
2179
2257
  playbackClockRef.current = clock;
2180
- if (sharedAudioContext?._experimentalKeepAudioContextAlive && sharedAudioContext.audioContext && !muted) {
2181
- const didUnmute = wasMuted && !muted;
2182
- const didReplaceAudioContext = anchoredAudioContextRef.current !== sharedAudioContext.audioContext;
2183
- const shouldRescheduleAudio = shouldRestartClock || didUnmute || didReplaceAudioContext;
2184
- const changed = setGlobalTimeAnchor({
2185
- audioContext: sharedAudioContext.audioContext,
2186
- audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
2187
- absoluteTimeInSeconds: getCurrentFrame() / fps,
2188
- globalPlaybackRate: playbackRate,
2189
- logLevel,
2190
- force: shouldRescheduleAudio
2191
- });
2192
- anchoredAudioContextRef.current = sharedAudioContext.audioContext;
2193
- if (changed || shouldRescheduleAudio) {
2194
- sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
2195
- }
2196
- }
2197
2258
  let hasBeenStopped = false;
2198
2259
  let audioContextFailed = false;
2199
2260
  let reqAnimFrameCall = null;
2200
- let playbackFrame = getCurrentFrame();
2201
- let lastSeekRevision = seek?.revision.current ?? null;
2261
+ let unsubscribeBuffering = null;
2202
2262
  const cancelQueuedFrame = () => {
2203
2263
  if (reqAnimFrameCall !== null) {
2204
2264
  if (reqAnimFrameCall.type === "raf") {
@@ -2206,13 +2266,17 @@ var usePlayback = ({
2206
2266
  } else {
2207
2267
  clearTimeout(reqAnimFrameCall.id);
2208
2268
  }
2269
+ reqAnimFrameCall = null;
2209
2270
  }
2210
2271
  };
2211
2272
  const stop = () => {
2212
2273
  hasBeenStopped = true;
2213
2274
  cancelQueuedFrame();
2275
+ unsubscribeBuffering?.();
2276
+ unsubscribeBuffering = null;
2214
2277
  };
2215
2278
  const callback = () => {
2279
+ reqAnimFrameCall = null;
2216
2280
  if (hasBeenStopped) {
2217
2281
  return;
2218
2282
  }
@@ -2220,18 +2284,29 @@ var usePlayback = ({
2220
2284
  sharedAudioContext?.suspend?.();
2221
2285
  return;
2222
2286
  }
2223
- if (!muted && !audioContextFailed && !isBuffering()) {
2287
+ if (isBuffering()) {
2288
+ queueNextFrame();
2289
+ return;
2290
+ }
2291
+ if (!muted && !audioContextFailed) {
2224
2292
  sharedAudioContext?.resume?.();
2225
2293
  }
2226
2294
  const time = performance.now() - clock.startedTime;
2227
2295
  const actualLastFrame = outFrame ?? durationInFrames - 1;
2228
2296
  const actualFirstFrame = inFrame ?? 0;
2229
2297
  const seekRevision = seek?.revision.current ?? null;
2230
- if (seekRevision !== lastSeekRevision) {
2231
- playbackFrame = getCurrentFrame();
2232
- lastSeekRevision = seekRevision;
2298
+ if (seekRevision !== clock.seekRevision) {
2299
+ clock.frame = getCurrentFrame();
2300
+ clock.seekRevision = seekRevision;
2301
+ if (anchorSeekRevision.current !== seekRevision) {
2302
+ updateAudioAnchor();
2303
+ anchorSeekRevision.current = seekRevision;
2304
+ if (previousAudioBoundary.current !== null) {
2305
+ previousAudioBoundary.current.seekRevision = seekRevision;
2306
+ }
2307
+ }
2233
2308
  }
2234
- const currentFrame = playbackFrame;
2309
+ const currentFrame = clock.frame;
2235
2310
  const { nextFrame, framesToAdvance, hasEnded } = calculateNextFrame({
2236
2311
  time,
2237
2312
  currentFrame,
@@ -2244,9 +2319,18 @@ var usePlayback = ({
2244
2319
  });
2245
2320
  clock.framesAdvanced += framesToAdvance;
2246
2321
  const frameToDisplay = hasEnded && !moveToBeginningWhenEnded ? playbackRate > 0 ? actualLastFrame : actualFirstFrame : nextFrame;
2247
- if (frameToDisplay !== currentFrame && !isBuffering()) {
2248
- playbackFrame = frameToDisplay;
2322
+ const didJump = frameToDisplay !== currentFrame + framesToAdvance;
2323
+ if (didJump) {
2324
+ playbackJumpRevision.current++;
2325
+ }
2326
+ clock.frame = frameToDisplay;
2327
+ if (frameToDisplay !== currentFrame) {
2249
2328
  setFrameFromPlayback((c) => ({ ...c, [compositionId]: frameToDisplay }));
2329
+ } else if (didJump) {
2330
+ updateAudioAnchor();
2331
+ if (previousAudioBoundary.current !== null) {
2332
+ previousAudioBoundary.current.jumpRevision = playbackJumpRevision.current;
2333
+ }
2250
2334
  }
2251
2335
  if (hasEnded) {
2252
2336
  stop();
@@ -2281,16 +2365,21 @@ var usePlayback = ({
2281
2365
  if (!muted && !audioContextFailed) {
2282
2366
  sharedAudioContext?.suspend?.();
2283
2367
  }
2284
- const unsubscribe = subscribeBuffering((state) => {
2368
+ unsubscribeBuffering = subscribeBuffering((state) => {
2285
2369
  if (state.buffering) {
2286
2370
  return;
2287
2371
  }
2288
- unsubscribe();
2289
- if (!muted && !audioContextFailed && sharedAudioContext?._experimentalKeepAudioContextAlive) {
2290
- sharedAudioContext.resume();
2372
+ unsubscribeBuffering?.();
2373
+ unsubscribeBuffering = null;
2374
+ if (hasBeenStopped) {
2375
+ return;
2291
2376
  }
2292
2377
  clock.startedTime = performance.now();
2293
2378
  clock.framesAdvanced = 0;
2379
+ updateAudioAnchor();
2380
+ if (!muted && !audioContextFailed && sharedAudioContext?._experimentalKeepAudioContextAlive) {
2381
+ sharedAudioContext.resume();
2382
+ }
2294
2383
  queueNextFrame();
2295
2384
  });
2296
2385
  return;
@@ -2304,9 +2393,13 @@ var usePlayback = ({
2304
2393
  }
2305
2394
  reqAnimFrameCall = { type: "raf", id: requestAnimationFrame(callback) };
2306
2395
  };
2396
+ const unsubscribeSeek = seek?.subscribe(() => {
2397
+ clock.startedTime = performance.now();
2398
+ clock.framesAdvanced = 0;
2399
+ });
2307
2400
  queueNextFrame();
2308
2401
  const onVisibilityChange = () => {
2309
- if (document.visibilityState === "visible") {
2402
+ if (reqAnimFrameCall === null) {
2310
2403
  return;
2311
2404
  }
2312
2405
  cancelQueuedFrame();
@@ -2315,6 +2408,7 @@ var usePlayback = ({
2315
2408
  window.addEventListener("visibilitychange", onVisibilityChange);
2316
2409
  return () => {
2317
2410
  window.removeEventListener("visibilitychange", onVisibilityChange);
2411
+ unsubscribeSeek?.();
2318
2412
  stop();
2319
2413
  };
2320
2414
  }, [
@@ -2338,8 +2432,8 @@ var usePlayback = ({
2338
2432
  setPlayerMuted,
2339
2433
  subscribeBuffering,
2340
2434
  seek,
2341
- logLevel,
2342
- muted
2435
+ muted,
2436
+ updateAudioAnchor
2343
2437
  ]);
2344
2438
  useEffect10(() => {
2345
2439
  const now = performance.now();
@@ -2363,7 +2457,7 @@ var usePlayback = ({
2363
2457
  // src/Player.tsx
2364
2458
  import React13, {
2365
2459
  forwardRef as forwardRef2,
2366
- useCallback as useCallback12,
2460
+ useCallback as useCallback13,
2367
2461
  useEffect as useEffect13,
2368
2462
  useImperativeHandle as useImperativeHandle2,
2369
2463
  useLayoutEffect as useLayoutEffect3,
@@ -2383,7 +2477,7 @@ var playerCssClassname = (override) => {
2383
2477
  import React11, {
2384
2478
  Suspense,
2385
2479
  forwardRef,
2386
- useCallback as useCallback10,
2480
+ useCallback as useCallback11,
2387
2481
  useContext as useContext4,
2388
2482
  useEffect as useEffect12,
2389
2483
  useImperativeHandle,
@@ -2393,6 +2487,29 @@ import React11, {
2393
2487
  } from "react";
2394
2488
  import { Internals as Internals11 } from "remotion";
2395
2489
 
2490
+ // src/buffer-indicator-state.ts
2491
+ var reduceBufferIndicator = (state, event) => {
2492
+ switch (event.type) {
2493
+ case "buffer-start":
2494
+ if (state.type !== "idle") {
2495
+ return { state, effect: null };
2496
+ }
2497
+ return event.delayInMilliseconds === 0 ? { state: { type: "showing" }, effect: null } : { state: { type: "pending" }, effect: "start-timer" };
2498
+ case "buffer-end":
2499
+ if (state.type === "idle") {
2500
+ return { state, effect: null };
2501
+ }
2502
+ return {
2503
+ state: { type: "idle" },
2504
+ effect: state.type === "pending" ? "clear-timer" : null
2505
+ };
2506
+ case "delay-elapsed":
2507
+ return state.type === "pending" ? { state: { type: "showing" }, effect: null } : { state, effect: null };
2508
+ default:
2509
+ throw new Error("Unhandled buffer indicator event: " + JSON.stringify(event));
2510
+ }
2511
+ };
2512
+
2396
2513
  // src/error-boundary.tsx
2397
2514
  import React9 from "react";
2398
2515
  import { jsx as jsx10 } from "react/jsx-runtime";
@@ -2519,7 +2636,7 @@ var RenderWarningIfBlacklist = () => {
2519
2636
  var IS_NODE = typeof document === "undefined";
2520
2637
 
2521
2638
  // src/utils/use-click-prevention-on-double-click.ts
2522
- import { useCallback as useCallback9, useMemo as useMemo11 } from "react";
2639
+ import { useCallback as useCallback10, useMemo as useMemo11 } from "react";
2523
2640
 
2524
2641
  // src/utils/cancellable-promise.ts
2525
2642
  var cancellablePromise = (promise) => {
@@ -2547,16 +2664,16 @@ var cancellablePromise = (promise) => {
2547
2664
  var delay = (n) => new Promise((resolve) => setTimeout(resolve, n));
2548
2665
 
2549
2666
  // src/utils/use-cancellable-promises.ts
2550
- import { useCallback as useCallback8, useMemo as useMemo10, useRef as useRef9 } from "react";
2667
+ import { useCallback as useCallback9, useMemo as useMemo10, useRef as useRef9 } from "react";
2551
2668
  var useCancellablePromises = () => {
2552
2669
  const pendingPromises = useRef9([]);
2553
- const appendPendingPromise = useCallback8((promise) => {
2670
+ const appendPendingPromise = useCallback9((promise) => {
2554
2671
  pendingPromises.current = [...pendingPromises.current, promise];
2555
2672
  }, []);
2556
- const removePendingPromise = useCallback8((promise) => {
2673
+ const removePendingPromise = useCallback9((promise) => {
2557
2674
  pendingPromises.current = pendingPromises.current.filter((p) => p !== promise);
2558
2675
  }, []);
2559
- const clearPendingPromises = useCallback8(() => pendingPromises.current.map((p) => p.cancel()), []);
2676
+ const clearPendingPromises = useCallback9(() => pendingPromises.current.map((p) => p.cancel()), []);
2560
2677
  const api = useMemo10(() => ({
2561
2678
  appendPendingPromise,
2562
2679
  removePendingPromise,
@@ -2568,7 +2685,7 @@ var useCancellablePromises = () => {
2568
2685
  // src/utils/use-click-prevention-on-double-click.ts
2569
2686
  var useClickPreventionOnDoubleClick = (onClick, onDoubleClick, doubleClickToFullscreen) => {
2570
2687
  const api = useCancellablePromises();
2571
- const handleClick = useCallback9(async (e) => {
2688
+ const handleClick = useCallback10(async (e) => {
2572
2689
  if (e instanceof PointerEvent ? e.pointerType === "touch" : e.nativeEvent.pointerType === "touch") {
2573
2690
  onClick(e);
2574
2691
  return;
@@ -2588,14 +2705,14 @@ var useClickPreventionOnDoubleClick = (onClick, onDoubleClick, doubleClickToFull
2588
2705
  }
2589
2706
  }
2590
2707
  }, [api, onClick]);
2591
- const handlePointerDown = useCallback9(() => {
2708
+ const handlePointerDown = useCallback10(() => {
2592
2709
  document.addEventListener("pointerup", (newEvt) => {
2593
2710
  handleClick(newEvt);
2594
2711
  }, {
2595
2712
  once: true
2596
2713
  });
2597
2714
  }, [handleClick]);
2598
- const handleDoubleClick = useCallback9(() => {
2715
+ const handleDoubleClick = useCallback10(() => {
2599
2716
  api.clearPendingPromises();
2600
2717
  onDoubleClick();
2601
2718
  }, [api, onDoubleClick]);
@@ -2639,8 +2756,6 @@ var PlayerUI = ({
2639
2756
  showPosterWhenPaused,
2640
2757
  showPosterWhenBuffering,
2641
2758
  showPosterWhenBufferingAndPaused,
2642
- inFrame,
2643
- outFrame,
2644
2759
  initiallyShowControls,
2645
2760
  renderFullscreen: renderFullscreenButton,
2646
2761
  renderPlayPauseButton,
@@ -2657,6 +2772,7 @@ var PlayerUI = ({
2657
2772
  overrideInternalClassName,
2658
2773
  noSuspense
2659
2774
  }, ref) => {
2775
+ const { inFrame, outFrame } = useContext4(PlaybackRangeContext);
2660
2776
  const config = Internals11.useUnsafeVideoConfig();
2661
2777
  const video = Internals11.useVideo();
2662
2778
  const container = useRef10(null);
@@ -2678,7 +2794,7 @@ var PlayerUI = ({
2678
2794
  const player = usePlayerMethods();
2679
2795
  const playing = Internals11.usePlaying();
2680
2796
  const frame = Internals11.Timeline.useTimelinePosition();
2681
- const play = useCallback10((e) => {
2797
+ const play = useCallback11((e) => {
2682
2798
  if (player.isPlaying()) {
2683
2799
  return;
2684
2800
  }
@@ -2730,14 +2846,14 @@ var PlayerUI = ({
2730
2846
  document.removeEventListener("webkitfullscreenchange", onFullscreenChange);
2731
2847
  };
2732
2848
  }, []);
2733
- const toggle = useCallback10((e) => {
2849
+ const toggle = useCallback11((e) => {
2734
2850
  if (player.isPlaying()) {
2735
2851
  player.pause();
2736
2852
  } else {
2737
2853
  play(e);
2738
2854
  }
2739
2855
  }, [play, player]);
2740
- const requestFullscreen = useCallback10(() => {
2856
+ const requestFullscreen = useCallback11(() => {
2741
2857
  if (!allowFullscreen) {
2742
2858
  throw new Error("allowFullscreen is false");
2743
2859
  }
@@ -2753,7 +2869,7 @@ var PlayerUI = ({
2753
2869
  container.current.requestFullscreen();
2754
2870
  }
2755
2871
  }, [allowFullscreen, supportsFullScreen]);
2756
- const exitFullscreen = useCallback10(() => {
2872
+ const exitFullscreen = useCallback11(() => {
2757
2873
  if (document.webkitExitFullscreen) {
2758
2874
  document.webkitExitFullscreen();
2759
2875
  } else {
@@ -2806,45 +2922,50 @@ var PlayerUI = ({
2806
2922
  }
2807
2923
  player.emitter.dispatchScaleChange(scale);
2808
2924
  }, [player.emitter, scale]);
2809
- const [showBufferIndicator, setShowBufferState] = useState10(false);
2925
+ const { subscribeBuffering, isBuffering } = useContext4(Internals11.SetTimelineContext);
2926
+ const [bufferIndicator, setBufferIndicator] = useState10({
2927
+ type: "idle"
2928
+ });
2929
+ const showBufferIndicator = bufferIndicator.type === "showing";
2810
2930
  useEffect12(() => {
2931
+ let current = { type: "idle" };
2811
2932
  let timeout = null;
2812
- let stopped = false;
2813
- const onBuffer = () => {
2814
- stopped = false;
2815
- requestAnimationFrame(() => {
2816
- if (bufferStateDelayInMilliseconds === 0) {
2817
- setShowBufferState(true);
2818
- } else {
2819
- timeout = setTimeout(() => {
2820
- if (!stopped) {
2821
- setShowBufferState(true);
2822
- }
2823
- }, bufferStateDelayInMilliseconds);
2824
- }
2825
- });
2933
+ const dispatch = (event) => {
2934
+ const { state: next, effect } = reduceBufferIndicator(current, event);
2935
+ if (effect === "start-timer") {
2936
+ timeout = setTimeout(() => {
2937
+ timeout = null;
2938
+ dispatch({ type: "delay-elapsed" });
2939
+ }, bufferStateDelayInMilliseconds);
2940
+ } else if (effect === "clear-timer" && timeout !== null) {
2941
+ clearTimeout(timeout);
2942
+ timeout = null;
2943
+ }
2944
+ if (next.type !== current.type) {
2945
+ current = next;
2946
+ setBufferIndicator(next);
2947
+ }
2826
2948
  };
2827
- const onResume = () => {
2828
- requestAnimationFrame(() => {
2829
- stopped = true;
2830
- setShowBufferState(false);
2831
- if (timeout) {
2832
- clearTimeout(timeout);
2833
- }
2949
+ const unsubscribe = subscribeBuffering((state) => {
2950
+ dispatch(state.buffering ? {
2951
+ type: "buffer-start",
2952
+ delayInMilliseconds: bufferStateDelayInMilliseconds
2953
+ } : { type: "buffer-end" });
2954
+ });
2955
+ if (isBuffering()) {
2956
+ dispatch({
2957
+ type: "buffer-start",
2958
+ delayInMilliseconds: bufferStateDelayInMilliseconds
2834
2959
  });
2835
- };
2836
- player.emitter.addEventListener("waiting", onBuffer);
2837
- player.emitter.addEventListener("resume", onResume);
2960
+ }
2838
2961
  return () => {
2839
- player.emitter.removeEventListener("waiting", onBuffer);
2840
- player.emitter.removeEventListener("resume", onResume);
2841
- setShowBufferState(false);
2842
- if (timeout) {
2962
+ unsubscribe();
2963
+ if (timeout !== null) {
2843
2964
  clearTimeout(timeout);
2844
2965
  }
2845
- stopped = true;
2966
+ setBufferIndicator({ type: "idle" });
2846
2967
  };
2847
- }, [bufferStateDelayInMilliseconds, player.emitter]);
2968
+ }, [bufferStateDelayInMilliseconds, isBuffering, subscribeBuffering]);
2848
2969
  useImperativeHandle(ref, () => {
2849
2970
  const methods = {
2850
2971
  play,
@@ -2947,32 +3068,32 @@ var PlayerUI = ({
2947
3068
  }, [config, layout, overflowVisible, scale]);
2948
3069
  const playerPause = player.pause;
2949
3070
  const playerDispatchError = player.emitter.dispatchError;
2950
- const onError = useCallback10((error) => {
3071
+ const onError = useCallback11((error) => {
2951
3072
  playerPause();
2952
3073
  playerDispatchError(error);
2953
3074
  }, [playerDispatchError, playerPause]);
2954
- const onFullscreenButtonClick = useCallback10((e) => {
3075
+ const onFullscreenButtonClick = useCallback11((e) => {
2955
3076
  e.stopPropagation();
2956
3077
  requestFullscreen();
2957
3078
  }, [requestFullscreen]);
2958
- const onExitFullscreenButtonClick = useCallback10((e) => {
3079
+ const onExitFullscreenButtonClick = useCallback11((e) => {
2959
3080
  e.stopPropagation();
2960
3081
  exitFullscreen();
2961
3082
  }, [exitFullscreen]);
2962
- const onSingleClick = useCallback10((e) => {
3083
+ const onSingleClick = useCallback11((e) => {
2963
3084
  const rightClick = e instanceof MouseEvent ? e.button === 2 : e.nativeEvent.button;
2964
3085
  if (rightClick) {
2965
3086
  return;
2966
3087
  }
2967
3088
  toggle(e);
2968
3089
  }, [toggle]);
2969
- const onSeekStart = useCallback10(() => {
3090
+ const onSeekStart = useCallback11(() => {
2970
3091
  setSeeking(true);
2971
3092
  }, []);
2972
- const onSeekEnd = useCallback10(() => {
3093
+ const onSeekEnd = useCallback11(() => {
2973
3094
  setSeeking(false);
2974
3095
  }, []);
2975
- const onDoubleClick = useCallback10(() => {
3096
+ const onDoubleClick = useCallback11(() => {
2976
3097
  if (isFullscreen) {
2977
3098
  exitFullscreen();
2978
3099
  } else {
@@ -3123,7 +3244,7 @@ var PlayerUI = ({
3123
3244
  var PlayerUI_default = forwardRef(PlayerUI);
3124
3245
 
3125
3246
  // src/SharedPlayerContext.tsx
3126
- import { useCallback as useCallback11, useMemo as useMemo13, useRef as useRef11, useState as useState11 } from "react";
3247
+ import { useCallback as useCallback12, useMemo as useMemo13, useRef as useRef11, useState as useState11 } from "react";
3127
3248
  import { Internals as Internals13 } from "remotion";
3128
3249
 
3129
3250
  // src/volume-persistence.ts
@@ -3232,7 +3353,7 @@ var SharedPlayerContexts = ({
3232
3353
  const audioContextWasCreated = useRef11(false);
3233
3354
  const shouldCreateAudioContext = audioContextWasCreated.current || audioEnabled && !playerMuted && mediaVolume > 0;
3234
3355
  audioContextWasCreated.current = shouldCreateAudioContext;
3235
- const setMediaVolumeAndPersist = useCallback11((vol) => {
3356
+ const setMediaVolumeAndPersist = useCallback12((vol) => {
3236
3357
  setMediaVolume(vol);
3237
3358
  if (persistVolumeToStorage) {
3238
3359
  persistVolume(vol, logLevel, volumePersistenceKey ?? null);
@@ -3533,8 +3654,8 @@ var PlayerFn = ({
3533
3654
  const audioAndVideoTags = useRef12([]);
3534
3655
  const playingStore = useMemo14(() => Internals15.createRuntimeValueStore({ playing: false }), []);
3535
3656
  const bufferingStore = useMemo14(() => Internals15.createRuntimeValueStore({ buffering: false }), []);
3536
- const readIsPlaying = useCallback12(() => playingStore.store.getSnapshot().playing, [playingStore]);
3537
- const readIsBuffering = useCallback12(() => bufferingStore.store.getSnapshot().buffering, [bufferingStore]);
3657
+ const readIsPlaying = useCallback13(() => playingStore.store.getSnapshot().playing, [playingStore]);
3658
+ const readIsBuffering = useCallback13(() => bufferingStore.store.getSnapshot().buffering, [bufferingStore]);
3538
3659
  const [currentPlaybackRate, setCurrentPlaybackRate] = useState12(playbackRate);
3539
3660
  if (typeof compositionHeight !== "number") {
3540
3661
  throw new TypeError(`'compositionHeight' must be a number but got '${typeof compositionHeight}' instead`);
@@ -3658,6 +3779,7 @@ var PlayerFn = ({
3658
3779
  Internals15.CSSUtils.injectCSS(Internals15.CSSUtils.makeDefaultPreviewCSS(`.${playerCssClassname(overrideInternalClassName)}`, "#fff"));
3659
3780
  }, [overrideInternalClassName]);
3660
3781
  }
3782
+ const playbackRange = useMemo14(() => ({ inFrame: inFrame ?? null, outFrame: outFrame ?? null }), [inFrame, outFrame]);
3661
3783
  const actualInputProps = useMemo14(() => inputProps ?? {}, [inputProps]);
3662
3784
  const browserMediaControlsBehavior = useMemo14(() => {
3663
3785
  return passedBrowserMediaControlsBehavior ?? {
@@ -3713,8 +3835,6 @@ var PlayerFn = ({
3713
3835
  showPosterWhenBuffering: Boolean(showPosterWhenBuffering),
3714
3836
  showPosterWhenBufferingAndPaused: Boolean(showPosterWhenBufferingAndPaused),
3715
3837
  renderPoster,
3716
- inFrame: inFrame ?? null,
3717
- outFrame: outFrame ?? null,
3718
3838
  initiallyShowControls: initiallyShowControls ?? true,
3719
3839
  renderFullscreen: renderFullscreenButton ?? null,
3720
3840
  renderPlayPauseButton: renderPlayPauseButton ?? null,
@@ -3734,19 +3854,22 @@ var PlayerFn = ({
3734
3854
  })
3735
3855
  })
3736
3856
  });
3737
- return /* @__PURE__ */ jsx14(Internals15.DefaultPremountContext.Provider, {
3738
- value: defaultPremountInSeconds,
3739
- children: onTimelineSequenceChange ? /* @__PURE__ */ jsx14(Internals15.SequenceRegistrationContext.Provider, {
3740
- value: true,
3741
- children: /* @__PURE__ */ jsxs10(Internals15.SequenceManagerProvider, {
3742
- children: [
3743
- /* @__PURE__ */ jsx14(TimelineSequenceObserverComponent, {
3744
- onTimelineSequenceChange
3745
- }),
3746
- player
3747
- ]
3748
- })
3749
- }) : player
3857
+ return /* @__PURE__ */ jsx14(PlaybackRangeContext.Provider, {
3858
+ value: playbackRange,
3859
+ children: /* @__PURE__ */ jsx14(Internals15.DefaultPremountContext.Provider, {
3860
+ value: defaultPremountInSeconds,
3861
+ children: onTimelineSequenceChange ? /* @__PURE__ */ jsx14(Internals15.SequenceRegistrationContext.Provider, {
3862
+ value: true,
3863
+ children: /* @__PURE__ */ jsxs10(Internals15.SequenceManagerProvider, {
3864
+ children: [
3865
+ /* @__PURE__ */ jsx14(TimelineSequenceObserverComponent, {
3866
+ onTimelineSequenceChange
3867
+ }),
3868
+ player
3869
+ ]
3870
+ })
3871
+ }) : player
3872
+ })
3750
3873
  });
3751
3874
  };
3752
3875
  var forward = forwardRef2;
@@ -3766,7 +3889,7 @@ import { Internals as Internals17 } from "remotion";
3766
3889
  import React14, {
3767
3890
  forwardRef as forwardRef3,
3768
3891
  Suspense as Suspense2,
3769
- useCallback as useCallback13,
3892
+ useCallback as useCallback14,
3770
3893
  useImperativeHandle as useImperativeHandle3,
3771
3894
  useMemo as useMemo16,
3772
3895
  useRef as useRef13
@@ -3854,7 +3977,7 @@ var ThumbnailUI = ({
3854
3977
  overflowVisible
3855
3978
  });
3856
3979
  }, [config, layout, overflowVisible, scale]);
3857
- const onError = useCallback13((error) => {
3980
+ const onError = useCallback14((error) => {
3858
3981
  thumbnail.emitter.dispatchError(error);
3859
3982
  }, [thumbnail.emitter]);
3860
3983
  const loadingMarkup = useMemo16(() => {
@@ -4047,6 +4170,7 @@ var PlayerInternals = {
4047
4170
  useHoverState,
4048
4171
  updateAllElementsSizes,
4049
4172
  PlayerEmitterProvider,
4173
+ PlaybackRangeContext,
4050
4174
  BufferingIndicator,
4051
4175
  PlayerControls: Controls,
4052
4176
  TimelineSequenceObserverContext,