@remotion/player 4.0.537 → 4.0.539

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.
Files changed (42) hide show
  1. package/dist/cjs/BufferingIndicator.js +3 -5
  2. package/dist/cjs/DefaultPlayPauseButton.js +3 -3
  3. package/dist/cjs/EmitterProvider.js +1 -1
  4. package/dist/cjs/MediaVolumeSlider.js +2 -2
  5. package/dist/cjs/PlaybackrateControl.js +18 -8
  6. package/dist/cjs/Player.d.ts +6 -1
  7. package/dist/cjs/Player.js +6 -4
  8. package/dist/cjs/PlayerControls.js +3 -11
  9. package/dist/cjs/PlayerSeekBar.js +1 -5
  10. package/dist/cjs/PlayerTimeLabel.js +1 -1
  11. package/dist/cjs/PlayerUI.d.ts +3 -3
  12. package/dist/cjs/PlayerUI.js +4 -7
  13. package/dist/cjs/SharedPlayerContext.d.ts +1 -0
  14. package/dist/cjs/SharedPlayerContext.js +2 -2
  15. package/dist/cjs/Thumbnail.d.ts +1 -1
  16. package/dist/cjs/Thumbnail.js +1 -1
  17. package/dist/cjs/ThumbnailUI.d.ts +1 -1
  18. package/dist/cjs/ThumbnailUI.js +3 -3
  19. package/dist/cjs/browser-mediasession.js +2 -2
  20. package/dist/cjs/calculate-scale.d.ts +11 -11
  21. package/dist/cjs/error-boundary.js +5 -2
  22. package/dist/cjs/event-emitter.js +88 -84
  23. package/dist/cjs/icons.js +9 -13
  24. package/dist/cjs/index.d.ts +14 -32
  25. package/dist/cjs/index.js +2 -2
  26. package/dist/cjs/license-blacklist.js +1 -1
  27. package/dist/cjs/player-css-classname.d.ts +1 -1
  28. package/dist/cjs/render-volume-slider.js +3 -5
  29. package/dist/cjs/set-global-time-anchor.d.ts +2 -1
  30. package/dist/cjs/timeline-imperative-context.d.ts +11 -0
  31. package/dist/cjs/timeline-imperative-context.js +76 -0
  32. package/dist/cjs/use-hover-state.d.ts +1 -1
  33. package/dist/cjs/use-playback.d.ts +2 -1
  34. package/dist/cjs/use-playback.js +48 -38
  35. package/dist/cjs/use-player-methods.js +9 -8
  36. package/dist/cjs/use-player.d.ts +21 -0
  37. package/dist/cjs/use-player.js +195 -0
  38. package/dist/cjs/use-remotion-license-acknowledge.d.ts +2 -1
  39. package/dist/cjs/utils/calculate-player-size.d.ts +4 -3
  40. package/dist/cjs/volume-persistence.d.ts +2 -1
  41. package/dist/esm/index.mjs +83 -53
  42. package/package.json +5 -5
