Skip to content

Commit c227e3b

Browse files
committed
fix(APlayer): fix crash right on starting to play on Safari
1 parent a1c4759 commit c227e3b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/hooks/useAudioControl.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,16 @@ export function useAudioControl(options: CreateAudioElementOptions) {
185185
},
186186
[audioElementRef]
187187
),
188-
() => audioElementRef.current?.currentTime,
188+
() => {
189+
if (!audioElementRef.current) {
190+
return undefined;
191+
}
192+
193+
// Use `Math.round()` here because
194+
// 1. The player UI only displays currentTime at second-level precision
195+
// 2. Prevent too many updates (leads to crash on Safari)
196+
return Math.round(audioElementRef.current.currentTime);
197+
},
189198
() => undefined
190199
);
191200

0 commit comments

Comments
 (0)