apm-react-audio-player 1.0.13 → 1.0.15
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/dist/index.js +441 -0
- package/package.json +1 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var React__default = _interopDefault(React);
|
|
9
|
+
|
|
10
|
+
function _iterableToArrayLimit(arr, i) {
|
|
11
|
+
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
12
|
+
if (null != _i) {
|
|
13
|
+
var _s,
|
|
14
|
+
_e,
|
|
15
|
+
_x,
|
|
16
|
+
_r,
|
|
17
|
+
_arr = [],
|
|
18
|
+
_n = !0,
|
|
19
|
+
_d = !1;
|
|
20
|
+
try {
|
|
21
|
+
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
22
|
+
if (Object(_i) !== _i) return;
|
|
23
|
+
_n = !1;
|
|
24
|
+
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
_d = !0, _e = err;
|
|
27
|
+
} finally {
|
|
28
|
+
try {
|
|
29
|
+
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
|
|
30
|
+
} finally {
|
|
31
|
+
if (_d) throw _e;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return _arr;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function _extends() {
|
|
38
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
39
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
40
|
+
var source = arguments[i];
|
|
41
|
+
for (var key in source) {
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
43
|
+
target[key] = source[key];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return target;
|
|
48
|
+
};
|
|
49
|
+
return _extends.apply(this, arguments);
|
|
50
|
+
}
|
|
51
|
+
function _slicedToArray(arr, i) {
|
|
52
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
53
|
+
}
|
|
54
|
+
function _arrayWithHoles(arr) {
|
|
55
|
+
if (Array.isArray(arr)) return arr;
|
|
56
|
+
}
|
|
57
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
58
|
+
if (!o) return;
|
|
59
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
60
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
61
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
62
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
63
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
64
|
+
}
|
|
65
|
+
function _arrayLikeToArray(arr, len) {
|
|
66
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
67
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
68
|
+
return arr2;
|
|
69
|
+
}
|
|
70
|
+
function _nonIterableRest() {
|
|
71
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtrl) {
|
|
75
|
+
var _useState = React.useState(false),
|
|
76
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
77
|
+
isPlaying = _useState2[0],
|
|
78
|
+
setIsPlaying = _useState2[1];
|
|
79
|
+
var _useState3 = React.useState(0),
|
|
80
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
81
|
+
duration = _useState4[0],
|
|
82
|
+
setDuration = _useState4[1];
|
|
83
|
+
var _useState5 = React.useState(0),
|
|
84
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
85
|
+
currentTime = _useState6[0],
|
|
86
|
+
setCurrentTime = _useState6[1];
|
|
87
|
+
var _useState7 = React.useState(false),
|
|
88
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
89
|
+
isFinishedPlaying = _useState8[0],
|
|
90
|
+
setIsFinishedPlaying = _useState8[1];
|
|
91
|
+
var animationRef = React.useRef(); // reference the animation
|
|
92
|
+
var _useState9 = React.useState(false),
|
|
93
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
94
|
+
isMuted = _useState10[0],
|
|
95
|
+
setIsMuted = _useState10[1];
|
|
96
|
+
var isStream = audioRef.current && audioRef.current.currentSrc.includes('stream');
|
|
97
|
+
React.useEffect(function () {
|
|
98
|
+
if (currentTime === Number(duration)) {
|
|
99
|
+
// restart()
|
|
100
|
+
setIsFinishedPlaying(true);
|
|
101
|
+
}
|
|
102
|
+
}, [currentTime]);
|
|
103
|
+
var onLoadedMetadata = function onLoadedMetadata() {
|
|
104
|
+
var seconds = Math.floor(audioRef.current.duration);
|
|
105
|
+
setDuration(seconds);
|
|
106
|
+
if (!isStream) {
|
|
107
|
+
progressBarRef.current.max = seconds;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var updateCurrentTime = function updateCurrentTime() {
|
|
111
|
+
setCurrentTime(progressBarRef.current.value);
|
|
112
|
+
};
|
|
113
|
+
var whilePlaying = function whilePlaying() {
|
|
114
|
+
if (!isStream) {
|
|
115
|
+
progressBarRef.current.value = Math.floor(audioRef.current.currentTime);
|
|
116
|
+
}
|
|
117
|
+
progressBarRef.current.style.setProperty('--seek-before-width', "".concat(progressBarRef.current.value / duration * 100, "%"));
|
|
118
|
+
updateCurrentTime();
|
|
119
|
+
|
|
120
|
+
// when you reach the end of the song
|
|
121
|
+
if (!isStream && progressBarRef.current.value === duration) {
|
|
122
|
+
// restart()
|
|
123
|
+
setIsFinishedPlaying(true);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
animationRef.current = window.requestAnimationFrame(whilePlaying);
|
|
127
|
+
};
|
|
128
|
+
var pause = function pause() {
|
|
129
|
+
setIsPlaying(false);
|
|
130
|
+
audioRef.current.pause();
|
|
131
|
+
window.cancelAnimationFrame(animationRef.current);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// const restart = () => {
|
|
135
|
+
// progressBarRef.current.value = 0
|
|
136
|
+
// updateCurrentTime()
|
|
137
|
+
// pause()
|
|
138
|
+
// }
|
|
139
|
+
|
|
140
|
+
var play = function play() {
|
|
141
|
+
setIsPlaying(true);
|
|
142
|
+
setIsFinishedPlaying(false);
|
|
143
|
+
audioRef.current.play();
|
|
144
|
+
if (!isStream) {
|
|
145
|
+
animationRef.current = window.requestAnimationFrame(whilePlaying);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var toggleMute = function toggleMute() {
|
|
149
|
+
setIsMuted(!isMuted);
|
|
150
|
+
};
|
|
151
|
+
var calculateTime = function calculateTime(secs) {
|
|
152
|
+
var minutes = Math.floor(secs / 60);
|
|
153
|
+
var returnedMinutes = minutes < 10 ? "0".concat(minutes) : "".concat(minutes);
|
|
154
|
+
var seconds = Math.floor(secs % 60);
|
|
155
|
+
var returnedSeconds = seconds < 10 ? "0".concat(seconds) : "".concat(seconds);
|
|
156
|
+
return "".concat(returnedMinutes, ":").concat(returnedSeconds);
|
|
157
|
+
};
|
|
158
|
+
var togglePlaying = function togglePlaying() {
|
|
159
|
+
if (!isPlaying) {
|
|
160
|
+
play();
|
|
161
|
+
} else {
|
|
162
|
+
pause();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var changePlayerCurrentTime = function changePlayerCurrentTime() {
|
|
166
|
+
audioRef.current.currentTime = progressBarRef.current.value;
|
|
167
|
+
setCurrentTime(progressBarRef.current.value);
|
|
168
|
+
progressBarRef.current.style.setProperty('--seek-before-width', "".concat(progressBarRef.current.value / duration * 100, "%"));
|
|
169
|
+
};
|
|
170
|
+
var changeRange = function changeRange() {
|
|
171
|
+
audioRef.current.currentTime = progressBarRef.current.value;
|
|
172
|
+
updateCurrentTime();
|
|
173
|
+
changePlayerCurrentTime();
|
|
174
|
+
};
|
|
175
|
+
var rewindControl = function rewindControl() {
|
|
176
|
+
progressBarRef.current.value = Number(progressBarRef.current.value) - 15;
|
|
177
|
+
changeRange();
|
|
178
|
+
};
|
|
179
|
+
var forwardControl = function forwardControl() {
|
|
180
|
+
progressBarRef.current.value = Number(progressBarRef.current.value) + 15;
|
|
181
|
+
changeRange();
|
|
182
|
+
};
|
|
183
|
+
var volumeControl = function volumeControl(e) {
|
|
184
|
+
var value = e.target.value;
|
|
185
|
+
var volume = value / 100;
|
|
186
|
+
audioRef.current.volume = volume;
|
|
187
|
+
};
|
|
188
|
+
var formatCalculateTime = function formatCalculateTime(timeString) {
|
|
189
|
+
var toString = String(timeString);
|
|
190
|
+
if (toString.split(':').length === 3) {
|
|
191
|
+
var _toString$split = toString.split(':'),
|
|
192
|
+
_toString$split2 = _slicedToArray(_toString$split, 3),
|
|
193
|
+
hours = _toString$split2[0],
|
|
194
|
+
minutes = _toString$split2[1],
|
|
195
|
+
seconds = _toString$split2[2];
|
|
196
|
+
return "".concat(parseInt(hours), "hr ").concat(parseInt(minutes), "min ").concat(parseInt(seconds), "sec");
|
|
197
|
+
} else if (toString.split(':').length === 2) {
|
|
198
|
+
var _toString$split3 = toString.split(':'),
|
|
199
|
+
_toString$split4 = _slicedToArray(_toString$split3, 2),
|
|
200
|
+
_minutes = _toString$split4[0],
|
|
201
|
+
_seconds = _toString$split4[1];
|
|
202
|
+
return "".concat(parseInt(_minutes), "min ").concat(parseInt(_seconds), "sec");
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
onLoadedMetadata: onLoadedMetadata,
|
|
207
|
+
calculateTime: calculateTime,
|
|
208
|
+
togglePlaying: togglePlaying,
|
|
209
|
+
changePlayerCurrentTime: changePlayerCurrentTime,
|
|
210
|
+
rewindControl: rewindControl,
|
|
211
|
+
forwardControl: forwardControl,
|
|
212
|
+
play: play,
|
|
213
|
+
pause: pause,
|
|
214
|
+
isPlaying: isPlaying,
|
|
215
|
+
isFinishedPlaying: isFinishedPlaying,
|
|
216
|
+
currentTime: currentTime,
|
|
217
|
+
duration: duration,
|
|
218
|
+
volumeCtrl: volumeCtrl,
|
|
219
|
+
isMuted: isMuted,
|
|
220
|
+
volumeControl: volumeControl,
|
|
221
|
+
toggleMute: toggleMute,
|
|
222
|
+
formatCalculateTime: formatCalculateTime
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
var Play = function Play() {
|
|
227
|
+
return /*#__PURE__*/React__default.createElement("svg", {
|
|
228
|
+
stroke: "currentColor",
|
|
229
|
+
fill: "currentColor",
|
|
230
|
+
strokeWidth: "0",
|
|
231
|
+
viewBox: "0 0 448 512",
|
|
232
|
+
className: "play",
|
|
233
|
+
height: "1em",
|
|
234
|
+
width: "1em",
|
|
235
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
236
|
+
role: "img",
|
|
237
|
+
"aria-labelledby": "play playButton"
|
|
238
|
+
}, /*#__PURE__*/React__default.createElement("title", {
|
|
239
|
+
id: "play"
|
|
240
|
+
}, "Play"), /*#__PURE__*/React__default.createElement("desc", {
|
|
241
|
+
id: "playButton"
|
|
242
|
+
}, "Play Button"), /*#__PURE__*/React__default.createElement("path", {
|
|
243
|
+
d: "M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"
|
|
244
|
+
}));
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
var Pause = function Pause() {
|
|
248
|
+
return /*#__PURE__*/React__default.createElement("svg", {
|
|
249
|
+
stroke: "currentColor",
|
|
250
|
+
fill: "currentColor",
|
|
251
|
+
strokeWidth: "0",
|
|
252
|
+
viewBox: "0 0 448 512",
|
|
253
|
+
height: "1em",
|
|
254
|
+
width: "1em",
|
|
255
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
256
|
+
role: "img",
|
|
257
|
+
"aria-labelledby": "pause pauseButton"
|
|
258
|
+
}, /*#__PURE__*/React__default.createElement("title", {
|
|
259
|
+
id: "pause"
|
|
260
|
+
}, "Pause"), /*#__PURE__*/React__default.createElement("desc", {
|
|
261
|
+
id: "pauseButton"
|
|
262
|
+
}, "Pause Button"), /*#__PURE__*/React__default.createElement("path", {
|
|
263
|
+
d: "M144 479H48c-26.5 0-48-21.5-48-48V79c0-26.5 21.5-48 48-48h96c26.5 0 48 21.5 48 48v352c0 26.5-21.5 48-48 48zm304-48V79c0-26.5-21.5-48-48-48h-96c-26.5 0-48 21.5-48 48v352c0 26.5 21.5 48 48 48h96c26.5 0 48-21.5 48-48z"
|
|
264
|
+
}));
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
var ReactAudioPlayerInner = function ReactAudioPlayerInner(props) {
|
|
268
|
+
var _props$audioPlayerRef, _props$progressBarRef;
|
|
269
|
+
// references
|
|
270
|
+
var audioPlayerRef = (_props$audioPlayerRef = props.audioPlayerRef) !== null && _props$audioPlayerRef !== void 0 ? _props$audioPlayerRef : React.useRef(); // reference our audio component
|
|
271
|
+
var progressBarRef = (_props$progressBarRef = props.progressBarRef) !== null && _props$progressBarRef !== void 0 ? _props$progressBarRef : React.useRef(); // reference our progress bar
|
|
272
|
+
|
|
273
|
+
var customStyles = props ? props.style : '';
|
|
274
|
+
var title = props.title,
|
|
275
|
+
audioSrc = props.audioSrc,
|
|
276
|
+
volumeCtrl = props.volumeCtrl,
|
|
277
|
+
playBtnClass = props.playBtnClass,
|
|
278
|
+
customHtml = props.customHtml,
|
|
279
|
+
isLive = props.isLive,
|
|
280
|
+
onLoadedMetadata = props.onLoadedMetadata,
|
|
281
|
+
calculateTime = props.calculateTime,
|
|
282
|
+
togglePlaying = props.togglePlaying,
|
|
283
|
+
changePlayerCurrentTime = props.changePlayerCurrentTime,
|
|
284
|
+
isPlaying = props.isPlaying,
|
|
285
|
+
currentTime = props.currentTime,
|
|
286
|
+
duration = props.duration,
|
|
287
|
+
volumeControl = props.volumeControl,
|
|
288
|
+
toggleMute = props.toggleMute,
|
|
289
|
+
isMuted = props.isMuted,
|
|
290
|
+
formatCalculateTime = props.formatCalculateTime,
|
|
291
|
+
rewindControl = props.rewindControl,
|
|
292
|
+
forwardControl = props.forwardControl;
|
|
293
|
+
var audioDuration = duration && !isNaN(duration) && calculateTime(duration);
|
|
294
|
+
var formatDuration = duration && !isNaN(duration) && audioDuration && formatCalculateTime(audioDuration);
|
|
295
|
+
return audioSrc && /*#__PURE__*/React__default.createElement("div", {
|
|
296
|
+
className: "audioPlayer",
|
|
297
|
+
style: customStyles && customStyles.audioPlayer
|
|
298
|
+
}, /*#__PURE__*/React__default.createElement("audio", {
|
|
299
|
+
ref: audioPlayerRef,
|
|
300
|
+
src: audioSrc,
|
|
301
|
+
preload: "metadata",
|
|
302
|
+
onLoadedMetadata: onLoadedMetadata,
|
|
303
|
+
muted: isMuted
|
|
304
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
|
305
|
+
className: "player-layout"
|
|
306
|
+
}, volumeCtrl && /*#__PURE__*/React__default.createElement("div", {
|
|
307
|
+
className: "player-controls-secondary-outer"
|
|
308
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
309
|
+
className: "player-volume-control"
|
|
310
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
311
|
+
className: "player-volume-icon"
|
|
312
|
+
}, /*#__PURE__*/React__default.createElement("button", {
|
|
313
|
+
onClick: toggleMute,
|
|
314
|
+
"aria-label": isMuted === true ? 'Muted' : 'Not Muted',
|
|
315
|
+
title: isMuted === true ? 'Muted' : 'Not Muted'
|
|
316
|
+
}, !isMuted ? /*#__PURE__*/React__default.createElement("img", {
|
|
317
|
+
src: "/img/icon-volume-low.svg",
|
|
318
|
+
alt: "Volume Button"
|
|
319
|
+
}) : /*#__PURE__*/React__default.createElement("img", {
|
|
320
|
+
src: "/img/icon-volume-mute.svg",
|
|
321
|
+
alt: "Volume Mute Button"
|
|
322
|
+
}))), /*#__PURE__*/React__default.createElement("div", {
|
|
323
|
+
className: "player-timeline player-controls-secondary"
|
|
324
|
+
}, /*#__PURE__*/React__default.createElement("input", {
|
|
325
|
+
id: "player-volume",
|
|
326
|
+
type: "range",
|
|
327
|
+
className: "player-volume-progress",
|
|
328
|
+
min: 0,
|
|
329
|
+
max: 100,
|
|
330
|
+
"aria-hidden": "true",
|
|
331
|
+
"aria-valuetext": "100%",
|
|
332
|
+
onChange: function onChange(e) {
|
|
333
|
+
return volumeControl(e);
|
|
334
|
+
}
|
|
335
|
+
})), /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("img", {
|
|
336
|
+
src: "/img/icon-volume-high.svg",
|
|
337
|
+
alt: "Volume Button"
|
|
338
|
+
}))), /*#__PURE__*/React__default.createElement("div", {
|
|
339
|
+
className: "player-volume-label"
|
|
340
|
+
}, "Volume")), /*#__PURE__*/React__default.createElement("div", {
|
|
341
|
+
className: "player-controls"
|
|
342
|
+
}, !isLive && /*#__PURE__*/React__default.createElement("div", {
|
|
343
|
+
className: "player-backward-forward-controls"
|
|
344
|
+
}, /*#__PURE__*/React__default.createElement("button", {
|
|
345
|
+
onClick: rewindControl
|
|
346
|
+
}, /*#__PURE__*/React__default.createElement("img", {
|
|
347
|
+
src: "/img/icon-rewind-15.svg",
|
|
348
|
+
alt: "Backward 15 seconds"
|
|
349
|
+
}))), /*#__PURE__*/React__default.createElement("div", {
|
|
350
|
+
className: "".concat(isPlaying ? 'is-playing' : '', " player-btn-play-pause-outer")
|
|
351
|
+
}, /*#__PURE__*/React__default.createElement("button", {
|
|
352
|
+
onClick: togglePlaying,
|
|
353
|
+
className: playBtnClass,
|
|
354
|
+
style: customStyles && customStyles.playPause
|
|
355
|
+
}, isPlaying ? /*#__PURE__*/React__default.createElement(Pause, null) : /*#__PURE__*/React__default.createElement(Play, null))), !isLive && /*#__PURE__*/React__default.createElement("div", {
|
|
356
|
+
className: "player-backward-forward-controls"
|
|
357
|
+
}, /*#__PURE__*/React__default.createElement("button", {
|
|
358
|
+
onClick: forwardControl
|
|
359
|
+
}, /*#__PURE__*/React__default.createElement("img", {
|
|
360
|
+
src: "/img/icon-forward-15.svg",
|
|
361
|
+
alt: "Forward 15 seconds"
|
|
362
|
+
})))), !isLive && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
|
|
363
|
+
className: "player-timeline"
|
|
364
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
365
|
+
className: "player-timeline-progress-outer"
|
|
366
|
+
}, /*#__PURE__*/React__default.createElement("input", {
|
|
367
|
+
type: "range",
|
|
368
|
+
className: "player-timeline-progress",
|
|
369
|
+
defaultValue: "0",
|
|
370
|
+
ref: progressBarRef,
|
|
371
|
+
onChange: changePlayerCurrentTime,
|
|
372
|
+
"aria-label": "Audio progress",
|
|
373
|
+
max: duration
|
|
374
|
+
})), /*#__PURE__*/React__default.createElement("div", {
|
|
375
|
+
className: "player-times"
|
|
376
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
377
|
+
className: "player-currentTime"
|
|
378
|
+
}, calculateTime(currentTime)), /*#__PURE__*/React__default.createElement("div", {
|
|
379
|
+
className: "player-duration",
|
|
380
|
+
style: customStyles && customStyles.duration
|
|
381
|
+
}, duration && !isNaN(duration) && calculateTime(duration))))), /*#__PURE__*/React__default.createElement("div", {
|
|
382
|
+
className: "player-content"
|
|
383
|
+
}, customHtml && customHtml, /*#__PURE__*/React__default.createElement("div", {
|
|
384
|
+
className: "player-audio-type type-sm"
|
|
385
|
+
}, isLive ? /*#__PURE__*/React__default.createElement("div", {
|
|
386
|
+
className: "player-live-label"
|
|
387
|
+
}, "On Air") : /*#__PURE__*/React__default.createElement("div", {
|
|
388
|
+
className: "player-label"
|
|
389
|
+
}, "listen", /*#__PURE__*/React__default.createElement("div", {
|
|
390
|
+
className: "player-label-duration"
|
|
391
|
+
}, "[".concat(formatDuration, "]"))), /*#__PURE__*/React__default.createElement("div", {
|
|
392
|
+
className: "player-title"
|
|
393
|
+
}, title || '', " ")))));
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
var ReactAudioPlayer = function ReactAudioPlayer(props) {
|
|
397
|
+
var _props$audioPlayerRef, _props$progressBarRef;
|
|
398
|
+
// references
|
|
399
|
+
var audioPlayerRef = (_props$audioPlayerRef = props.audioPlayerRef) !== null && _props$audioPlayerRef !== void 0 ? _props$audioPlayerRef : React.useRef(); // reference our audio component
|
|
400
|
+
var progressBarRef = (_props$progressBarRef = props.progressBarRef) !== null && _props$progressBarRef !== void 0 ? _props$progressBarRef : React.useRef(); // reference our progress bar
|
|
401
|
+
|
|
402
|
+
var customStyles = props ? props.style : '';
|
|
403
|
+
|
|
404
|
+
// hooks
|
|
405
|
+
var _useAudioPlayer = useAudioPlayer(audioPlayerRef, progressBarRef),
|
|
406
|
+
onLoadedMetadata = _useAudioPlayer.onLoadedMetadata,
|
|
407
|
+
calculateTime = _useAudioPlayer.calculateTime,
|
|
408
|
+
togglePlaying = _useAudioPlayer.togglePlaying,
|
|
409
|
+
changePlayerCurrentTime = _useAudioPlayer.changePlayerCurrentTime,
|
|
410
|
+
isPlaying = _useAudioPlayer.isPlaying,
|
|
411
|
+
currentTime = _useAudioPlayer.currentTime,
|
|
412
|
+
duration = _useAudioPlayer.duration,
|
|
413
|
+
volumeControl = _useAudioPlayer.volumeControl,
|
|
414
|
+
toggleMute = _useAudioPlayer.toggleMute,
|
|
415
|
+
isMuted = _useAudioPlayer.isMuted,
|
|
416
|
+
formatCalculateTime = _useAudioPlayer.formatCalculateTime,
|
|
417
|
+
rewindControl = _useAudioPlayer.rewindControl,
|
|
418
|
+
forwardControl = _useAudioPlayer.forwardControl;
|
|
419
|
+
return /*#__PURE__*/React__default.createElement(ReactAudioPlayerInner, _extends({}, props, {
|
|
420
|
+
audioPlayerRef: audioPlayerRef,
|
|
421
|
+
progressBarRef: progressBarRef,
|
|
422
|
+
isPlaying: isPlaying,
|
|
423
|
+
isMuted: isMuted,
|
|
424
|
+
currentTime: currentTime,
|
|
425
|
+
duration: duration,
|
|
426
|
+
customStyles: customStyles,
|
|
427
|
+
onLoadedMetadata: onLoadedMetadata,
|
|
428
|
+
calculateTime: calculateTime,
|
|
429
|
+
togglePlaying: togglePlaying,
|
|
430
|
+
changePlayerCurrentTime: changePlayerCurrentTime,
|
|
431
|
+
volumeControl: volumeControl,
|
|
432
|
+
toggleMute: toggleMute,
|
|
433
|
+
formatCalculateTime: formatCalculateTime,
|
|
434
|
+
rewindControl: rewindControl,
|
|
435
|
+
forwardControl: forwardControl
|
|
436
|
+
}));
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
exports.ReactAudioPlayer = ReactAudioPlayer;
|
|
440
|
+
exports.ReactAudioPlayerInner = ReactAudioPlayerInner;
|
|
441
|
+
exports.useAudioPlayer = useAudioPlayer;
|