Skip to content

Commit 8eaac8d

Browse files
fix: enhance play function in useAudio hook to reset currentTime before playback
1 parent 207f55c commit 8eaac8d

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# [Versions](https://github.com/Tracktor/react-utils/releases)
22

3-
## v1.27.0
4-
- **[feat]** : Add `useAudio` hook for audio playback management (play, pause, toggle, stop, volume control).
3+
## v1.27.1
4+
- **[fix]** : Enhance play function in useAudio hook to reset currentTime before playback

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@tracktor/react-utils",
33
"description": "React data table and react data grid",
4-
"version": "1.27.0",
4+
"version": "1.27.1",
55
"private": false,
66
"license": "ISC",
77
"type": "module",

src/hooks/useAudio/useAudio.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,17 @@ const useAudio = (src: string, options?: UseAudioOptions): UseAudioReturn => {
158158
);
159159

160160
const play = useCallback(() => {
161-
audioRef.current?.play().catch((err) => {
161+
const audio = audioRef.current;
162+
163+
if (!audio) {
164+
return;
165+
}
166+
167+
if (!audio.paused) {
168+
audio.currentTime = 0;
169+
}
170+
171+
audio.play().catch((err) => {
162172
setError(err instanceof Error ? err.message : "Play was prevented");
163173
});
164174
}, []);

0 commit comments

Comments
 (0)