@@ -577,6 +577,8 @@ var usePlayerMethods = () => {
577
577
  const audioTagsContext = useContext2(Internals3.SharedAudioTagsContext);
578
578
  const environment = useRemotionEnvironment();
579
579
  const video = Internals3.useVideo();
580
+ const videoId = video?.id ?? null;
581
+ const videoDurationInFrames = video?.durationInFrames ?? null;
580
582
  const config = Internals3.useUnsafeVideoConfig();
581
583
  const emitter = useContext2(PlayerEventEmitterContext);
582
584
  const playStart = useRef(0);
@@ -586,12 +588,12 @@ var usePlayerMethods = () => {
586
588
  throw new TypeError("Expected Player event emitter context");
587
589
  }
588
590
  const getCurrentFrame = useCallback(() => {
589
- if (!video) {
591
+ if (videoId === null || videoDurationInFrames === null) {
590
592
  return fallbackFrame.current ?? (typeof window === "undefined" ? 0 : window.remotion_initialFrame ?? 0);
591
593
  }
592
- const unclamped = frameRef.current[video.id] ?? (environment.isPlayer ? 0 : Internals3.Timeline.getFrameForComposition(video.id));
593
- return Internals3.Timeline.clampFrameToCompositionRange(unclamped, video.durationInFrames);
594
- }, [environment.isPlayer, frameRef, video]);
594
+ const unclamped = frameRef.current[videoId] ?? (environment.isPlayer ? 0 : Internals3.Timeline.getFrameForComposition(videoId));
595
+ return Internals3.Timeline.clampFrameToCompositionRange(unclamped, videoDurationInFrames);
596
+ }, [environment.isPlayer, frameRef, videoId, videoDurationInFrames]);
595
597
  const seek = useCallback((newFrame) => {
596
598
  const frameToSeekTo = config ? Internals3.TimelinePosition.clampFrameToCompositionRange(newFrame, config.durationInFrames) : Math.max(0, newFrame);
597
599
  fallbackFrame.current = frameToSeekTo;
@@ -667,7 +669,6 @@ var usePlayerMethods = () => {
667
669
  }
668
670
  }
669
671
  }, [config, emitter, frameRef, readIsPlaying, setPlaying, seekFrame]);
670
- const videoId = video?.id;
671
672
  const lastFrame = (config?.durationInFrames ?? 1) - 1;
