@zohodesk/dot 1.7.22 → 1.7.24
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/README.md +10 -0
- package/assets/Appearance/dark/mode/Dot_DarkMode.module.css +10 -0
- package/assets/Appearance/light/mode/Dot_LightMode.module.css +10 -0
- package/assets/Appearance/pureDark/mode/Dot_PureDarkMode.module.css +10 -0
- package/es/AudioPlayer/AudioPlayer.js +580 -0
- package/es/AudioPlayer/AudioPlayer.module.css +146 -0
- package/es/AudioPlayer/Timer/Timer.js +67 -0
- package/es/AudioPlayer/Timer/Timer.module.css +5 -0
- package/es/AudioPlayer/Timer/__tests__/Timer.spec.js +20 -0
- package/es/AudioPlayer/Timer/__tests__/__snapshots__/Timer.spec.js.snap +14 -0
- package/es/AudioPlayer/Timer/propTypes/defaultProps.js +4 -0
- package/es/AudioPlayer/Timer/propTypes/propTypes.js +11 -0
- package/es/AudioPlayer/__tests__/AudioPlayer.spec.js +44 -0
- package/es/AudioPlayer/__tests__/__snapshots__/AudioPlayer.spec.js.snap +145 -0
- package/es/AudioPlayer/propTypes/defaultProps.js +14 -0
- package/es/AudioPlayer/propTypes/propTypes.js +33 -0
- package/es/AudioPlayer/utils/utils.js +24 -0
- package/lib/AudioPlayer/AudioPlayer.js +662 -0
- package/lib/AudioPlayer/AudioPlayer.module.css +146 -0
- package/lib/AudioPlayer/Timer/Timer.js +117 -0
- package/lib/AudioPlayer/Timer/Timer.module.css +5 -0
- package/lib/AudioPlayer/Timer/__tests__/Timer.spec.js +26 -0
- package/lib/AudioPlayer/Timer/__tests__/__snapshots__/Timer.spec.js.snap +14 -0
- package/lib/AudioPlayer/Timer/propTypes/defaultProps.js +11 -0
- package/lib/AudioPlayer/Timer/propTypes/propTypes.js +22 -0
- package/lib/AudioPlayer/__tests__/AudioPlayer.spec.js +50 -0
- package/lib/AudioPlayer/__tests__/__snapshots__/AudioPlayer.spec.js.snap +145 -0
- package/lib/AudioPlayer/propTypes/defaultProps.js +24 -0
- package/lib/AudioPlayer/propTypes/propTypes.js +44 -0
- package/lib/AudioPlayer/utils/utils.js +33 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
In this Library, we Provide Some Basic Components to Build Your Application
|
|
4
4
|
|
|
5
|
+
# 1.7.24
|
|
6
|
+
|
|
7
|
+
- **Timer**
|
|
8
|
+
- timer_default_text css variable added.
|
|
9
|
+
|
|
10
|
+
# 1.7.23
|
|
11
|
+
|
|
12
|
+
- introduced AudioPlayer & Timer comopnent.
|
|
13
|
+
|
|
14
|
+
|
|
5
15
|
# 1.7.22
|
|
6
16
|
|
|
7
17
|
- **useDragger**
|
|
@@ -34,6 +34,16 @@
|
|
|
34
34
|
--zdt_attachment_download_hover_bg: var(--zdt_cta_grey_35_bg);
|
|
35
35
|
--zdt_avataruser_delete_text: hsla(217, 23.08%, calc(17.84% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
36
36
|
|
|
37
|
+
/* audio player */
|
|
38
|
+
--zdt_audioplayer_default_bg: var(--zdt_cta_grey_15_bg);
|
|
39
|
+
--zdt_audioplayer_line_text: hsla(217, 13.73%, calc(70.00% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
40
|
+
--zdt_audioplayer_input_bg: var(--zdt_cta_grey_35_bg);
|
|
41
|
+
--zdt_audioplayer_pauseicon_text: hsla(217, 13.73%, calc(70.00% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
42
|
+
--zdt_audioplayer_loading_bg: var(--zdtm_cta_primary_bg_default_inverse_lower);
|
|
43
|
+
|
|
44
|
+
/* timer */
|
|
45
|
+
--zdt_timer_default_text: hsla(217, 7.76%, calc(54.51% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
46
|
+
|
|
37
47
|
/* avatar close */
|
|
38
48
|
--zdt_avatarclose_pop_bg: hsla(0, 0.00%, calc(0.00% + var(--zdc_default)), calc( 0.75 + var(--zdc_alpha_high)));
|
|
39
49
|
--zdt_avatarclose_pop_text: hsla(30, 1.64%, calc(76.08% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
@@ -34,6 +34,16 @@
|
|
|
34
34
|
--zdt_attachment_download_hover_bg: var(--zdt_cta_grey_35_bg);
|
|
35
35
|
--zdt_avataruser_delete_text: hsla(0, 0.00%, calc(100.00% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
36
36
|
|
|
37
|
+
/* audio player */
|
|
38
|
+
--zdt_audioplayer_default_bg: var(--zdt_cta_grey_15_bg);
|
|
39
|
+
--zdt_audioplayer_line_text: hsla(220, 10.45%, calc(39.41% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
40
|
+
--zdt_audioplayer_input_bg: var(--zdt_cta_grey_35_bg);
|
|
41
|
+
--zdt_audioplayer_pauseicon_text: hsla(217, 25.93%, calc(15.88% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
42
|
+
--zdt_audioplayer_loading_bg: var(--zdtm_cta_primary_bg_default_inverse_lower);
|
|
43
|
+
|
|
44
|
+
/* timer */
|
|
45
|
+
--zdt_timer_default_text: hsla(217, 25.93%, calc(15.88% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
46
|
+
|
|
37
47
|
/* avatar close */
|
|
38
48
|
--zdt_avatarclose_pop_bg: hsla(0, 0.00%, calc(0.00% + var(--zdc_default)), calc( 0.75 + var(--zdc_alpha_high)));
|
|
39
49
|
--zdt_avatarclose_pop_text: hsla(30, 1.64%, calc(76.08% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
@@ -34,6 +34,16 @@
|
|
|
34
34
|
--zdt_attachment_download_hover_bg: var(--zdt_cta_grey_35_bg);
|
|
35
35
|
--zdt_avataruser_delete_text: hsla(0, 0.00%, calc(12.94% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
36
36
|
|
|
37
|
+
/* audio player */
|
|
38
|
+
--zdt_audioplayer_default_bg: var(--zdt_cta_grey_15_bg);
|
|
39
|
+
--zdt_audioplayer_line_text: hsla(0, 0.00%, calc(60.00% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
40
|
+
--zdt_audioplayer_input_bg: var(--zdt_cta_grey_35_bg);
|
|
41
|
+
--zdt_audioplayer_pauseicon_text: hsla(0, 0.00%, calc(60.00% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
42
|
+
--zdt_audioplayer_loading_bg: var(--zdtm_cta_primary_bg_default_inverse_lower);
|
|
43
|
+
|
|
44
|
+
/* timer */
|
|
45
|
+
--zdt_timer_default_text: hsla(217, 7.76%, calc(54.51% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
46
|
+
|
|
37
47
|
/* avatar close */
|
|
38
48
|
--zdt_avatarclose_pop_bg: hsla(0, 0.00%, calc(0.00% + var(--zdc_default)), calc( 0.75 + var(--zdc_alpha_high)));
|
|
39
49
|
--zdt_avatarclose_pop_text: hsla(30, 1.64%, calc(76.08% + var(--zdc_default_inverse)), calc(1 + var(--zdc_alpha_high)));
|
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Container, Box } from '@zohodesk/components/lib/Layout';
|
|
3
|
+
import Timer from "./Timer/Timer";
|
|
4
|
+
import Icon from '@zohodesk/icons/lib/Icon';
|
|
5
|
+
import { AudioPlayer_propTypes } from "./propTypes/propTypes";
|
|
6
|
+
import { AudioPlayer_defaultProps } from "./propTypes/defaultProps";
|
|
7
|
+
import { openInNewTabWithNoopener } from "./utils/utils";
|
|
8
|
+
import { getExtensionFromFileName } from "./../AttachmentViewer/Attachment";
|
|
9
|
+
import style from "./AudioPlayer.module.css";
|
|
10
|
+
export default class AudioPlayer extends React.Component {
|
|
11
|
+
constructor(props) {
|
|
12
|
+
super(props);
|
|
13
|
+
this.audioPlayer = null;
|
|
14
|
+
this.removeEventListeners = this.removeEventListeners.bind(this);
|
|
15
|
+
this.setAudioPlayerRef = this.setAudioPlayerRef.bind(this);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
componentDidMount() {
|
|
19
|
+
const {
|
|
20
|
+
AudioPlayerChild
|
|
21
|
+
} = this.refs;
|
|
22
|
+
this.audioPlayer.addEventListener('keydown', AudioPlayerChild.handleKeyDown);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
componentWillUnmount() {
|
|
26
|
+
this.removeEventListeners();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
removeEventListeners() {
|
|
30
|
+
const {
|
|
31
|
+
AudioPlayerChild
|
|
32
|
+
} = this.refs;
|
|
33
|
+
this.audioPlayer.removeEventListener('keydown', AudioPlayerChild.handleKeyDown);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
setAudioPlayerRef(ele) {
|
|
37
|
+
this.audioPlayer = ele;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
render() {
|
|
41
|
+
const {
|
|
42
|
+
id,
|
|
43
|
+
isPlay,
|
|
44
|
+
onClose,
|
|
45
|
+
src,
|
|
46
|
+
timerFormat,
|
|
47
|
+
forwardStepInSec,
|
|
48
|
+
backwardStepInSec,
|
|
49
|
+
getAudioDuration,
|
|
50
|
+
needClose,
|
|
51
|
+
needDownload,
|
|
52
|
+
needMuteIcon,
|
|
53
|
+
onPlay,
|
|
54
|
+
onPause,
|
|
55
|
+
onDownloading,
|
|
56
|
+
onAudioSeeking,
|
|
57
|
+
onAudioLoading,
|
|
58
|
+
onError,
|
|
59
|
+
onMuteUnmute,
|
|
60
|
+
duration,
|
|
61
|
+
i18nKeys,
|
|
62
|
+
dataId,
|
|
63
|
+
customClass,
|
|
64
|
+
range
|
|
65
|
+
} = this.props;
|
|
66
|
+
return /*#__PURE__*/React.createElement(Container, {
|
|
67
|
+
dataId: dataId,
|
|
68
|
+
eleRef: this.setAudioPlayerRef,
|
|
69
|
+
tabIndex: 0,
|
|
70
|
+
isCover: false,
|
|
71
|
+
className: `${customClass}`
|
|
72
|
+
}, /*#__PURE__*/React.createElement(AudioPlayerChild, {
|
|
73
|
+
ref: "AudioPlayerChild",
|
|
74
|
+
id: id,
|
|
75
|
+
src: src,
|
|
76
|
+
isPlay: isPlay,
|
|
77
|
+
onClose: onClose,
|
|
78
|
+
timerFormat: timerFormat,
|
|
79
|
+
duration: duration,
|
|
80
|
+
forwardStepInSec: forwardStepInSec,
|
|
81
|
+
backwardStepInSec: backwardStepInSec,
|
|
82
|
+
getAudioDuration: getAudioDuration,
|
|
83
|
+
needClose: needClose,
|
|
84
|
+
needDownload: needDownload,
|
|
85
|
+
needMuteIcon: needMuteIcon,
|
|
86
|
+
onPlay: onPlay,
|
|
87
|
+
onPause: onPause,
|
|
88
|
+
onDownloading: onDownloading,
|
|
89
|
+
onAudioSeeking: onAudioSeeking,
|
|
90
|
+
onAudioLoading: onAudioLoading,
|
|
91
|
+
onError: onError,
|
|
92
|
+
onMuteUnmute: onMuteUnmute,
|
|
93
|
+
i18nKeys: i18nKeys,
|
|
94
|
+
dataId: dataId,
|
|
95
|
+
range: range
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}
|
|
100
|
+
AudioPlayer.defaultProps = AudioPlayer_defaultProps;
|
|
101
|
+
AudioPlayer.propTypes = AudioPlayer_propTypes;
|
|
102
|
+
|
|
103
|
+
class AudioPlayerChild extends React.Component {
|
|
104
|
+
constructor(props) {
|
|
105
|
+
super(props);
|
|
106
|
+
this.audio = null;
|
|
107
|
+
this.intervalId = props.intervalId || '';
|
|
108
|
+
this.state = {
|
|
109
|
+
isPlay: props.isPlay,
|
|
110
|
+
currentHour: '00',
|
|
111
|
+
currentMinute: '00',
|
|
112
|
+
currentSecond: '00',
|
|
113
|
+
sliderRangeValue: 0,
|
|
114
|
+
audioHours: '00',
|
|
115
|
+
audioMinutes: '00',
|
|
116
|
+
audioSeconds: '00',
|
|
117
|
+
overallSeconds: 0,
|
|
118
|
+
minValue: 0,
|
|
119
|
+
step: '1',
|
|
120
|
+
audioType: 'audio/mpeg',
|
|
121
|
+
isMuted: false,
|
|
122
|
+
disableControlIcons: true,
|
|
123
|
+
isShowDuration: false,
|
|
124
|
+
disableRangeSlider: false,
|
|
125
|
+
loadingRange: props.range || 0
|
|
126
|
+
}; // Bind all methods
|
|
127
|
+
|
|
128
|
+
this.getAudioDetails = this.getAudioDetails.bind(this);
|
|
129
|
+
this.onPlayAudio = this.onPlayAudio.bind(this);
|
|
130
|
+
this.onPauseAudio = this.onPauseAudio.bind(this);
|
|
131
|
+
this.togglePlayPause = this.togglePlayPause.bind(this);
|
|
132
|
+
this.updatePlayer = this.updatePlayer.bind(this);
|
|
133
|
+
this.updateRangeValue = this.updateRangeValue.bind(this);
|
|
134
|
+
this.updateTimerValues = this.updateTimerValues.bind(this);
|
|
135
|
+
this.togglePlayer = this.togglePlayer.bind(this);
|
|
136
|
+
this.getAudioDurationDetails = this.getAudioDurationDetails.bind(this);
|
|
137
|
+
this.browserCompatible = this.browserCompatible.bind(this);
|
|
138
|
+
this.onMuteUnmute = this.onMuteUnmute.bind(this);
|
|
139
|
+
this.handleAudioSeeking = this.handleAudioSeeking.bind(this);
|
|
140
|
+
this.handleError = this.handleError.bind(this);
|
|
141
|
+
this.handleAudioLoading = this.handleAudioLoading.bind(this);
|
|
142
|
+
this.removeEventListeners = this.removeEventListeners.bind(this);
|
|
143
|
+
this.downloadFile = this.downloadFile.bind(this);
|
|
144
|
+
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
145
|
+
this.handleClosePlayer = this.handleClosePlayer.bind(this);
|
|
146
|
+
this.updateRange = this.updateRange.bind(this);
|
|
147
|
+
this.setInputRangeRef = this.setInputRangeRef.bind(this);
|
|
148
|
+
this.removeEvent = this.removeEvent.bind(this);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
componentDidMount() {
|
|
152
|
+
this.audio.addEventListener('loadedmetadata', this.getAudioDetails);
|
|
153
|
+
this.audio.addEventListener('canplay', this.browserCompatible);
|
|
154
|
+
this.audio.addEventListener('seeking', this.handleAudioSeeking);
|
|
155
|
+
this.audio.addEventListener('waiting', this.handleAudioLoading);
|
|
156
|
+
this.audio.addEventListener('error', this.handleError);
|
|
157
|
+
this.audio.addEventListener('ended', this.removeEvent);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
componentDidUpdate(prevProps) {
|
|
161
|
+
if (prevProps.isPlay !== this.props.isPlay && this.props.isPlay === false) {
|
|
162
|
+
this.onPauseAudio();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
componentWillUnmount() {
|
|
167
|
+
this.audio.pause();
|
|
168
|
+
clearInterval(this.intervalId);
|
|
169
|
+
this.removeEventListeners();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
removeEventListeners() {
|
|
173
|
+
this.audio.removeEventListener('loadedmetadata', this.getAudioDetails);
|
|
174
|
+
this.audio.removeEventListener('canplay', this.browserCompatible);
|
|
175
|
+
this.audio.removeEventListener('seeking', this.handleAudioSeeking);
|
|
176
|
+
this.audio.removeEventListener('waiting', this.handleAudioLoading);
|
|
177
|
+
this.audio.removeEventListener('error', this.handleError);
|
|
178
|
+
this.audio.removeEventListener('ended', this.removeEvent);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
removeEvent() {
|
|
182
|
+
setTimeout(this.onPauseAudio, 1000);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
getAudioDetails(event) {
|
|
186
|
+
const {
|
|
187
|
+
getAudioDuration,
|
|
188
|
+
src,
|
|
189
|
+
duration: fallbackDuration
|
|
190
|
+
} = this.props;
|
|
191
|
+
const audioType = getExtensionFromFileName(src);
|
|
192
|
+
let durationCalc = Math.ceil(event.target.duration);
|
|
193
|
+
const isDurationValid = Number.isFinite(durationCalc) && !Number.isNaN(durationCalc);
|
|
194
|
+
durationCalc = isDurationValid ? durationCalc : fallbackDuration ? fallbackDuration : 0;
|
|
195
|
+
const {
|
|
196
|
+
hours,
|
|
197
|
+
minutes,
|
|
198
|
+
seconds
|
|
199
|
+
} = this.getAudioDurationDetails(durationCalc);
|
|
200
|
+
const isShowDuration = isDurationValid || fallbackDuration !== undefined;
|
|
201
|
+
this.setState({
|
|
202
|
+
overallSeconds: durationCalc,
|
|
203
|
+
audioHours: hours,
|
|
204
|
+
audioMinutes: minutes,
|
|
205
|
+
audioSeconds: seconds,
|
|
206
|
+
audioType,
|
|
207
|
+
disableControlIcons: false,
|
|
208
|
+
isShowDuration,
|
|
209
|
+
disableRangeSlider: !isDurationValid
|
|
210
|
+
});
|
|
211
|
+
getAudioDuration && getAudioDuration(hours, minutes, seconds);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
getAudioDurationDetails(valueInSec) {
|
|
215
|
+
let hours = 0,
|
|
216
|
+
minutes = 0,
|
|
217
|
+
seconds = 0;
|
|
218
|
+
|
|
219
|
+
if (valueInSec > 0) {
|
|
220
|
+
hours = Math.floor(valueInSec / 3600);
|
|
221
|
+
valueInSec %= 3600;
|
|
222
|
+
minutes = Math.floor(valueInSec / 60);
|
|
223
|
+
seconds = Math.floor(valueInSec % 60);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
hours: hours <= 9 ? `0${hours}` : `${hours}`,
|
|
228
|
+
minutes: minutes <= 9 ? `0${minutes}` : `${minutes}`,
|
|
229
|
+
seconds: seconds <= 9 ? `0${seconds}` : `${seconds}`
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
togglePlayPause() {
|
|
234
|
+
this.state.isPlay ? this.onPauseAudio() : this.onPlayAudio();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
onPlayAudio() {
|
|
238
|
+
const {
|
|
239
|
+
onPlay,
|
|
240
|
+
id
|
|
241
|
+
} = this.props;
|
|
242
|
+
const {
|
|
243
|
+
sliderRangeValue,
|
|
244
|
+
overallSeconds
|
|
245
|
+
} = this.state;
|
|
246
|
+
const isRestart = sliderRangeValue === overallSeconds;
|
|
247
|
+
this.audio.play();
|
|
248
|
+
this.intervalId = setInterval(this.updatePlayer, 1000);
|
|
249
|
+
this.setState({
|
|
250
|
+
isPlay: true,
|
|
251
|
+
isRestart
|
|
252
|
+
});
|
|
253
|
+
onPlay && onPlay(id, 'playing');
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
onPauseAudio() {
|
|
257
|
+
const {
|
|
258
|
+
onPause,
|
|
259
|
+
id
|
|
260
|
+
} = this.props;
|
|
261
|
+
this.audio.pause();
|
|
262
|
+
clearInterval(this.intervalId);
|
|
263
|
+
this.setState({
|
|
264
|
+
isPlay: false
|
|
265
|
+
});
|
|
266
|
+
onPause && onPause(id, 'paused');
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
handleClosePlayer() {
|
|
270
|
+
const {
|
|
271
|
+
onClose,
|
|
272
|
+
id
|
|
273
|
+
} = this.props;
|
|
274
|
+
this.togglePlayer();
|
|
275
|
+
this.onPauseAudio();
|
|
276
|
+
onClose && onClose(id, 'closed');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
handleAudioSeeking() {
|
|
280
|
+
const {
|
|
281
|
+
onAudioSeeking
|
|
282
|
+
} = this.props;
|
|
283
|
+
onAudioSeeking && onAudioSeeking(this.audio.seeking);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
handleAudioLoading() {
|
|
287
|
+
const {
|
|
288
|
+
onAudioLoading
|
|
289
|
+
} = this.props;
|
|
290
|
+
onAudioLoading && onAudioLoading();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
handleError() {
|
|
294
|
+
const {
|
|
295
|
+
onError
|
|
296
|
+
} = this.props;
|
|
297
|
+
onError && onError(this.audio.error.code);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
browserCompatible(playable) {
|
|
301
|
+
if (playable === '') alert('Your browser is unable to play the audio');
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
onMuteUnmute(e) {
|
|
305
|
+
e && e.preventDefault();
|
|
306
|
+
const {
|
|
307
|
+
isMuted
|
|
308
|
+
} = this.state;
|
|
309
|
+
this.audio.muted = !isMuted;
|
|
310
|
+
const {
|
|
311
|
+
onMuteUnmute
|
|
312
|
+
} = this.props;
|
|
313
|
+
this.setState({
|
|
314
|
+
isMuted: !isMuted
|
|
315
|
+
});
|
|
316
|
+
onMuteUnmute && onMuteUnmute(!isMuted);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
setInputRangeRef(ele) {
|
|
320
|
+
const {
|
|
321
|
+
getRef
|
|
322
|
+
} = this.props;
|
|
323
|
+
this.inputRange = ele;
|
|
324
|
+
getRef && getRef(ele);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
updateRange(e) {
|
|
328
|
+
this.props.updateRange(e.target.value);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
updatePlayer(e) {
|
|
332
|
+
this.updateRangeValue(e?.target?.value, this.updateTimerValues);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
updateRangeValue(value, afterUpdateCallback) {
|
|
336
|
+
let {
|
|
337
|
+
isPlay,
|
|
338
|
+
sliderRangeValue,
|
|
339
|
+
overallSeconds,
|
|
340
|
+
isRestart
|
|
341
|
+
} = this.state;
|
|
342
|
+
sliderRangeValue = Math.max(0, sliderRangeValue);
|
|
343
|
+
let rangeValue = value || ++sliderRangeValue;
|
|
344
|
+
|
|
345
|
+
if (rangeValue > overallSeconds && !isRestart) {
|
|
346
|
+
if (isPlay) {
|
|
347
|
+
this.audio.pause();
|
|
348
|
+
this.setState({
|
|
349
|
+
isPlay: false
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
this.audio.currentTime = overallSeconds;
|
|
354
|
+
clearInterval(this.intervalId);
|
|
355
|
+
rangeValue = overallSeconds;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (isRestart) {
|
|
359
|
+
this.audio.currentTime = 0;
|
|
360
|
+
rangeValue = 0;
|
|
361
|
+
this.setState({
|
|
362
|
+
sliderRangeValue: rangeValue,
|
|
363
|
+
isRestart: false,
|
|
364
|
+
isPlay: true
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (rangeValue <= overallSeconds) {
|
|
369
|
+
value && (this.audio.currentTime = value);
|
|
370
|
+
this.setState({
|
|
371
|
+
sliderRangeValue: rangeValue
|
|
372
|
+
}, () => afterUpdateCallback(rangeValue));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
updateTimerValues(sliderRangeValue) {
|
|
377
|
+
const {
|
|
378
|
+
hours,
|
|
379
|
+
minutes,
|
|
380
|
+
seconds
|
|
381
|
+
} = this.getAudioDurationDetails(Number(sliderRangeValue));
|
|
382
|
+
this.setState({
|
|
383
|
+
currentHour: hours,
|
|
384
|
+
currentMinute: minutes,
|
|
385
|
+
currentSecond: seconds
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
togglePlayer() {
|
|
390
|
+
this.audio.pause();
|
|
391
|
+
this.setState({
|
|
392
|
+
isPlay: false
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
handleKeyDown(e) {
|
|
397
|
+
const {
|
|
398
|
+
keyCode
|
|
399
|
+
} = e;
|
|
400
|
+
const {
|
|
401
|
+
sliderRangeValue
|
|
402
|
+
} = this.state;
|
|
403
|
+
const {
|
|
404
|
+
forwardStepInSec,
|
|
405
|
+
backwardStepInSec
|
|
406
|
+
} = this.props;
|
|
407
|
+
if (keyCode === 32) this.togglePlayPause();else if (keyCode === 39) this.updatePlayer(sliderRangeValue + forwardStepInSec);else if (keyCode === 37) this.updatePlayer(sliderRangeValue - backwardStepInSec);else if (keyCode === 27) this.togglePlayer();
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
downloadFile() {
|
|
411
|
+
const {
|
|
412
|
+
onDownloading,
|
|
413
|
+
src,
|
|
414
|
+
requestOptions
|
|
415
|
+
} = this.props;
|
|
416
|
+
|
|
417
|
+
const getFileName = (url, ext) => {
|
|
418
|
+
const parts = url.split('/');
|
|
419
|
+
const name = parts[parts.length - 1].split('?')[0];
|
|
420
|
+
return name.includes('.') ? name : `${name}.${ext}`;
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
const reqOptions = requestOptions || {
|
|
424
|
+
credentials: 'include'
|
|
425
|
+
};
|
|
426
|
+
fetch(src, reqOptions).then(resp => resp.blob()).then(blob => {
|
|
427
|
+
const url = window.URL.createObjectURL(blob);
|
|
428
|
+
const extnsn = blob.type.split('-')[1] || blob.type.split('/')[1];
|
|
429
|
+
const fileName = getFileName(src, extnsn);
|
|
430
|
+
const a = document.createElement('a');
|
|
431
|
+
a.style.display = 'none';
|
|
432
|
+
a.href = url;
|
|
433
|
+
a.download = fileName;
|
|
434
|
+
document.body.appendChild(a);
|
|
435
|
+
a.click();
|
|
436
|
+
window.URL.revokeObjectURL(url);
|
|
437
|
+
}).catch(() => openInNewTabWithNoopener(src));
|
|
438
|
+
onDownloading && onDownloading();
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
render() {
|
|
442
|
+
const {
|
|
443
|
+
isPlay,
|
|
444
|
+
currentHour,
|
|
445
|
+
currentMinute,
|
|
446
|
+
currentSecond,
|
|
447
|
+
audioHours,
|
|
448
|
+
audioMinutes,
|
|
449
|
+
audioSeconds,
|
|
450
|
+
isMuted,
|
|
451
|
+
disableControlIcons,
|
|
452
|
+
isShowDuration,
|
|
453
|
+
disableRangeSlider,
|
|
454
|
+
sliderRangeValue,
|
|
455
|
+
overallSeconds,
|
|
456
|
+
minValue,
|
|
457
|
+
step
|
|
458
|
+
} = this.state;
|
|
459
|
+
const {
|
|
460
|
+
src,
|
|
461
|
+
needDownload,
|
|
462
|
+
needClose,
|
|
463
|
+
needMuteIcon,
|
|
464
|
+
id,
|
|
465
|
+
i18nKeys,
|
|
466
|
+
dataId
|
|
467
|
+
} = this.props;
|
|
468
|
+
const timerFormat = audioHours ? 'hh:mm:ss' : 'mm:ss';
|
|
469
|
+
const loadingRange = (sliderRangeValue - minValue) * 100 / (overallSeconds - minValue);
|
|
470
|
+
const {
|
|
471
|
+
playTitle = 'Play',
|
|
472
|
+
pauseTitle = 'Pause',
|
|
473
|
+
downloadTitle = 'Download',
|
|
474
|
+
closeTitle = 'Close',
|
|
475
|
+
muteTitle = 'Mute',
|
|
476
|
+
unmuteTitle = 'Unmute'
|
|
477
|
+
} = i18nKeys;
|
|
478
|
+
return /*#__PURE__*/React.createElement(Container, {
|
|
479
|
+
align: "vertical",
|
|
480
|
+
alignBox: "row",
|
|
481
|
+
className: style.container,
|
|
482
|
+
isCover: false
|
|
483
|
+
}, /*#__PURE__*/React.createElement("audio", {
|
|
484
|
+
id: id,
|
|
485
|
+
controls: true,
|
|
486
|
+
preload: "auto",
|
|
487
|
+
className: style.audioHid,
|
|
488
|
+
ref: ele => this.audio = ele
|
|
489
|
+
}, /*#__PURE__*/React.createElement("source", {
|
|
490
|
+
src: src,
|
|
491
|
+
type: this.state.audioType
|
|
492
|
+
})), /*#__PURE__*/React.createElement(Box, {
|
|
493
|
+
className: `${style.rightBox} ${style.downloadBox} ${style.boxLeftRadius}`
|
|
494
|
+
}, /*#__PURE__*/React.createElement(Container, {
|
|
495
|
+
className: disableControlIcons ? style.disable : '',
|
|
496
|
+
align: "both",
|
|
497
|
+
onClick: this.togglePlayPause,
|
|
498
|
+
"data-title": isPlay ? pauseTitle : playTitle,
|
|
499
|
+
dataId: `${dataId}_playpause`
|
|
500
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
501
|
+
name: isPlay ? 'ZD-commentTimerPause' : 'ZD-bcarr',
|
|
502
|
+
iconClass: `${style.downloadIcon} ${style.iconColor}`
|
|
503
|
+
}))), /*#__PURE__*/React.createElement(Box, {
|
|
504
|
+
className: style.timerBox
|
|
505
|
+
}, /*#__PURE__*/React.createElement(Container, {
|
|
506
|
+
align: "vertical",
|
|
507
|
+
alignBox: "row"
|
|
508
|
+
}, /*#__PURE__*/React.createElement(Timer, {
|
|
509
|
+
timerFormat: timerFormat,
|
|
510
|
+
hour: currentHour,
|
|
511
|
+
minute: currentMinute,
|
|
512
|
+
second: currentSecond,
|
|
513
|
+
separator: "colon",
|
|
514
|
+
className: style.iconColor
|
|
515
|
+
}), isShowDuration && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Box, {
|
|
516
|
+
className: style.line
|
|
517
|
+
}, /*#__PURE__*/React.createElement("span", null, "\xA0"), "/", /*#__PURE__*/React.createElement("span", null, "\xA0")), /*#__PURE__*/React.createElement(Timer, {
|
|
518
|
+
timerFormat: timerFormat,
|
|
519
|
+
hour: audioHours,
|
|
520
|
+
minute: audioMinutes,
|
|
521
|
+
second: audioSeconds,
|
|
522
|
+
separator: "colon",
|
|
523
|
+
className: style.iconColor
|
|
524
|
+
})))), /*#__PURE__*/React.createElement(Box, {
|
|
525
|
+
className: `${style.dragtag} ${disableControlIcons || disableRangeSlider ? style.disable : style.cursor}`,
|
|
526
|
+
flexible: true
|
|
527
|
+
}, /*#__PURE__*/React.createElement(Container, {
|
|
528
|
+
className: style.audioRangeContainer
|
|
529
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
530
|
+
className: style.loading,
|
|
531
|
+
style: {
|
|
532
|
+
width: `${loadingRange}%`
|
|
533
|
+
}
|
|
534
|
+
}), /*#__PURE__*/React.createElement("input", {
|
|
535
|
+
"data-id": dataId,
|
|
536
|
+
ref: this.setInputRangeRef,
|
|
537
|
+
className: style.input,
|
|
538
|
+
type: "range",
|
|
539
|
+
value: sliderRangeValue,
|
|
540
|
+
min: minValue,
|
|
541
|
+
max: overallSeconds,
|
|
542
|
+
step: step,
|
|
543
|
+
onChange: this.updatePlayer
|
|
544
|
+
}))), needDownload && /*#__PURE__*/React.createElement(Box, {
|
|
545
|
+
className: `${style.rightBox} ${style.downloadBox} ${!needClose && !needMuteIcon ? style.boxRightRadius : ''}`
|
|
546
|
+
}, /*#__PURE__*/React.createElement(Container, {
|
|
547
|
+
className: disableControlIcons ? style.disable : '',
|
|
548
|
+
align: "both",
|
|
549
|
+
onClick: this.downloadFile,
|
|
550
|
+
"data-title": downloadTitle,
|
|
551
|
+
dataId: `${dataId}_download`
|
|
552
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
553
|
+
name: "ZD-downloadNew",
|
|
554
|
+
iconClass: `${style.downloadIcon} ${style.iconColor}`
|
|
555
|
+
}))), needMuteIcon && /*#__PURE__*/React.createElement(Box, {
|
|
556
|
+
className: `${style.rightBox} ${style.downloadBox} ${!needClose ? style.boxRightRadius : ''}`
|
|
557
|
+
}, /*#__PURE__*/React.createElement(Container, {
|
|
558
|
+
className: disableControlIcons ? style.disable : '',
|
|
559
|
+
align: "both",
|
|
560
|
+
onClick: this.onMuteUnmute,
|
|
561
|
+
"data-title": isMuted ? unmuteTitle : muteTitle,
|
|
562
|
+
dataId: `${dataId}_muteUnmute`
|
|
563
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
564
|
+
name: isMuted ? 'ZD-mute1New' : 'ZD-kbcatlogovolume',
|
|
565
|
+
iconClass: `${style.downloadIcon} ${style.iconColor}`
|
|
566
|
+
}))), needClose && /*#__PURE__*/React.createElement(Box, {
|
|
567
|
+
className: `${style.closeBox} ${style.boxRightRadius}`
|
|
568
|
+
}, /*#__PURE__*/React.createElement(Container, {
|
|
569
|
+
className: disableControlIcons ? style.disable : '',
|
|
570
|
+
align: "both",
|
|
571
|
+
onClick: this.handleClosePlayer,
|
|
572
|
+
"data-title": closeTitle,
|
|
573
|
+
dataId: `${dataId}_close`
|
|
574
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
575
|
+
name: "ZD-cross",
|
|
576
|
+
iconClass: `${style.pauseIcon} ${style.iconColor}`
|
|
577
|
+
}))));
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
}
|