l-min-components 1.7.1323 → 1.7.1325
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
|
@@ -41,15 +41,14 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
41
41
|
const handleEnded = () => setIsPlaying(false);
|
|
42
42
|
const handlePause = () => setIsPlaying(false);
|
|
43
43
|
const handlePlay = () => setIsPlaying(true);
|
|
44
|
-
|
|
45
44
|
const handleProgress = () => {
|
|
46
45
|
if (audio) {
|
|
47
46
|
const currentTime = audio.currentTime;
|
|
48
47
|
const duration = audio.duration;
|
|
48
|
+
|
|
49
49
|
setProgress({ currentTime, duration });
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
-
|
|
53
52
|
const attachAudioEvents = () => {
|
|
54
53
|
audio.addEventListener("ended", handleEnded);
|
|
55
54
|
audio.addEventListener("pause", handlePause);
|
|
@@ -59,34 +58,17 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
59
58
|
audio.addEventListener("waiting", () => setIsBuffering(true));
|
|
60
59
|
audio.addEventListener("canplay", () => setIsBuffering(false));
|
|
61
60
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
audio.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
audio.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
if (audio && accountId) {
|
|
74
|
-
if (src) {
|
|
75
|
-
// Load src directly — faster, non-stream
|
|
76
|
-
audio.src = src;
|
|
77
|
-
const handleMetadata = () => {
|
|
78
|
-
setIsReady(true);
|
|
79
|
-
handleProgress();
|
|
80
|
-
audio.removeEventListener("loadedmetadata", handleMetadata);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
audio.addEventListener("loadedmetadata", handleMetadata);
|
|
84
|
-
attachAudioEvents();
|
|
85
|
-
audio.load();
|
|
86
|
-
} else if (Hls.isSupported() && streamSrc) {
|
|
87
|
-
// HLS streaming setup
|
|
61
|
+
if (audio && src) {
|
|
62
|
+
audio.src = src;
|
|
63
|
+
audio.addEventListener("loadedmetadata", () => {
|
|
64
|
+
setIsReady(true);
|
|
65
|
+
});
|
|
66
|
+
attachAudioEvents();
|
|
67
|
+
audio.load();
|
|
68
|
+
} else if (audio && accountId) {
|
|
69
|
+
if (Hls?.isSupported() && streamSrc && !src) {
|
|
88
70
|
hls = new Hls({
|
|
89
|
-
xhrSetup: (xhr, url)
|
|
71
|
+
xhrSetup: function (xhr, url) {
|
|
90
72
|
const modifiedURL = `${url}?_account=${accountId}`;
|
|
91
73
|
xhr.open("GET", modifiedURL, true);
|
|
92
74
|
xhr.setRequestHeader("Authorization", `Bearer ${accessToken}`);
|
|
@@ -94,7 +76,7 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
94
76
|
lowLatencyMode: true,
|
|
95
77
|
});
|
|
96
78
|
|
|
97
|
-
hls
|
|
79
|
+
hls?.attachMedia(audio);
|
|
98
80
|
|
|
99
81
|
hls.on(Hls.Events.MEDIA_ATTACHED, () => {
|
|
100
82
|
hls.loadSource(url);
|
|
@@ -105,13 +87,17 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
105
87
|
setError(null);
|
|
106
88
|
});
|
|
107
89
|
|
|
108
|
-
hls.on(Hls
|
|
90
|
+
hls.on(Hls?.Events?.MANIFEST_PARSED, () => {
|
|
109
91
|
setIsReady(true);
|
|
110
92
|
setError(null);
|
|
111
93
|
});
|
|
94
|
+
hls.on(Hls?.Events?.BUFFER_STALLED, () => {
|
|
95
|
+
setIsBuffering(true);
|
|
96
|
+
});
|
|
112
97
|
|
|
113
|
-
hls.on(Hls
|
|
114
|
-
|
|
98
|
+
hls.on(Hls?.Events?.BUFFER_APPENDED, () => {
|
|
99
|
+
setIsBuffering(false);
|
|
100
|
+
});
|
|
115
101
|
|
|
116
102
|
hls.on(Hls.Events.ERROR, (event, data) => {
|
|
117
103
|
console.warn("HLS error", data);
|
|
@@ -127,26 +113,19 @@ const useAudioPlayer = ({ src, streamSrc }) => {
|
|
|
127
113
|
}
|
|
128
114
|
}
|
|
129
115
|
});
|
|
130
|
-
|
|
131
|
-
attachAudioEvents();
|
|
132
|
-
} else if (
|
|
133
|
-
streamSrc &&
|
|
134
|
-
audio.canPlayType("application/vnd.apple.mpegurl")
|
|
135
|
-
) {
|
|
136
|
-
// Safari native HLS
|
|
116
|
+
} else if (!src && audio.canPlayType("application/vnd.apple.mpegurl")) {
|
|
137
117
|
audio.src = url;
|
|
138
118
|
audio.addEventListener("loadedmetadata", () => {
|
|
139
119
|
setIsReady(true);
|
|
140
120
|
});
|
|
141
|
-
attachAudioEvents();
|
|
142
121
|
}
|
|
122
|
+
attachAudioEvents();
|
|
143
123
|
}
|
|
144
|
-
|
|
145
124
|
return () => {
|
|
146
125
|
if (hls) {
|
|
147
126
|
hls.destroy();
|
|
148
127
|
}
|
|
149
|
-
|
|
128
|
+
|
|
150
129
|
setIsReady(false);
|
|
151
130
|
};
|
|
152
131
|
}, [url, accessToken, accountId, audio, src, streamSrc]);
|