@remotion/player 4.0.465 → 4.0.467

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,7 +5,7 @@ const remotion_1 = require("remotion");
5
5
  exports.ALLOWED_GLOBAL_TIME_ANCHOR_SHIFT = 0.1;
6
6
  const setGlobalTimeAnchor = ({ audioContext, audioSyncAnchor, absoluteTimeInSeconds, globalPlaybackRate, logLevel, force, }) => {
7
7
  const newAnchor = audioContext.currentTime - absoluteTimeInSeconds / globalPlaybackRate;
8
- const shift = (newAnchor - audioSyncAnchor.value) * globalPlaybackRate;
8
+ const shift = newAnchor - audioSyncAnchor.value;
9
9
  const { outputLatency } = audioContext;
10
10
  const safeOutputLatency = outputLatency === 0 ? 0.3 : outputLatency;
11
11
  const latency = audioContext.baseLatency + safeOutputLatency;
@@ -13,6 +13,10 @@ const setGlobalTimeAnchor = ({ audioContext, audioSyncAnchor, absoluteTimeInSeco
13
13
  if (Math.abs(shift) < exports.ALLOWED_GLOBAL_TIME_ANCHOR_SHIFT + latency && !force) {
14
14
  return false;
15
15
  }
16
+ // If force is true, but shift is zero, no change is needed
17
+ if (Math.abs(shift) < Number.EPSILON) {
18
+ return false;
19
+ }
16
20
  remotion_1.Internals.Log.verbose({ logLevel, tag: 'audio-scheduling' }, 'Anchor ' +
17
21
  (force ? 'forcibly ' : '') +
18
22
  'changed from %s to %s with shift %s', audioSyncAnchor.value, newAnchor, shift);
@@ -10,6 +10,18 @@ const calculate_next_frame_js_1 = require("./calculate-next-frame.js");
10
10
  const is_backgrounded_js_1 = require("./is-backgrounded.js");
11
11
  const set_global_time_anchor_js_1 = require("./set-global-time-anchor.js");
12
12
  const use_player_js_1 = require("./use-player.js");
13
+ const shouldForceAnchorChange = (newState) => {
14
+ if (newState === 'suspended' || newState === 'running-to-suspended') {
15
+ return true;
16
+ }
17
+ if (newState === 'closed' ||
18
+ newState === 'interrupted' ||
19
+ newState === 'running' ||
20
+ newState === 'suspended-to-running') {
21
+ return false;
22
+ }
23
+ throw new Error(`Unexpected audio context state: ${newState}`);
24
+ };
13
25
  const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, outFrame, browserMediaControlsBehavior, getCurrentFrame, muted, }) => {
14
26
  const config = remotion_1.Internals.useUnsafeVideoConfig();
15
27
  const frame = remotion_1.Internals.Timeline.useTimelinePosition();
@@ -72,7 +84,8 @@ const usePlayback = ({ loop, playbackRate, moveToBeginningWhenEnded, inFrame, ou
72
84
  return;
73
85
  }
74
86
  const callback = () => {
75
- if (audioContext.state !== 'running') {
87
+ const newState = sharedAudioContext === null || sharedAudioContext === void 0 ? void 0 : sharedAudioContext.getAudioContextState();
88
+ if (newState && shouldForceAnchorChange(newState)) {
76
89
  (0, set_global_time_anchor_js_1.setGlobalTimeAnchor)({
77
90
  audioContext,
78
91
  audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
@@ -921,19 +921,31 @@ var setGlobalTimeAnchor = ({
921
921
  force
922
922
  }) => {
923
923
  const newAnchor = audioContext.currentTime - absoluteTimeInSeconds / globalPlaybackRate;
924
- const shift = (newAnchor - audioSyncAnchor.value) * globalPlaybackRate;
924
+ const shift = newAnchor - audioSyncAnchor.value;
925
925
  const { outputLatency } = audioContext;
926
926
  const safeOutputLatency = outputLatency === 0 ? 0.3 : outputLatency;
927
927
  const latency = audioContext.baseLatency + safeOutputLatency;
928
928
  if (Math.abs(shift) < ALLOWED_GLOBAL_TIME_ANCHOR_SHIFT + latency && !force) {
929
929
  return false;
930
930
  }
931
+ if (Math.abs(shift) < Number.EPSILON) {
932
+ return false;
933
+ }
931
934
  Internals5.Log.verbose({ logLevel, tag: "audio-scheduling" }, "Anchor " + (force ? "forcibly " : "") + "changed from %s to %s with shift %s", audioSyncAnchor.value, newAnchor, shift);
932
935
  audioSyncAnchor.value = newAnchor;
933
936
  return true;
934
937
  };
935
938
 
936
939
  // src/use-playback.ts
940
+ var shouldForceAnchorChange = (newState) => {
941
+ if (newState === "suspended" || newState === "running-to-suspended") {
942
+ return true;
943
+ }
944
+ if (newState === "closed" || newState === "interrupted" || newState === "running" || newState === "suspended-to-running") {
945
+ return false;
946
+ }
947
+ throw new Error(`Unexpected audio context state: ${newState}`);
948
+ };
937
949
  var usePlayback = ({
938
950
  loop,
939
951
  playbackRate,
@@ -998,7 +1010,8 @@ var usePlayback = ({
998
1010
  return;
999
1011
  }
1000
1012
  const callback = () => {
1001
- if (audioContext.state !== "running") {
1013
+ const newState = sharedAudioContext?.getAudioContextState();
1014
+ if (newState && shouldForceAnchorChange(newState)) {
1002
1015
  setGlobalTimeAnchor({
1003
1016
  audioContext,
1004
1017
  audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
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.465",
6
+ "version": "4.0.467",
7
7
  "description": "React component for embedding a Remotion preview into your app",
8
8
  "main": "dist/cjs/index.js",
9
9
  "types": "dist/cjs/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  ],
36
36
  "license": "SEE LICENSE IN LICENSE.md",
37
37
  "dependencies": {
38
- "remotion": "4.0.465"
38
+ "remotion": "4.0.467"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": ">=16.8.0",
@@ -49,7 +49,7 @@
49
49
  "react-dom": "19.2.3",
50
50
  "webpack": "5.105.0",
51
51
  "zod": "4.3.6",
52
- "@remotion/eslint-config-internal": "4.0.465",
52
+ "@remotion/eslint-config-internal": "4.0.467",
53
53
  "eslint": "9.19.0",
54
54
  "@typescript/native-preview": "7.0.0-dev.20260217.1"
55
55
  },