@remotion/player 4.0.542 → 4.0.544

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
@@ -2064,12 +2075,12 @@ var setGlobalTimeAnchor = ({
2064
2075
 
2065
2076
  // src/use-playback.ts
2066
2077
  var shouldForceAnchorChange = (newState) => {
2067
- if (newState === "suspended" || newState === "running-to-suspended") {
2068
- return true;
2069
- }
2070
- if (newState === "closed" || newState === "interrupted" || newState === "running" || newState === "suspended-to-running") {
2078
+ if (newState === "closed") {
2071
2079
  return false;
2072
2080
  }
2081
+ if (newState === "suspended" || newState === "running-to-suspended" || newState === "interrupted" || newState === "running" || newState === "suspended-to-running") {
2082
+ return true;
2083
+ }
2073
2084
  throw new Error(`Unexpected audio context state: ${newState}`);
2074
2085
  };
2075
2086
  var usePlayback = ({
@@ -2096,39 +2107,103 @@ var usePlayback = ({
2096
2107
  const logLevel = Internals10.useLogLevel();
2097
2108
  const isBackgroundedRef = useIsBackgrounded();
2098
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;
2099
2114
  const playbackClockRef = useRef8(null);
2100
- const previousMutedRef = useRef8(muted);
2101
- const anchoredAudioContextRef = useRef8(null);
2115
+ const previousAudioBoundary = useRef8(null);
2102
2116
  useBrowserMediaSession({
2103
2117
  browserMediaControlsBehavior,
2104
2118
  playbackRate,
2105
2119
  videoConfig: config
2106
2120
  });
2107
- useLayoutEffect2(() => {
2108
- if (!sharedAudioContext) {
2109
- return;
2110
- }
2111
- if (!sharedAudioContext.audioContext) {
2112
- return;
2113
- }
2114
- if (fps === null) {
2115
- return;
2121
+ const updateAudioAnchor = useCallback8(() => {
2122
+ if (!sharedAudioContext?.audioContext || fps === null || muted) {
2123
+ return false;
2116
2124
  }
2117
- if (muted) {
2118
- 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;
2119
2141
  }
2120
2142
  const changed = setGlobalTimeAnchor({
2121
2143
  audioContext: sharedAudioContext.audioContext,
2122
2144
  audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
2123
- absoluteTimeInSeconds: frame / fps,
2145
+ absoluteTimeInSeconds: absoluteFrame / fps,
2124
2146
  globalPlaybackRate: playbackRate,
2125
2147
  logLevel,
2126
- force: false
2148
+ force: true
2127
2149
  });
2128
2150
  if (changed) {
2129
2151
  sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
2130
2152
  }
2131
- }, [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
+ ]);
2132
2207
  useLayoutEffect2(() => {
2133
2208
  const audioContext = sharedAudioContext?.audioContext;
2134
2209
  if (!audioContext) {
@@ -2142,28 +2217,19 @@ var usePlayback = ({
2142
2217
  }
2143
2218
  const callback = () => {
2144
2219
  const newState = sharedAudioContext?.getAudioContextState();
2220
+ if (newState === "running" && sharedAudioContext?.getIsResumingAudioContext()) {
2221
+ return;
2222
+ }
2145
2223
  if (newState && shouldForceAnchorChange(newState)) {
2146
- const changed = setGlobalTimeAnchor({
2147
- audioContext,
2148
- audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
2149
- absoluteTimeInSeconds: getCurrentFrame() / fps,
2150
- globalPlaybackRate: playbackRate,
2151
- logLevel,
2152
- force: true
2153
- });
2154
- if (changed) {
2155
- sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
2156
- }
2224
+ updateAudioAnchor();
2157
2225
  }
2158
2226
  };
2159
2227
  audioContext?.addEventListener("statechange", callback);
2160
2228
  return () => {
2161
2229
  audioContext?.removeEventListener("statechange", callback);
2162
2230
  };
2163
- }, [fps, getCurrentFrame, logLevel, muted, playbackRate, sharedAudioContext]);
2231
+ }, [fps, getCurrentFrame, muted, sharedAudioContext, updateAudioAnchor]);
2164
2232
  useEffect10(() => {
2165
- const wasMuted = previousMutedRef.current;
2166
- previousMutedRef.current = muted;
2167
2233
  if (fps === null || durationInFrames === null || compositionId === null) {
2168
2234
  playbackClockRef.current = null;
2169
2235
  return;
@@ -2182,32 +2248,16 @@ var usePlayback = ({
2182
2248
  compositionId,
2183
2249
  startedTime: performance.now(),
2184
2250
  framesAdvanced: 0,
2251
+ frame: getCurrentFrame(),
2252
+ seekRevision: seek?.revision.current ?? null,
2185
2253
  fps,
2186
2254
  playbackRate
2187
2255
  } : previousClock;
2256
+ clock.frame = Internals10.Timeline.clampFrameToCompositionRange(clock.frame, durationInFrames);
2188
2257
  playbackClockRef.current = clock;
2189
- if (sharedAudioContext?._experimentalKeepAudioContextAlive && sharedAudioContext.audioContext && !muted) {
2190
- const didUnmute = wasMuted && !muted;
2191
- const didReplaceAudioContext = anchoredAudioContextRef.current !== sharedAudioContext.audioContext;
2192
- const shouldRescheduleAudio = shouldRestartClock || didUnmute || didReplaceAudioContext;
2193
- const changed = setGlobalTimeAnchor({
2194
- audioContext: sharedAudioContext.audioContext,
2195
- audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
2196
- absoluteTimeInSeconds: getCurrentFrame() / fps,
2197
- globalPlaybackRate: playbackRate,
2198
- logLevel,
2199
- force: shouldRescheduleAudio
2200
- });
2201
- anchoredAudioContextRef.current = sharedAudioContext.audioContext;
2202
- if (changed || shouldRescheduleAudio) {
2203
- sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
2204
- }
2205
- }
2206
2258
  let hasBeenStopped = false;
2207
2259
  let audioContextFailed = false;
2208
2260
  let reqAnimFrameCall = null;
2209
- let playbackFrame = getCurrentFrame();
2210
- let lastSeekRevision = seek?.revision.current ?? null;
2211
2261
  let unsubscribeBuffering = null;
2212
2262
  const cancelQueuedFrame = () => {
2213
2263
  if (reqAnimFrameCall !== null) {
@@ -2245,11 +2295,18 @@ var usePlayback = ({
2245
2295
  const actualLastFrame = outFrame ?? durationInFrames - 1;
2246
2296
  const actualFirstFrame = inFrame ?? 0;
2247
2297
  const seekRevision = seek?.revision.current ?? null;
2248
- if (seekRevision !== lastSeekRevision) {
2249
- playbackFrame = getCurrentFrame();
2250
- 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
+ }
2251
2308
  }
2252
- const currentFrame = playbackFrame;
2309
+ const currentFrame = clock.frame;
2253
2310
  const { nextFrame, framesToAdvance, hasEnded } = calculateNextFrame({
2254
2311
  time,
2255
2312
  currentFrame,
@@ -2262,9 +2319,18 @@ var usePlayback = ({
2262
2319
  });
2263
2320
  clock.framesAdvanced += framesToAdvance;
2264
2321
  const frameToDisplay = hasEnded && !moveToBeginningWhenEnded ? playbackRate > 0 ? actualLastFrame : actualFirstFrame : nextFrame;
2322
+ const didJump = frameToDisplay !== currentFrame + framesToAdvance;
2323
+ if (didJump) {
2324
+ playbackJumpRevision.current++;
2325
+ }
2326
+ clock.frame = frameToDisplay;
2265
2327
  if (frameToDisplay !== currentFrame) {
2266
- playbackFrame = frameToDisplay;
2267
2328
  setFrameFromPlayback((c) => ({ ...c, [compositionId]: frameToDisplay }));
2329
+ } else if (didJump) {
2330
+ updateAudioAnchor();
2331
+ if (previousAudioBoundary.current !== null) {
2332
+ previousAudioBoundary.current.jumpRevision = playbackJumpRevision.current;
2333
+ }
2268
2334
  }
2269
2335
  if (hasEnded) {
2270
2336
  stop();
@@ -2308,11 +2374,12 @@ var usePlayback = ({
2308
2374
  if (hasBeenStopped) {
2309
2375
  return;
2310
2376
  }
2377
+ clock.startedTime = performance.now();
2378
+ clock.framesAdvanced = 0;
2379
+ updateAudioAnchor();
2311
2380
  if (!muted && !audioContextFailed && sharedAudioContext?._experimentalKeepAudioContextAlive) {
2312
2381
  sharedAudioContext.resume();
2313
2382
  }
2314
- clock.startedTime = performance.now();
2315
- clock.framesAdvanced = 0;
2316
2383
  queueNextFrame();
2317
2384
  });
2318
2385
  return;
@@ -2365,8 +2432,8 @@ var usePlayback = ({
2365
2432
  setPlayerMuted,
2366
2433
  subscribeBuffering,
2367
2434
  seek,
2368
- logLevel,
2369
- muted
2435
+ muted,
2436
+ updateAudioAnchor
2370
2437
  ]);
2371
2438
  useEffect10(() => {
2372
2439
  const now = performance.now();
@@ -2390,7 +2457,7 @@ var usePlayback = ({
2390
2457
  // src/Player.tsx
2391
2458
  import React13, {
2392
2459
  forwardRef as forwardRef2,
2393
- useCallback as useCallback12,
2460
+ useCallback as useCallback13,
2394
2461
  useEffect as useEffect13,
2395
2462
  useImperativeHandle as useImperativeHandle2,
2396
2463
  useLayoutEffect as useLayoutEffect3,
@@ -2410,7 +2477,7 @@ var playerCssClassname = (override) => {
2410
2477
  import React11, {
2411
2478
  Suspense,
2412
2479
  forwardRef,
2413
- useCallback as useCallback10,
2480
+ useCallback as useCallback11,
2414
2481
  useContext as useContext4,
2415
2482
  useEffect as useEffect12,
2416
2483
  useImperativeHandle,
@@ -2420,6 +2487,29 @@ import React11, {
2420
2487
  } from "react";
2421
2488
  import { Internals as Internals11 } from "remotion";
2422
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
+
2423
2513
  // src/error-boundary.tsx
2424
2514
  import React9 from "react";
2425
2515
  import { jsx as jsx10 } from "react/jsx-runtime";
@@ -2546,7 +2636,7 @@ var RenderWarningIfBlacklist = () => {
2546
2636
  var IS_NODE = typeof document === "undefined";
2547
2637
 
2548
2638
  // src/utils/use-click-prevention-on-double-click.ts
2549
- import { useCallback as useCallback9, useMemo as useMemo11 } from "react";
2639
+ import { useCallback as useCallback10, useMemo as useMemo11 } from "react";
2550
2640
 
2551
2641
  // src/utils/cancellable-promise.ts
2552
2642
  var cancellablePromise = (promise) => {
@@ -2574,16 +2664,16 @@ var cancellablePromise = (promise) => {
2574
2664
  var delay = (n) => new Promise((resolve) => setTimeout(resolve, n));
2575
2665
 
2576
2666
  // src/utils/use-cancellable-promises.ts
2577
- 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";
2578
2668
  var useCancellablePromises = () => {
2579
2669
  const pendingPromises = useRef9([]);
2580
- const appendPendingPromise = useCallback8((promise) => {
2670
+ const appendPendingPromise = useCallback9((promise) => {
2581
2671
  pendingPromises.current = [...pendingPromises.current, promise];
2582
2672
  }, []);
2583
- const removePendingPromise = useCallback8((promise) => {
2673
+ const removePendingPromise = useCallback9((promise) => {
2584
2674
  pendingPromises.current = pendingPromises.current.filter((p) => p !== promise);
2585
2675
  }, []);
2586
- const clearPendingPromises = useCallback8(() => pendingPromises.current.map((p) => p.cancel()), []);
2676
+ const clearPendingPromises = useCallback9(() => pendingPromises.current.map((p) => p.cancel()), []);
2587
2677
  const api = useMemo10(() => ({
2588
2678
  appendPendingPromise,
2589
2679
  removePendingPromise,
@@ -2595,7 +2685,7 @@ var useCancellablePromises = () => {
2595
2685
  // src/utils/use-click-prevention-on-double-click.ts
2596
2686
  var useClickPreventionOnDoubleClick = (onClick, onDoubleClick, doubleClickToFullscreen) => {
2597
2687
  const api = useCancellablePromises();
2598
- const handleClick = useCallback9(async (e) => {
2688
+ const handleClick = useCallback10(async (e) => {
2599
2689
  if (e instanceof PointerEvent ? e.pointerType === "touch" : e.nativeEvent.pointerType === "touch") {
2600
2690
  onClick(e);
2601
2691
  return;
@@ -2615,14 +2705,14 @@ var useClickPreventionOnDoubleClick = (onClick, onDoubleClick, doubleClickToFull
2615
2705
  }
2616
2706
  }
2617
2707
  }, [api, onClick]);
2618
- const handlePointerDown = useCallback9(() => {
2708
+ const handlePointerDown = useCallback10(() => {
2619
2709
  document.addEventListener("pointerup", (newEvt) => {
2620
2710
  handleClick(newEvt);
2621
2711
  }, {
2622
2712
  once: true
2623
2713
  });
2624
2714
  }, [handleClick]);
2625
- const handleDoubleClick = useCallback9(() => {
2715
+ const handleDoubleClick = useCallback10(() => {
2626
2716
  api.clearPendingPromises();
2627
2717
  onDoubleClick();
2628
2718
  }, [api, onDoubleClick]);
@@ -2666,8 +2756,6 @@ var PlayerUI = ({
2666
2756
  showPosterWhenPaused,
2667
2757
  showPosterWhenBuffering,
2668
2758
  showPosterWhenBufferingAndPaused,
2669
- inFrame,
2670
- outFrame,
2671
2759
  initiallyShowControls,
2672
2760
  renderFullscreen: renderFullscreenButton,
2673
2761
  renderPlayPauseButton,
@@ -2684,6 +2772,7 @@ var PlayerUI = ({
2684
2772
  overrideInternalClassName,
2685
2773
  noSuspense
2686
2774
  }, ref) => {
2775
+ const { inFrame, outFrame } = useContext4(PlaybackRangeContext);
2687
2776
  const config = Internals11.useUnsafeVideoConfig();
2688
2777
  const video = Internals11.useVideo();
2689
2778
  const container = useRef10(null);
@@ -2705,7 +2794,7 @@ var PlayerUI = ({
2705
2794
  const player = usePlayerMethods();
2706
2795
  const playing = Internals11.usePlaying();
2707
2796
  const frame = Internals11.Timeline.useTimelinePosition();
2708
- const play = useCallback10((e) => {
2797
+ const play = useCallback11((e) => {
2709
2798
  if (player.isPlaying()) {
2710
2799
  return;
2711
2800
  }
@@ -2757,14 +2846,14 @@ var PlayerUI = ({
2757
2846
  document.removeEventListener("webkitfullscreenchange", onFullscreenChange);
2758
2847
  };
2759
2848
  }, []);
2760
- const toggle = useCallback10((e) => {
2849
+ const toggle = useCallback11((e) => {
2761
2850
  if (player.isPlaying()) {
2762
2851
  player.pause();
2763
2852
  } else {
2764
2853
  play(e);
2765
2854
  }
2766
2855
  }, [play, player]);
2767
- const requestFullscreen = useCallback10(() => {
2856
+ const requestFullscreen = useCallback11(() => {
2768
2857
  if (!allowFullscreen) {
2769
2858
  throw new Error("allowFullscreen is false");
2770
2859
  }
@@ -2780,7 +2869,7 @@ var PlayerUI = ({
2780
2869
  container.current.requestFullscreen();
2781
2870
  }
2782
2871
  }, [allowFullscreen, supportsFullScreen]);
2783
- const exitFullscreen = useCallback10(() => {
2872
+ const exitFullscreen = useCallback11(() => {
2784
2873
  if (document.webkitExitFullscreen) {
2785
2874
  document.webkitExitFullscreen();
2786
2875
  } else {
@@ -2833,45 +2922,50 @@ var PlayerUI = ({
2833
2922
  }
2834
2923
  player.emitter.dispatchScaleChange(scale);
2835
2924
  }, [player.emitter, scale]);
2836
- 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";
2837
2930
  useEffect12(() => {
2931
+ let current = { type: "idle" };
2838
2932
  let timeout = null;
2839
- let stopped = false;
2840
- const onBuffer = () => {
2841
- stopped = false;
2842
- requestAnimationFrame(() => {
2843
- if (bufferStateDelayInMilliseconds === 0) {
2844
- setShowBufferState(true);
2845
- } else {
2846
- timeout = setTimeout(() => {
2847
- if (!stopped) {
2848
- setShowBufferState(true);
2849
- }
2850
- }, bufferStateDelayInMilliseconds);
2851
- }
2852
- });
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
+ }
2853
2948
  };
2854
- const onResume = () => {
2855
- requestAnimationFrame(() => {
2856
- stopped = true;
2857
- setShowBufferState(false);
2858
- if (timeout) {
2859
- clearTimeout(timeout);
2860
- }
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
2861
2959
  });
2862
- };
2863
- player.emitter.addEventListener("waiting", onBuffer);
2864
- player.emitter.addEventListener("resume", onResume);
2960
+ }
2865
2961
  return () => {
2866
- player.emitter.removeEventListener("waiting", onBuffer);
2867
- player.emitter.removeEventListener("resume", onResume);
2868
- setShowBufferState(false);
2869
- if (timeout) {
2962
+ unsubscribe();
2963
+ if (timeout !== null) {
2870
2964
  clearTimeout(timeout);
2871
2965
  }
2872
- stopped = true;
2966
+ setBufferIndicator({ type: "idle" });
2873
2967
  };
2874
- }, [bufferStateDelayInMilliseconds, player.emitter]);
2968
+ }, [bufferStateDelayInMilliseconds, isBuffering, subscribeBuffering]);
2875
2969
  useImperativeHandle(ref, () => {
2876
2970
  const methods = {
2877
2971
  play,
@@ -2974,32 +3068,32 @@ var PlayerUI = ({
2974
3068
  }, [config, layout, overflowVisible, scale]);
2975
3069
  const playerPause = player.pause;
2976
3070
  const playerDispatchError = player.emitter.dispatchError;
2977
- const onError = useCallback10((error) => {
3071
+ const onError = useCallback11((error) => {
2978
3072
  playerPause();
2979
3073
  playerDispatchError(error);
2980
3074
  }, [playerDispatchError, playerPause]);
2981
- const onFullscreenButtonClick = useCallback10((e) => {
3075
+ const onFullscreenButtonClick = useCallback11((e) => {
2982
3076
  e.stopPropagation();
2983
3077
  requestFullscreen();
2984
3078
  }, [requestFullscreen]);
2985
- const onExitFullscreenButtonClick = useCallback10((e) => {
3079
+ const onExitFullscreenButtonClick = useCallback11((e) => {
2986
3080
  e.stopPropagation();
2987
3081
  exitFullscreen();
2988
3082
  }, [exitFullscreen]);
2989
- const onSingleClick = useCallback10((e) => {
3083
+ const onSingleClick = useCallback11((e) => {
2990
3084
  const rightClick = e instanceof MouseEvent ? e.button === 2 : e.nativeEvent.button;
2991
3085
  if (rightClick) {
2992
3086
  return;
2993
3087
  }
2994
3088
  toggle(e);
2995
3089
  }, [toggle]);
2996
- const onSeekStart = useCallback10(() => {
3090
+ const onSeekStart = useCallback11(() => {
2997
3091
  setSeeking(true);
2998
3092
  }, []);
2999
- const onSeekEnd = useCallback10(() => {
3093
+ const onSeekEnd = useCallback11(() => {
3000
3094
  setSeeking(false);
3001
3095
  }, []);
3002
- const onDoubleClick = useCallback10(() => {
3096
+ const onDoubleClick = useCallback11(() => {
3003
3097
  if (isFullscreen) {
3004
3098
  exitFullscreen();
3005
3099
  } else {
@@ -3150,7 +3244,7 @@ var PlayerUI = ({
3150
3244
  var PlayerUI_default = forwardRef(PlayerUI);
3151
3245
 
3152
3246
  // src/SharedPlayerContext.tsx
3153
- 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";
3154
3248
  import { Internals as Internals13 } from "remotion";
3155
3249
 
3156
3250
  // src/volume-persistence.ts
@@ -3259,7 +3353,7 @@ var SharedPlayerContexts = ({
3259
3353
  const audioContextWasCreated = useRef11(false);
3260
3354
  const shouldCreateAudioContext = audioContextWasCreated.current || audioEnabled && !playerMuted && mediaVolume > 0;
3261
3355
  audioContextWasCreated.current = shouldCreateAudioContext;
3262
- const setMediaVolumeAndPersist = useCallback11((vol) => {
3356
+ const setMediaVolumeAndPersist = useCallback12((vol) => {
3263
3357
  setMediaVolume(vol);
3264
3358
  if (persistVolumeToStorage) {
3265
3359
  persistVolume(vol, logLevel, volumePersistenceKey ?? null);
@@ -3560,8 +3654,8 @@ var PlayerFn = ({
3560
3654
  const audioAndVideoTags = useRef12([]);
3561
3655
  const playingStore = useMemo14(() => Internals15.createRuntimeValueStore({ playing: false }), []);
3562
3656
  const bufferingStore = useMemo14(() => Internals15.createRuntimeValueStore({ buffering: false }), []);
3563
- const readIsPlaying = useCallback12(() => playingStore.store.getSnapshot().playing, [playingStore]);
3564
- 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]);
3565
3659
  const [currentPlaybackRate, setCurrentPlaybackRate] = useState12(playbackRate);
3566
3660
  if (typeof compositionHeight !== "number") {
3567
3661
  throw new TypeError(`'compositionHeight' must be a number but got '${typeof compositionHeight}' instead`);
@@ -3685,6 +3779,7 @@ var PlayerFn = ({
3685
3779
  Internals15.CSSUtils.injectCSS(Internals15.CSSUtils.makeDefaultPreviewCSS(`.${playerCssClassname(overrideInternalClassName)}`, "#fff"));
3686
3780
  }, [overrideInternalClassName]);
3687
3781
  }
3782
+ const playbackRange = useMemo14(() => ({ inFrame: inFrame ?? null, outFrame: outFrame ?? null }), [inFrame, outFrame]);
3688
3783
  const actualInputProps = useMemo14(() => inputProps ?? {}, [inputProps]);
3689
3784
  const browserMediaControlsBehavior = useMemo14(() => {
3690
3785
  return passedBrowserMediaControlsBehavior ?? {
@@ -3740,8 +3835,6 @@ var PlayerFn = ({
3740
3835
  showPosterWhenBuffering: Boolean(showPosterWhenBuffering),
3741
3836
  showPosterWhenBufferingAndPaused: Boolean(showPosterWhenBufferingAndPaused),
3742
3837
  renderPoster,
3743
- inFrame: inFrame ?? null,
3744
- outFrame: outFrame ?? null,
3745
3838
  initiallyShowControls: initiallyShowControls ?? true,
3746
3839
  renderFullscreen: renderFullscreenButton ?? null,
3747
3840
  renderPlayPauseButton: renderPlayPauseButton ?? null,
@@ -3761,19 +3854,22 @@ var PlayerFn = ({
3761
3854
  })
3762
3855
  })
3763
3856
  });
3764
- return /* @__PURE__ */ jsx14(Internals15.DefaultPremountContext.Provider, {
3765
- value: defaultPremountInSeconds,
3766
- children: onTimelineSequenceChange ? /* @__PURE__ */ jsx14(Internals15.SequenceRegistrationContext.Provider, {
3767
- value: true,
3768
- children: /* @__PURE__ */ jsxs10(Internals15.SequenceManagerProvider, {
3769
- children: [
3770
- /* @__PURE__ */ jsx14(TimelineSequenceObserverComponent, {
3771
- onTimelineSequenceChange
3772
- }),
3773
- player
3774
- ]
3775
- })
3776
- }) : 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
+ })
3777
3873
  });
3778
3874
  };
3779
3875
  var forward = forwardRef2;
@@ -3793,7 +3889,7 @@ import { Internals as Internals17 } from "remotion";
3793
3889
  import React14, {
3794
3890
  forwardRef as forwardRef3,
3795
3891
  Suspense as Suspense2,
3796
- useCallback as useCallback13,
3892
+ useCallback as useCallback14,
3797
3893
  useImperativeHandle as useImperativeHandle3,
3798
3894
  useMemo as useMemo16,
3799
3895
  useRef as useRef13
@@ -3881,7 +3977,7 @@ var ThumbnailUI = ({
3881
3977
  overflowVisible
3882
3978
  });
3883
3979
  }, [config, layout, overflowVisible, scale]);
3884
- const onError = useCallback13((error) => {
3980
+ const onError = useCallback14((error) => {
3885
3981
  thumbnail.emitter.dispatchError(error);
3886
3982
  }, [thumbnail.emitter]);
3887
3983
  const loadingMarkup = useMemo16(() => {
@@ -4074,6 +4170,7 @@ var PlayerInternals = {
4074
4170
  useHoverState,
4075
4171
  updateAllElementsSizes,
4076
4172
  PlayerEmitterProvider,
4173
+ PlaybackRangeContext,
4077
4174
  BufferingIndicator,
4078
4175
  PlayerControls: Controls,
4079
4176
  TimelineSequenceObserverContext,