@wavv/ui 2.4.15-alpha.1 → 2.4.15-alpha.2

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.
@@ -35,9 +35,20 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
35
35
  const { current: audio } = audioRef;
36
36
  return audio ? !audio.paused : false;
37
37
  };
38
+ const isNearEnd = (sec)=>totalDuration > 0 && totalDuration - sec <= END_EPSILON_SECONDS;
38
39
  const togglePlayPause = ()=>{
39
40
  if (isPlaying) pause();
40
- else play();
41
+ else {
42
+ if (isNearEnd(progress)) {
43
+ setProgress(0);
44
+ setDisplayCurrent('0:00');
45
+ const { current: audio } = audioRef;
46
+ if (audio) try {
47
+ audio.currentTime = 0;
48
+ } catch (_e) {}
49
+ }
50
+ play();
51
+ }
41
52
  };
42
53
  useImperativeHandle(ref, ()=>({
43
54
  play,
@@ -59,6 +70,16 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
59
70
  const handleAudioStop = (event)=>{
60
71
  setIsPlaying(false);
61
72
  setIsCleared(true);
73
+ setProgress(0);
74
+ setDisplayCurrent('0:00');
75
+ const { current: audio } = audioRef;
76
+ if (audio) try {
77
+ audio.currentTime = 0;
78
+ window.setTimeout(()=>{
79
+ const ct = audio.currentTime ?? 0;
80
+ if (ct > 0.5) audio.currentTime = 0;
81
+ }, 120);
82
+ } catch (_e) {}
62
83
  if (onStop) onStop(event);
63
84
  };
64
85
  const handleAudioError = ()=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavv/ui",
3
- "version": "2.4.15-alpha.1",
3
+ "version": "2.4.15-alpha.2",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {