l-min-components 1.0.1143 → 1.0.1145

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "l-min-components",
3
- "version": "1.0.1143",
3
+ "version": "1.0.1145",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -13,15 +13,14 @@ const useAudioPlayer = ({ src, streamSrc }) => {
13
13
  const { accessToken, generalData } = useContext(OutletContext);
14
14
 
15
15
  const accountId = generalData?.selectedAccount?.id;
16
- const audio = audioRef?.current;
17
16
 
18
17
  useEffect(() => {
19
- if (!audio) return;
18
+ if (!audioRef.current) return;
20
19
  let hls;
21
20
 
22
21
  if (src) {
23
- audio.src = src;
24
- audio.load();
22
+ audioRef.current.src = src;
23
+ audioRef.current.load();
25
24
  setIsReady(true);
26
25
  } else if (Hls?.isSupported() && streamSrc) {
27
26
  hls = new Hls({
@@ -34,7 +33,7 @@ const useAudioPlayer = ({ src, streamSrc }) => {
34
33
  });
35
34
 
36
35
  hls.loadSource(streamSrc);
37
- hls?.attachMedia(audio);
36
+ hls?.attachMedia(audioRef.current);
38
37
 
39
38
  hls.on(Hls?.Events?.MANIFEST_PARSED, () => {
40
39
  setIsReady(true);
@@ -51,15 +50,18 @@ const useAudioPlayer = ({ src, streamSrc }) => {
51
50
  hls.on(Hls.Events.ERROR, (event, data) => {
52
51
  setError(data);
53
52
  });
54
- } else if (!src && audio.canPlayType("application/vnd.apple.mpegurl")) {
55
- audio.src = streamSrc;
56
- audio.addEventListener("loadedmetadata", () => {
53
+ } else if (
54
+ !src &&
55
+ audioRef.current.canPlayType("application/vnd.apple.mpegurl")
56
+ ) {
57
+ audioRef.current.src = streamSrc;
58
+ audioRef.current.addEventListener("loadedmetadata", () => {
57
59
  setIsReady(true);
58
60
  });
59
61
  } else {
60
- if (audio && src) {
61
- audio.src = src;
62
- audio.load();
62
+ if (audioRef.current && src) {
63
+ audioRef.current.src = src;
64
+ audioRef.current.load();
63
65
  setIsReady(true);
64
66
  }
65
67
  }
@@ -72,46 +74,59 @@ const useAudioPlayer = ({ src, streamSrc }) => {
72
74
  setIsPlaying(false);
73
75
  };
74
76
 
75
- audio.addEventListener("ended", handleEnded);
76
- audio.addEventListener("playing", handlePlaying);
77
- audio.addEventListener("pause", handlePause);
77
+ audioRef.current.addEventListener("ended", handleEnded);
78
+ audioRef.current.addEventListener("playing", handlePlaying);
79
+ audioRef.current.addEventListener("pause", handlePause);
78
80
 
79
81
  const handleProgress = () => {
80
- if (audio) {
81
- const currentTime = audio.currentTime;
82
- const duration = audio.duration;
82
+ if (audioRef.current) {
83
+ const currentTime = audioRef.current.currentTime;
84
+ const duration = audioRef.current.duration;
83
85
 
84
86
  setProgress({ currentTime, duration });
85
87
  }
86
88
  };
87
- audio.addEventListener("timeupdate", handleProgress);
88
- audio.addEventListener("loadedmetadata", handleProgress);
89
+ audioRef.current.addEventListener("timeupdate", handleProgress);
90
+ audioRef.current.addEventListener("loadedmetadata", handleProgress);
91
+ audioRef.current.addEventListener("waiting", () => setIsBuffering(true));
92
+ audioRef.current.addEventListener("canplay", () => setIsBuffering(false));
89
93
 
90
94
  return () => {
91
95
  if (hls) {
92
96
  hls.destroy();
93
97
  }
98
+ audioRef.current.removeEventListener("ended", handleEnded);
99
+ audioRef.current.removeEventListener("playing", handlePlaying);
100
+ audioRef.current.removeEventListener("pause", handlePause);
101
+ audioRef.current.removeEventListener("timeupdate", handleProgress);
102
+ audioRef.current.removeEventListener("loadedmetadata", handleProgress);
103
+ audioRef.current.removeEventListener("waiting", () =>
104
+ setIsBuffering(true)
105
+ );
106
+ audioRef.current.removeEventListener("canplay", () =>
107
+ setIsBuffering(false)
108
+ );
94
109
  };
95
110
  }, [src, streamSrc, accessToken, accountId]);
96
111
 
97
112
  const play = useCallback(() => {
98
- if (audioRef.current) {
113
+ if (audioRef.current && (src || streamSrc)) {
99
114
  audioRef.current.play();
100
115
  }
101
- }, [src, streamSrc, accessToken, accountId]);
116
+ }, [src, streamSrc]);
102
117
 
103
118
  const pause = useCallback(() => {
104
- if (audioRef.current) {
119
+ if (audioRef.current && (src || streamSrc)) {
105
120
  audioRef.current.pause();
106
121
  }
107
- }, [src, streamSrc, accessToken, accountId]);
122
+ }, [src, streamSrc]);
108
123
 
109
124
  const stop = useCallback(() => {
110
- if (audioRef.current) {
125
+ if (audioRef.current && (src || streamSrc)) {
111
126
  audioRef.current.pause();
112
127
  audioRef.current.currentTime = 0;
113
128
  }
114
- }, [src, streamSrc, accessToken, accountId]);
129
+ }, [src, streamSrc]);
115
130
 
116
131
  return {
117
132
  stop,