@wavv/ui 2.4.14 → 2.4.15-alpha.1
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.
- package/build/components/Audio.js +27 -1
- package/package.json +1 -1
|
@@ -13,6 +13,9 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
|
|
|
13
13
|
const [displayCurrent, setDisplayCurrent] = useState('');
|
|
14
14
|
const [displayDuration, setDisplayDuration] = useState('0:00');
|
|
15
15
|
const audioRef = useRef(null);
|
|
16
|
+
const isSeekingRef = useRef(false);
|
|
17
|
+
const seekedTimeoutRef = useRef(null);
|
|
18
|
+
const END_EPSILON_SECONDS = 0.75;
|
|
16
19
|
const { height = 30, showHoverTime = false, playedColor, unplayedColor } = 'object' == typeof waveform ? waveform : {};
|
|
17
20
|
const play = ()=>{
|
|
18
21
|
const { current: audio } = audioRef;
|
|
@@ -88,6 +91,9 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
|
|
|
88
91
|
src,
|
|
89
92
|
fallbackDuration
|
|
90
93
|
]);
|
|
94
|
+
useEffect(()=>()=>{
|
|
95
|
+
if (seekedTimeoutRef.current) clearTimeout(seekedTimeoutRef.current);
|
|
96
|
+
}, []);
|
|
91
97
|
const formatTime = (time)=>{
|
|
92
98
|
if (!Number.isFinite(time) || time < 0) return '0:00';
|
|
93
99
|
const mins = Math.floor(time / 60);
|
|
@@ -95,6 +101,7 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
|
|
|
95
101
|
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
|
96
102
|
};
|
|
97
103
|
const updateProgress = ()=>{
|
|
104
|
+
if (isSeekingRef.current) return;
|
|
98
105
|
const { current: audio } = audioRef;
|
|
99
106
|
if (audio) {
|
|
100
107
|
const { currentTime } = audio;
|
|
@@ -128,9 +135,27 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
|
|
|
128
135
|
}, 100);
|
|
129
136
|
}
|
|
130
137
|
};
|
|
138
|
+
const handleSeeked = ()=>{
|
|
139
|
+
isSeekingRef.current = false;
|
|
140
|
+
if (seekedTimeoutRef.current) {
|
|
141
|
+
clearTimeout(seekedTimeoutRef.current);
|
|
142
|
+
seekedTimeoutRef.current = null;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
131
145
|
const handleControlGrab = (value)=>{
|
|
132
146
|
const sliderPosition = Array.isArray(value) ? value[0] : value;
|
|
133
|
-
if (audioRef?.current
|
|
147
|
+
if (!audioRef?.current || !Number.isFinite(sliderPosition) || !Number.isFinite(totalDuration) || totalDuration <= 0) return;
|
|
148
|
+
const maxSeekTarget = Math.max(0, totalDuration - END_EPSILON_SECONDS);
|
|
149
|
+
const clamped = Math.min(Math.max(sliderPosition, 0), maxSeekTarget);
|
|
150
|
+
isSeekingRef.current = true;
|
|
151
|
+
if (seekedTimeoutRef.current) clearTimeout(seekedTimeoutRef.current);
|
|
152
|
+
seekedTimeoutRef.current = setTimeout(()=>{
|
|
153
|
+
isSeekingRef.current = false;
|
|
154
|
+
seekedTimeoutRef.current = null;
|
|
155
|
+
}, 300);
|
|
156
|
+
setProgress(clamped);
|
|
157
|
+
setDisplayCurrent(formatTime(clamped));
|
|
158
|
+
audioRef.current.currentTime = clamped;
|
|
134
159
|
};
|
|
135
160
|
const hideSlider = isCleared && hideSliderOnStop;
|
|
136
161
|
const hideTime = isCleared && hideTimeOnStop;
|
|
@@ -199,6 +224,7 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
|
|
|
199
224
|
onEmptied: handleAudioStop,
|
|
200
225
|
onEnded: handleAudioStop,
|
|
201
226
|
onTimeUpdate: updateProgress,
|
|
227
|
+
onSeeked: handleSeeked,
|
|
202
228
|
onDurationChange: handleLoad,
|
|
203
229
|
onLoadedMetadata: handleLoad,
|
|
204
230
|
onLoadedData: handleLoad,
|