l-min-components 1.0.1143 → 1.0.1147
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
|
@@ -13,17 +13,12 @@ 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 (!
|
|
18
|
+
if (!audioRef.current) return;
|
|
20
19
|
let hls;
|
|
21
20
|
|
|
22
|
-
if (src) {
|
|
23
|
-
audio.src = src;
|
|
24
|
-
audio.load();
|
|
25
|
-
setIsReady(true);
|
|
26
|
-
} else if (Hls?.isSupported() && streamSrc) {
|
|
21
|
+
if (Hls?.isSupported() && streamSrc && !src) {
|
|
27
22
|
hls = new Hls({
|
|
28
23
|
xhrSetup: function (xhr, url) {
|
|
29
24
|
const modifiedURL = `${url}?_account=${accountId}`;
|
|
@@ -34,7 +29,7 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
34
29
|
});
|
|
35
30
|
|
|
36
31
|
hls.loadSource(streamSrc);
|
|
37
|
-
hls?.attachMedia(
|
|
32
|
+
hls?.attachMedia(audioRef.current);
|
|
38
33
|
|
|
39
34
|
hls.on(Hls?.Events?.MANIFEST_PARSED, () => {
|
|
40
35
|
setIsReady(true);
|
|
@@ -51,15 +46,18 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
51
46
|
hls.on(Hls.Events.ERROR, (event, data) => {
|
|
52
47
|
setError(data);
|
|
53
48
|
});
|
|
54
|
-
} else if (
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
} else if (
|
|
50
|
+
!src &&
|
|
51
|
+
audioRef.current.canPlayType("application/vnd.apple.mpegurl")
|
|
52
|
+
) {
|
|
53
|
+
audioRef.current.src = streamSrc;
|
|
54
|
+
audioRef.current.addEventListener("loadedmetadata", () => {
|
|
57
55
|
setIsReady(true);
|
|
58
56
|
});
|
|
59
57
|
} else {
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
if (audioRef.current && src) {
|
|
59
|
+
audioRef.current.src = src;
|
|
60
|
+
audioRef.current.load();
|
|
63
61
|
setIsReady(true);
|
|
64
62
|
}
|
|
65
63
|
}
|
|
@@ -72,25 +70,38 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
72
70
|
setIsPlaying(false);
|
|
73
71
|
};
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
audioRef.current.addEventListener("ended", handleEnded);
|
|
74
|
+
audioRef.current.addEventListener("playing", handlePlaying);
|
|
75
|
+
audioRef.current.addEventListener("pause", handlePause);
|
|
78
76
|
|
|
79
77
|
const handleProgress = () => {
|
|
80
|
-
if (
|
|
81
|
-
const currentTime =
|
|
82
|
-
const duration =
|
|
78
|
+
if (audioRef.current) {
|
|
79
|
+
const currentTime = audioRef.current.currentTime;
|
|
80
|
+
const duration = audioRef.current.duration;
|
|
83
81
|
|
|
84
82
|
setProgress({ currentTime, duration });
|
|
85
83
|
}
|
|
86
84
|
};
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
audioRef.current.addEventListener("timeupdate", handleProgress);
|
|
86
|
+
audioRef.current.addEventListener("loadedmetadata", handleProgress);
|
|
87
|
+
audioRef.current.addEventListener("waiting", () => setIsBuffering(true));
|
|
88
|
+
audioRef.current.addEventListener("canplay", () => setIsBuffering(false));
|
|
89
89
|
|
|
90
90
|
return () => {
|
|
91
91
|
if (hls) {
|
|
92
92
|
hls.destroy();
|
|
93
93
|
}
|
|
94
|
+
audioRef.current.removeEventListener("ended", handleEnded);
|
|
95
|
+
audioRef.current.removeEventListener("playing", handlePlaying);
|
|
96
|
+
audioRef.current.removeEventListener("pause", handlePause);
|
|
97
|
+
audioRef.current.removeEventListener("timeupdate", handleProgress);
|
|
98
|
+
audioRef.current.removeEventListener("loadedmetadata", handleProgress);
|
|
99
|
+
audioRef.current.removeEventListener("waiting", () =>
|
|
100
|
+
setIsBuffering(true)
|
|
101
|
+
);
|
|
102
|
+
audioRef.current.removeEventListener("canplay", () =>
|
|
103
|
+
setIsBuffering(false)
|
|
104
|
+
);
|
|
94
105
|
};
|
|
95
106
|
}, [src, streamSrc, accessToken, accountId]);
|
|
96
107
|
|
|
@@ -98,20 +109,20 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
98
109
|
if (audioRef.current) {
|
|
99
110
|
audioRef.current.play();
|
|
100
111
|
}
|
|
101
|
-
}, [
|
|
112
|
+
}, []);
|
|
102
113
|
|
|
103
114
|
const pause = useCallback(() => {
|
|
104
115
|
if (audioRef.current) {
|
|
105
116
|
audioRef.current.pause();
|
|
106
117
|
}
|
|
107
|
-
}, [
|
|
118
|
+
}, []);
|
|
108
119
|
|
|
109
120
|
const stop = useCallback(() => {
|
|
110
121
|
if (audioRef.current) {
|
|
111
122
|
audioRef.current.pause();
|
|
112
123
|
audioRef.current.currentTime = 0;
|
|
113
124
|
}
|
|
114
|
-
}, [
|
|
125
|
+
}, []);
|
|
115
126
|
|
|
116
127
|
return {
|
|
117
128
|
stop,
|