672
673
  const frameBack = useCallback((frames) => {
673
674
  if (!videoId) {
@@ -822,12 +823,12 @@ var useBrowserMediaSession = ({
822
823
  });
823
824
  navigator.mediaSession.setActionHandler("seekbackward", () => {
824
825
  if (browserMediaControlsBehavior.mode === "register-media-session" && videoConfig) {
825
- seek(Math.max(0, Math.round((getCurrentFrame() - 10) * videoConfig.fps)));
826
+ seek(Math.max(0, Math.round(getCurrentFrame() - 10 * videoConfig.fps)));
826
827
  }
827
828
  });
828
829
  navigator.mediaSession.setActionHandler("seekforward", () => {
829
830
  if (browserMediaControlsBehavior.mode === "register-media-session" && videoConfig) {
830
- seek(Math.max(videoConfig.durationInFrames - 1, Math.round((getCurrentFrame() + 10) * videoConfig.fps)));
831
+ seek(Math.min(videoConfig.durationInFrames - 1, Math.round(getCurrentFrame() + 10 * videoConfig.fps)));
831
832
  }
832
833
  });
833
834
  navigator.mediaSession.setActionHandler("previoustrack", () => {
@@ -954,6 +955,9 @@ var usePlayback = ({
954
955
  muted
955
956
  }) => {
956
957
  const config = Internals6.useUnsafeVideoConfig();
958
+ const fps = config?.fps ?? null;
959
+ const durationInFrames = config?.durationInFrames ?? null;
960
+ const compositionId = config?.id ?? null;
957
961
  const frame = Internals6.Timeline.useTimelinePosition();
958
962
  const playing = Internals6.usePlaying();
959
963
  const { pause, emitter, isPlaying } = usePlayerMethods();
@@ -965,6 +969,8 @@ var usePlayback = ({
965
969
  const isBackgroundedRef = useIsBackgrounded();
966
970
  const lastTimeUpdateTimestamp = useRef4(0);
967
971
  const playbackClockRef = useRef4(null);
972
+ const previousMutedRef = useRef4(muted);
973
+ const anchoredAudioContextRef = useRef4(null);
968
974
  useBrowserMediaSession({
969
975
  browserMediaControlsBehavior,
970
976
  playbackRate,
@@ -977,7 +983,7 @@ var usePlayback = ({
977
983
  if (!sharedAudioContext.audioContext) {
978
984
  return;
979
985
  }
980
- if (!config) {
986
+ if (fps === null) {
981
987
  return;
982
988
  }
983
989
  if (muted) {
@@ -986,7 +992,7 @@ var usePlayback = ({
986
992
  const changed = setGlobalTimeAnchor({
987
993
  audioContext: sharedAudioContext.audioContext,
988
994
  audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
989
- absoluteTimeInSeconds: frame / config.fps,
995
+ absoluteTimeInSeconds: frame / fps,
990
996
  globalPlaybackRate: playbackRate,
991
997
  logLevel,
992
998
  force: false
@@ -994,13 +1000,13 @@ var usePlayback = ({
994
1000
  if (changed) {
995
1001
  sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
996
1002
  }
997
- }, [config, frame, logLevel, playbackRate, sharedAudioContext, muted]);
1003
+ }, [fps, frame, logLevel, playbackRate, sharedAudioContext, muted]);
998
1004
  useLayoutEffect2(() => {
999
1005
  const audioContext = sharedAudioContext?.audioContext;
1000
1006
  if (!audioContext) {
1001
1007
  return;
1002
1008
  }
1003
- if (!config) {
1009
+ if (fps === null) {
1004
1010
  return;
1005
1011
  }
1006
1012
  if (muted) {
@@ -1012,7 +1018,7 @@ var usePlayback = ({
1012
1018
  const changed = setGlobalTimeAnchor({
1013
1019
  audioContext,
1014
1020
  audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
1015
- absoluteTimeInSeconds: getCurrentFrame() / config.fps,
1021
+ absoluteTimeInSeconds: getCurrentFrame() / fps,
1016
1022
  globalPlaybackRate: playbackRate,
1017
1023
  logLevel,
1018
1024
  force: true
@@ -1026,16 +1032,12 @@ var usePlayback = ({
1026
1032
  return () => {
1027
1033
  audioContext?.removeEventListener("statechange", callback);
1028
1034
  };
1029
- }, [
1030
- config,
1031
- getCurrentFrame,
1032
- logLevel,
1033
- muted,
1034
- playbackRate,
1035
- sharedAudioContext
1036
- ]);
1035
+ }, [fps, getCurrentFrame, logLevel, muted, playbackRate, sharedAudioContext]);
1037
1036
  useEffect5(() => {
1038
- if (!config) {
1037
+ const wasMuted = previousMutedRef.current;
1038
+ previousMutedRef.current = muted;
1039
+ if (fps === null || durationInFrames === null || compositionId === null) {
1040
+ playbackClockRef.current = null;
1039
1041
  return;
1040
1042
  }
1041
1043
  if (!playing) {
@@ -1044,23 +1046,29 @@ var usePlayback = ({
1044
1046
  return;
1045
1047
  }
1046
1048
  const previousClock = playbackClockRef.current;
1047
- const clock = previousClock !== null && previousClock.fps === config.fps && previousClock.playbackRate === playbackRate ? previousClock : {
1049
+ const shouldRestartClock = previousClock === null || previousClock.compositionId !== compositionId || previousClock.fps !== fps || previousClock.playbackRate !== playbackRate;
1050
+ const clock = shouldRestartClock ? {
1051
+ compositionId,
1048
1052
  startedTime: performance.now(),
1049
1053
  framesAdvanced: 0,
1050
- fps: config.fps,
1054
+ fps,
1051
1055
  playbackRate
1052
- };
1056
+ } : previousClock;
1053
1057
  playbackClockRef.current = clock;
1054
1058
  if (sharedAudioContext?._experimentalKeepAudioContextAlive && sharedAudioContext.audioContext && !muted) {
1059
+ const didUnmute = wasMuted && !muted;
1060
+ const didReplaceAudioContext = anchoredAudioContextRef.current !== sharedAudioContext.audioContext;
1061
+ const shouldRescheduleAudio = shouldRestartClock || didUnmute || didReplaceAudioContext;
1055
1062
  const changed = setGlobalTimeAnchor({
1056
1063
  audioContext: sharedAudioContext.audioContext,
1057
1064
  audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
1058
- absoluteTimeInSeconds: getCurrentFrame() / config.fps,
1065
+ absoluteTimeInSeconds: getCurrentFrame() / fps,
1059
1066
  globalPlaybackRate: playbackRate,
1060
1067
  logLevel,
1061
- force: true
1068
+ force: shouldRescheduleAudio
1062
1069
  });
1063
- if (changed) {
1070
+ anchoredAudioContextRef.current = sharedAudioContext.audioContext;
1071
+ if (changed || shouldRescheduleAudio) {
1064
1072
  sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
1065
1073
  }
1066
1074
  }
@@ -1094,7 +1102,7 @@ var usePlayback = ({
1094
1102
  sharedAudioContext?.resume?.();
1095
1103
  }
1096
1104
  const time = performance.now() - clock.startedTime;
1097
- const actualLastFrame = outFrame ?? config.durationInFrames - 1;
1105
+ const actualLastFrame = outFrame ?? durationInFrames - 1;
1098
1106
  const actualFirstFrame = inFrame ?? 0;
1099
1107
  const seekRevision = seek?.revision.current ?? null;
1100
1108
  if (seekRevision !== lastSeekRevision) {
@@ -1106,7 +1114,7 @@ var usePlayback = ({
1106
1114
  time,
1107
1115
  currentFrame,
1108
1116
  playbackSpeed: playbackRate,
1109
- fps: config.fps,
1117
+ fps,
1110
1118
  actualFirstFrame,
1111
1119
  actualLastFrame,
1112
1120
  framesAdvanced: clock.framesAdvanced,
@@ -1116,7 +1124,7 @@ var usePlayback = ({
1116
1124
  const frameToDisplay = hasEnded && !moveToBeginningWhenEnded ? playbackRate > 0 ? actualLastFrame : actualFirstFrame : nextFrame;
1117
1125
  if (frameToDisplay !== currentFrame && !isBuffering()) {
1118
1126
  playbackFrame = frameToDisplay;
1119
- setFrameFromPlayback((c) => ({ ...c, [config.id]: frameToDisplay }));
1127
+ setFrameFromPlayback((c) => ({ ...c, [compositionId]: frameToDisplay }));
1120
1128
  }
1121
1129
  if (hasEnded) {
1122
1130
  stop();
@@ -1168,7 +1176,7 @@ var usePlayback = ({
1168
1176
  if (isBackgroundedRef.current) {
1169
1177
  reqAnimFrameCall = {
1170
1178
  type: "timeout",
1171
- id: setTimeout(callback, 1000 / config.fps)
1179
+ id: setTimeout(callback, 1000 / fps)
1172
1180
  };
1173
1181
  return;
1174
1182
  }
@@ -1188,7 +1196,9 @@ var usePlayback = ({
1188
1196
  stop();
1189
1197
  };
1190
1198
  }, [
1191
- config,
1199
+ compositionId,
1200
+ durationInFrames,
1201
+ fps,
1192
1202
  loop,
1193
1203
  pause,
1194
1204
  playing,
@@ -1840,8 +1850,11 @@ var PlaybackPopup = ({ setIsComponentVisible, playbackRates, canvasSize }) => {
1840
1850
  const [keyboardSelectedRate, setKeyboardSelectedRate] = useState7(playbackRate);
1841
1851
  useEffect9(() => {
1842
1852
  const listener = (e) => {
1843
- e.preventDefault();
1853
+ if (e.ctrlKey || e.metaKey || e.altKey) {
1854
+ return;
1855
+ }
1844
1856
  if (e.key === "ArrowUp") {
1857
+ e.preventDefault();
1845
1858
  const currentIndex = playbackRates.findIndex((rate) => rate === keyboardSelectedRate);
1846
1859
  if (currentIndex === 0) {
1847
1860
  return;
@@ -1852,6 +1865,7 @@ var PlaybackPopup = ({ setIsComponentVisible, playbackRates, canvasSize }) => {
1852
1865
  setKeyboardSelectedRate(playbackRates[currentIndex - 1]);
1853
1866
  }
1854
1867
  } else if (e.key === "ArrowDown") {
1868
+ e.preventDefault();
1855
1869
  const currentIndex = playbackRates.findIndex((rate) => rate === keyboardSelectedRate);
1856
1870
  if (currentIndex === playbackRates.length - 1) {
1857
1871
  return;
@@ -1862,8 +1876,14 @@ var PlaybackPopup = ({ setIsComponentVisible, playbackRates, canvasSize }) => {
1862
1876
  setKeyboardSelectedRate(playbackRates[currentIndex + 1]);
1863
1877
  }
1864
1878
  } else if (e.key === "Enter") {
1879
+ e.preventDefault();
1865
1880
  setPlaybackRate(keyboardSelectedRate);
1866
1881
  setIsComponentVisible(false);
1882
+ } else if (e.key === "Escape") {
1883
+ e.preventDefault();
1884
+ setIsComponentVisible(false);
1885
+ } else if (e.key === "Tab") {
1886
+ setIsComponentVisible(false);
1867
1887
  }
1868
1888
  };
1869
1889
  window.addEventListener("keydown", listener);
@@ -3130,6 +3150,7 @@ var SharedPlayerContexts = ({
3130
3150
  children,
3131
3151
  timelineContext,
3132
3152
  playbackRateContext,
3153
+ preservePitch,
3133
3154
  fps,
3134
3155
  compositionHeight,
3135
3156
  compositionWidth,
@@ -3238,26 +3259,29 @@ var SharedPlayerContexts = ({
3238
3259
  value: timelineContext,
3239
3260
  children: /* @__PURE__ */ jsx13(Internals13.PlaybackRateContext.Provider, {
3240
3261
  value: playbackRateContext,
3241
- children: /* @__PURE__ */ jsx13(Internals13.TimelineContext.Provider, {
3242
- value: timelineContext,
3243
- children: /* @__PURE__ */ jsx13(Internals13.CompositionManager.Provider, {
3244
- value: compositionManagerContext,
3245
- children: /* @__PURE__ */ jsx13(Internals13.VideoProvider, {
3246
- children: /* @__PURE__ */ jsx13(Internals13.PrefetchProvider, {
3247
- children: /* @__PURE__ */ jsx13(Internals13.DurationsContextProvider, {
3248
- children: /* @__PURE__ */ jsx13(Internals13.MediaVolumeContext.Provider, {
3249
- value: mediaVolumeContextValue,
3250
- children: /* @__PURE__ */ jsx13(Internals13.SetMediaVolumeContext.Provider, {
3251
- value: setMediaVolumeContextValue,
3252
- children: /* @__PURE__ */ jsx13(Internals13.BufferingProvider, {
3253
- children: /* @__PURE__ */ jsx13(Internals13.SharedAudioContextProvider, {
3254
- audioLatencyHint,
3255
- audioEnabled: shouldCreateAudioContext,
3256
- previewSampleRate: sampleRate,
3257
- _experimentalKeepAudioContextAlive,
3258
- children: /* @__PURE__ */ jsx13(Internals13.SharedAudioTagsContextProvider, {
3259
- numberOfAudioTags: numberOfSharedAudioTags,
3260
- children
3262
+ children: /* @__PURE__ */ jsx13(Internals13.PlaybackPitchContext.Provider, {
3263
+ value: preservePitch,
3264
+ children: /* @__PURE__ */ jsx13(Internals13.TimelineContext.Provider, {
3265
+ value: timelineContext,
3266
+ children: /* @__PURE__ */ jsx13(Internals13.CompositionManager.Provider, {
3267
+ value: compositionManagerContext,
3268
+ children: /* @__PURE__ */ jsx13(Internals13.VideoProvider, {
3269
+ children: /* @__PURE__ */ jsx13(Internals13.PrefetchProvider, {
3270
+ children: /* @__PURE__ */ jsx13(Internals13.DurationsContextProvider, {
3271
+ children: /* @__PURE__ */ jsx13(Internals13.MediaVolumeContext.Provider, {
3272
+ value: mediaVolumeContextValue,
3273
+ children: /* @__PURE__ */ jsx13(Internals13.SetMediaVolumeContext.Provider, {
3274
+ value: setMediaVolumeContextValue,
3275
+ children: /* @__PURE__ */ jsx13(Internals13.BufferingProvider, {
3276
+ children: /* @__PURE__ */ jsx13(Internals13.SharedAudioContextProvider, {
3277
+ audioLatencyHint,
3278
+ audioEnabled: shouldCreateAudioContext,
3279
+ previewSampleRate: sampleRate,
3280
+ _experimentalKeepAudioContextAlive,
3281
+ children: /* @__PURE__ */ jsx13(Internals13.SharedAudioTagsContextProvider, {
3282
+ numberOfAudioTags: numberOfSharedAudioTags,
3283
+ children
3284
+ })
3261
3285
  })
3262
3286
  })
3263
3287
  })
@@ -3426,6 +3450,7 @@ var PlayerFn = ({
3426
3450
  numberOfSharedAudioTags = NoReactInternals2.ENABLE_V5_BREAKING_CHANGES ? 0 : 5,
3427
3451
  errorFallback = () => "⚠️",
3428
3452
  playbackRate = 1,
3453
+ preservePitch = false,
3429
3454
  renderLoading,
3430
3455
  className,
3431
3456
  showPosterWhenUnplayed,
@@ -3520,6 +3545,9 @@ var PlayerFn = ({
3520
3545
  if (typeof controls !== "boolean" && typeof controls !== "undefined") {
3521
3546
  throw new TypeError(`'controls' must be a boolean or undefined but got '${typeof controls}' instead`);
3522
3547
  }
3548
+ if (typeof preservePitch !== "boolean") {
3549
+ throw new TypeError(`'preservePitch' must be a boolean but got '${typeof preservePitch}' instead`);
3550
+ }
3523
3551
  if (typeof autoPlay !== "boolean" && typeof autoPlay !== "undefined") {
3524
3552
  throw new TypeError(`'autoPlay' must be a boolean or undefined but got '${typeof autoPlay}' instead`);
3525
3553
  }
@@ -3629,6 +3657,7 @@ var PlayerFn = ({
3629
3657
  children: /* @__PURE__ */ jsx14(SharedPlayerContexts, {
3630
3658
  timelineContext: timelineContextValue,
3631
3659
  playbackRateContext: playbackRateContextValue,
3660
+ preservePitch,
3632
3661
  component,
3633
3662
  compositionHeight,
3634
3663
  compositionWidth,
@@ -3956,6 +3985,7 @@ var ThumbnailFn = ({
3956
3985
  children: /* @__PURE__ */ jsx16(SharedPlayerContexts, {
3957
3986
  timelineContext: timelineState,
3958
3987
  playbackRateContext,
3988
+ preservePitch: false,
3959
3989
  component: Component,
3960
3990
  compositionHeight,
3961
3991
  compositionWidth,
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.537",
6
+ "version": "4.0.539",
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",
@@ -12,7 +12,7 @@
12
12
  "formatting": "oxfmt src --check",
13
13
  "format": "oxfmt src",
14
14
  "lint": "eslint src",
15
- "make": "tsgo -d && bun ensure-correct-version.ts && bun --env-file=../.env.bundle bundle.ts",
15
+ "make": "tsc -d && bun ensure-correct-version.ts && bun --env-file=../.env.bundle bundle.ts",
16
16
  "test": "bun test src",
17
17
  "prerelease": "cp ../../README.md . && cp ../../LICENSE.md ."
18
18
  },
@@ -35,7 +35,7 @@
35
35
  ],
36
36
  "license": "SEE LICENSE IN LICENSE.md",
37
37
  "dependencies": {
38
- "remotion": "4.0.537"
38
+ "remotion": "4.0.539"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.8.0",
@@ -49,9 +49,9 @@
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.537",
52
+ "@remotion/eslint-config-internal": "4.0.539",
53
53
  "eslint": "9.19.0",
54
- "@typescript/native-preview": "7.0.0-dev.20260217.1"
54
+ "typescript": "7.1.0-beta"
55
55
  },
56
56
  "keywords": [
57
57
  "remotion",