l-min-components 1.7.1484 → 1.7.1486
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
|
@@ -26,18 +26,10 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
26
26
|
const [error, setError] = useState(null);
|
|
27
27
|
const [progress, setProgress] = useState({});
|
|
28
28
|
|
|
29
|
-
const url = useMemo(() =>
|
|
29
|
+
const url = useMemo(() => streamSrc || src, [src, streamSrc]);
|
|
30
30
|
const audio = useMemo(() => new Audio(), [url]);
|
|
31
31
|
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
registerAudio(audio);
|
|
34
|
-
return () => {
|
|
35
|
-
unregisterAudio(audio);
|
|
36
|
-
};
|
|
37
|
-
}, [audio]);
|
|
38
|
-
|
|
39
32
|
const { accessToken, generalData } = useContext(OutletContext);
|
|
40
|
-
|
|
41
33
|
const accountId = generalData?.selectedAccount?.id;
|
|
42
34
|
|
|
43
35
|
const play = useCallback(() => {
|
|
@@ -68,12 +60,13 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
68
60
|
const handlePlay = () => setIsPlaying(true);
|
|
69
61
|
const handleProgress = () => {
|
|
70
62
|
if (audio) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
setProgress({
|
|
64
|
+
currentTime: audio.currentTime,
|
|
65
|
+
duration: audio.duration,
|
|
66
|
+
});
|
|
75
67
|
}
|
|
76
68
|
};
|
|
69
|
+
|
|
77
70
|
const attachAudioEvents = () => {
|
|
78
71
|
audio.addEventListener("ended", handleEnded);
|
|
79
72
|
audio.addEventListener("pause", handlePause);
|
|
@@ -83,15 +76,10 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
83
76
|
audio.addEventListener("waiting", () => setIsBuffering(true));
|
|
84
77
|
audio.addEventListener("canplay", () => setIsBuffering(false));
|
|
85
78
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
attachAudioEvents();
|
|
92
|
-
audio.load();
|
|
93
|
-
} else if (audio && accountId) {
|
|
94
|
-
if (Hls?.isSupported() && streamSrc && !src) {
|
|
79
|
+
|
|
80
|
+
if (audio && streamSrc && accountId && !src) {
|
|
81
|
+
// HLS stream preferred
|
|
82
|
+
if (Hls.isSupported()) {
|
|
95
83
|
hls = new Hls({
|
|
96
84
|
xhrSetup: function (xhr, url) {
|
|
97
85
|
const modifiedURL = `${url}?_account=${accountId}`;
|
|
@@ -101,10 +89,10 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
101
89
|
lowLatencyMode: true,
|
|
102
90
|
});
|
|
103
91
|
|
|
104
|
-
hls
|
|
92
|
+
hls.attachMedia(audio);
|
|
105
93
|
|
|
106
94
|
hls.on(Hls.Events.MEDIA_ATTACHED, () => {
|
|
107
|
-
hls.loadSource(
|
|
95
|
+
hls.loadSource(streamSrc);
|
|
108
96
|
});
|
|
109
97
|
|
|
110
98
|
hls.on(Hls.Events.LEVEL_LOADED, () => {
|
|
@@ -112,25 +100,6 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
112
100
|
setError(null);
|
|
113
101
|
});
|
|
114
102
|
|
|
115
|
-
hls.on(Hls.Events.LEVEL_SWITCHED, (val) => {
|
|
116
|
-
if (val === "hlsLevelSwitched") {
|
|
117
|
-
setIsReady(true);
|
|
118
|
-
setError(null);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
hls.on(Hls.Events.LEVEL_LOADING, (val) => {
|
|
122
|
-
if (val === "hlsLevelLoading") {
|
|
123
|
-
setIsReady(false);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
hls.on(Hls?.Events?.BUFFER_STALLED, () => {
|
|
127
|
-
setIsBuffering(true);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
hls.on(Hls?.Events?.BUFFER_APPENDED, () => {
|
|
131
|
-
setIsBuffering(false);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
103
|
hls.on(Hls.Events.ERROR, (event, data) => {
|
|
135
104
|
console.warn("HLS error", data);
|
|
136
105
|
if (data.fatal) {
|
|
@@ -145,24 +114,39 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
145
114
|
}
|
|
146
115
|
}
|
|
147
116
|
});
|
|
148
|
-
} else if (
|
|
149
|
-
audio.src =
|
|
117
|
+
} else if (audio.canPlayType("application/vnd.apple.mpegurl")) {
|
|
118
|
+
audio.src = streamSrc;
|
|
150
119
|
audio.addEventListener("loadedmetadata", () => {
|
|
151
120
|
setIsReady(true);
|
|
152
121
|
});
|
|
153
122
|
}
|
|
154
123
|
attachAudioEvents();
|
|
124
|
+
} else if (audio && src) {
|
|
125
|
+
// Fallback to normal src
|
|
126
|
+
audio.src = src;
|
|
127
|
+
audio.addEventListener("loadedmetadata", () => {
|
|
128
|
+
setIsReady(true);
|
|
129
|
+
});
|
|
130
|
+
attachAudioEvents();
|
|
155
131
|
}
|
|
132
|
+
|
|
156
133
|
return () => {
|
|
157
134
|
if (hls) {
|
|
158
135
|
hls.destroy();
|
|
159
136
|
}
|
|
160
|
-
|
|
161
|
-
|
|
137
|
+
audio.pause();
|
|
138
|
+
audio.currentTime = 0;
|
|
162
139
|
setIsReady(false);
|
|
163
140
|
};
|
|
164
141
|
}, [url, accessToken, accountId, audio, src, streamSrc]);
|
|
165
142
|
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
registerAudio(audio);
|
|
145
|
+
return () => {
|
|
146
|
+
unregisterAudio(audio);
|
|
147
|
+
};
|
|
148
|
+
}, [audio]);
|
|
149
|
+
|
|
166
150
|
return {
|
|
167
151
|
stop,
|
|
168
152
|
audio,
|