l-min-components 1.0.1128 → 1.0.1135
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
package/src/components/index.js
CHANGED
|
@@ -54,3 +54,5 @@ export { default as useTranslation } from "../hooks/useTranslation";
|
|
|
54
54
|
export { default as ImageComponent } from "./ImageComponent";
|
|
55
55
|
export { default as DeveloperBanner } from "./banner/developerBanner";
|
|
56
56
|
export { default as VideoPlayer } from "./video-player";
|
|
57
|
+
export { default as useAudioPlayer } from "./useAudioPlayer";
|
|
58
|
+
export { default as AudioWaveComponent } from "./useAudioPlayer/audioWave";
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import styled from "styled-components";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {{type: 'extra-small' | 'small' | 'normal', count: number, lineWidth:string, playState: 'play' | 'paused' | 'stop' , color:string
|
|
7
|
+
* }} prpos
|
|
8
|
+
*/
|
|
9
|
+
const AudioWaveComponent = ({
|
|
10
|
+
type,
|
|
11
|
+
count = 20,
|
|
12
|
+
lineWidth,
|
|
13
|
+
playState = "stop",
|
|
14
|
+
color,
|
|
15
|
+
}) => {
|
|
16
|
+
const getLine = () => {
|
|
17
|
+
const list = [];
|
|
18
|
+
|
|
19
|
+
for (let index = 0; index < count; index++) {
|
|
20
|
+
const value = index + 1;
|
|
21
|
+
if (value % 7 === 0) list.push("wave-delay-1");
|
|
22
|
+
else if (value % 6 === 0) list.push("wave-delay-5");
|
|
23
|
+
else if (value % 5 === 0) list.push("wave-delay-3");
|
|
24
|
+
else if (value % 4 === 0) list.push("wave-delay-2");
|
|
25
|
+
else if (value % 3 === 0) list.push("wave-delay-4");
|
|
26
|
+
else if (value % 2 === 0) list.push("wave-delay-3");
|
|
27
|
+
else list.push("wave-delay-2");
|
|
28
|
+
}
|
|
29
|
+
return list;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Container className={type}>
|
|
34
|
+
{getLine()?.map((i, idx) => {
|
|
35
|
+
return (
|
|
36
|
+
<li
|
|
37
|
+
key={idx}
|
|
38
|
+
style={
|
|
39
|
+
lineWidth || color
|
|
40
|
+
? { width: lineWidth, background: color }
|
|
41
|
+
: null
|
|
42
|
+
}
|
|
43
|
+
className={`wave ${i} ${playState}`}
|
|
44
|
+
></li>
|
|
45
|
+
);
|
|
46
|
+
})}
|
|
47
|
+
</Container>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default AudioWaveComponent;
|
|
52
|
+
|
|
53
|
+
const Container = styled.ul`
|
|
54
|
+
position: relative;
|
|
55
|
+
display: flex;
|
|
56
|
+
align-items: center;
|
|
57
|
+
gap: 12px;
|
|
58
|
+
height: 52px;
|
|
59
|
+
width: fit-content;
|
|
60
|
+
|
|
61
|
+
&.extra-small {
|
|
62
|
+
height: 20px;
|
|
63
|
+
gap: 5px;
|
|
64
|
+
.wave {
|
|
65
|
+
height: 8px;
|
|
66
|
+
width: 2.5px;
|
|
67
|
+
animation-name: ex_smail_pulse;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
&.small {
|
|
71
|
+
height: 34px;
|
|
72
|
+
gap: 8px;
|
|
73
|
+
.wave {
|
|
74
|
+
width: 3px;
|
|
75
|
+
animation-name: smail_pulse;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.wave {
|
|
80
|
+
fill: #231f20;
|
|
81
|
+
animation-name: pulse;
|
|
82
|
+
animation-duration: 1.2s;
|
|
83
|
+
animation-iteration-count: infinite;
|
|
84
|
+
width: 5px;
|
|
85
|
+
height: 16px;
|
|
86
|
+
flex-shrink: 0;
|
|
87
|
+
overflow: hidden;
|
|
88
|
+
y: 11px;
|
|
89
|
+
border-radius: 100px;
|
|
90
|
+
background: linear-gradient(180deg, #e5ad0e 0%, #fecf4c 100%);
|
|
91
|
+
|
|
92
|
+
&.play {
|
|
93
|
+
animation-play-state: running;
|
|
94
|
+
}
|
|
95
|
+
&.paused {
|
|
96
|
+
animation-play-state: paused;
|
|
97
|
+
}
|
|
98
|
+
&.stop {
|
|
99
|
+
animation-name: none;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.wave-delay-5 {
|
|
104
|
+
animation-delay: 1s;
|
|
105
|
+
}
|
|
106
|
+
.wave-delay-4 {
|
|
107
|
+
animation-delay: 0.8s;
|
|
108
|
+
}
|
|
109
|
+
.wave-delay-3 {
|
|
110
|
+
animation-delay: 0.6s;
|
|
111
|
+
}
|
|
112
|
+
.wave-delay-2 {
|
|
113
|
+
animation-delay: 0.4s;
|
|
114
|
+
}
|
|
115
|
+
.wave-delay-1 {
|
|
116
|
+
animation-delay: 0.2s;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@keyframes pulse {
|
|
120
|
+
0%,
|
|
121
|
+
100% {
|
|
122
|
+
height: 16px;
|
|
123
|
+
y: 11px;
|
|
124
|
+
}
|
|
125
|
+
50% {
|
|
126
|
+
height: 52px;
|
|
127
|
+
y: 0px;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@keyframes smail_pulse {
|
|
132
|
+
0%,
|
|
133
|
+
100% {
|
|
134
|
+
height: 16px;
|
|
135
|
+
y: 11px;
|
|
136
|
+
}
|
|
137
|
+
50% {
|
|
138
|
+
height: 34px;
|
|
139
|
+
y: 0px;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
@keyframes ex_smail_pulse {
|
|
143
|
+
0%,
|
|
144
|
+
100% {
|
|
145
|
+
height: 8px;
|
|
146
|
+
y: 11px;
|
|
147
|
+
}
|
|
148
|
+
50% {
|
|
149
|
+
height: 20px;
|
|
150
|
+
y: 0px;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
`;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { useContext, useEffect, useRef, useState } from "react";
|
|
2
|
+
import Hls from "hls.js";
|
|
3
|
+
import { OutletContext } from "../AppMainLayout";
|
|
4
|
+
|
|
5
|
+
const useAudioPlayer = ({ src, streamSrc }) => {
|
|
6
|
+
const audioRef = useRef(null);
|
|
7
|
+
const [isPlaying, setIsPlaying] = useState(false);
|
|
8
|
+
const [isBuffering, setIsBuffering] = useState(false);
|
|
9
|
+
const [isReady, setIsReady] = useState(false);
|
|
10
|
+
const [error, setError] = useState(null);
|
|
11
|
+
const [progress, setProgress] = useState({});
|
|
12
|
+
|
|
13
|
+
const { accessToken, generalData } = useContext(OutletContext);
|
|
14
|
+
|
|
15
|
+
const accountId = generalData?.selectedAccount?.id;
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const audio = audioRef?.current;
|
|
19
|
+
if (!audio) return;
|
|
20
|
+
let hls;
|
|
21
|
+
|
|
22
|
+
if (src) {
|
|
23
|
+
audio.src = src;
|
|
24
|
+
} else if (Hls?.isSupported() && streamSrc) {
|
|
25
|
+
hls = new Hls({
|
|
26
|
+
xhrSetup: function (xhr, url) {
|
|
27
|
+
const modifiedURL = `${url}?_account=${accountId}`;
|
|
28
|
+
xhr.open("GET", modifiedURL, true);
|
|
29
|
+
xhr.setRequestHeader("Authorization", `Bearer ${accessToken}`);
|
|
30
|
+
},
|
|
31
|
+
lowLatencyMode: true,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
hls.loadSource(streamSrc);
|
|
35
|
+
hls?.attachMedia(audio);
|
|
36
|
+
|
|
37
|
+
hls.on(Hls?.Events?.MANIFEST_PARSED, () => {
|
|
38
|
+
setIsReady(true);
|
|
39
|
+
setError(null);
|
|
40
|
+
});
|
|
41
|
+
hls.on(Hls?.Events?.BUFFER_STALLED, () => {
|
|
42
|
+
setIsBuffering(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
hls.on(Hls?.Events?.BUFFER_APPENDED, () => {
|
|
46
|
+
setIsBuffering(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
hls.on(Hls.Events.ERROR, (event, data) => {
|
|
50
|
+
setError(data);
|
|
51
|
+
});
|
|
52
|
+
} else if (!src && audio.canPlayType("application/vnd.apple.mpegurl")) {
|
|
53
|
+
audio.src = streamSrc;
|
|
54
|
+
audio.addEventListener("loadedmetadata", () => {
|
|
55
|
+
setIsReady(true);
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
if (audio && src) {
|
|
59
|
+
audio.src = src;
|
|
60
|
+
audio.load();
|
|
61
|
+
setIsReady(true);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const handleEnded = () => setIsPlaying(false);
|
|
65
|
+
|
|
66
|
+
const handlePlaying = () => {
|
|
67
|
+
setIsPlaying(true);
|
|
68
|
+
};
|
|
69
|
+
const handlePause = () => {
|
|
70
|
+
setIsPlaying(false);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
audio.addEventListener("ended", handleEnded);
|
|
74
|
+
audio.addEventListener("playing", handlePlaying);
|
|
75
|
+
audio.addEventListener("pause", handlePause);
|
|
76
|
+
|
|
77
|
+
const handleProgress = () => {
|
|
78
|
+
if (audio) {
|
|
79
|
+
const currentTime = audio.currentTime;
|
|
80
|
+
const duration = audio.duration;
|
|
81
|
+
|
|
82
|
+
setProgress({ currentTime, duration });
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
audio.addEventListener("timeupdate", handleProgress);
|
|
86
|
+
|
|
87
|
+
return () => {
|
|
88
|
+
if (hls) {
|
|
89
|
+
hls.destroy();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}, [src, streamSrc, accessToken, accountId]);
|
|
93
|
+
|
|
94
|
+
const play = () => {
|
|
95
|
+
if (audioRef.current) {
|
|
96
|
+
audioRef.current.play();
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const pause = () => {
|
|
101
|
+
if (audioRef.current) {
|
|
102
|
+
audioRef.current.pause();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const stop = () => {
|
|
106
|
+
if (audioRef.current) {
|
|
107
|
+
audioRef.current.pause();
|
|
108
|
+
audioRef.current.currentTime = 0;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
stop,
|
|
113
|
+
audioRef,
|
|
114
|
+
play,
|
|
115
|
+
pause,
|
|
116
|
+
isPlaying,
|
|
117
|
+
isBuffering,
|
|
118
|
+
isReady,
|
|
119
|
+
error,
|
|
120
|
+
progress,
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export default useAudioPlayer;
|