apm-react-audio-player 1.0.6 → 1.0.8
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 +127 -49
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,35 +7,6 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var React__default = _interopDefault(React);
|
|
9
9
|
|
|
10
|
-
var Play = function Play() {
|
|
11
|
-
return /*#__PURE__*/React__default.createElement("svg", {
|
|
12
|
-
stroke: "currentColor",
|
|
13
|
-
fill: "currentColor",
|
|
14
|
-
strokeWidth: "0",
|
|
15
|
-
viewBox: "0 0 448 512",
|
|
16
|
-
className: "play",
|
|
17
|
-
height: "1em",
|
|
18
|
-
width: "1em",
|
|
19
|
-
xmlns: "http://www.w3.org/2000/svg"
|
|
20
|
-
}, /*#__PURE__*/React__default.createElement("path", {
|
|
21
|
-
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"
|
|
22
|
-
}));
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
var Pause = function Pause() {
|
|
26
|
-
return /*#__PURE__*/React__default.createElement("svg", {
|
|
27
|
-
stroke: "currentColor",
|
|
28
|
-
fill: "currentColor",
|
|
29
|
-
strokeWidth: "0",
|
|
30
|
-
viewBox: "0 0 448 512",
|
|
31
|
-
height: "1em",
|
|
32
|
-
width: "1em",
|
|
33
|
-
xmlns: "http://www.w3.org/2000/svg"
|
|
34
|
-
}, /*#__PURE__*/React__default.createElement("path", {
|
|
35
|
-
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"
|
|
36
|
-
}));
|
|
37
|
-
};
|
|
38
|
-
|
|
39
10
|
function _iterableToArrayLimit(arr, i) {
|
|
40
11
|
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
41
12
|
if (null != _i) {
|
|
@@ -63,6 +34,20 @@ function _iterableToArrayLimit(arr, i) {
|
|
|
63
34
|
return _arr;
|
|
64
35
|
}
|
|
65
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
|
+
}
|
|
66
51
|
function _slicedToArray(arr, i) {
|
|
67
52
|
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
68
53
|
}
|
|
@@ -104,7 +89,16 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
|
|
|
104
89
|
isFinishedPlaying = _useState8[0],
|
|
105
90
|
setIsFinishedPlaying = _useState8[1];
|
|
106
91
|
var animationRef = React.useRef(); // reference the animation
|
|
107
|
-
|
|
92
|
+
var _useState9 = React.useState(false),
|
|
93
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
94
|
+
isMuted = _useState10[0],
|
|
95
|
+
setIsMuted = _useState10[1];
|
|
96
|
+
React.useEffect(function () {
|
|
97
|
+
if (currentTime === Number(duration)) {
|
|
98
|
+
restart();
|
|
99
|
+
setIsFinishedPlaying(true);
|
|
100
|
+
}
|
|
101
|
+
}, [currentTime]);
|
|
108
102
|
var onLoadedMetadata = function onLoadedMetadata() {
|
|
109
103
|
var seconds = Math.floor(audioRef.current.duration);
|
|
110
104
|
setDuration(seconds);
|
|
@@ -140,9 +134,13 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
|
|
|
140
134
|
};
|
|
141
135
|
var play = function play() {
|
|
142
136
|
setIsPlaying(true);
|
|
137
|
+
setIsFinishedPlaying(false);
|
|
143
138
|
audioRef.current.play();
|
|
144
139
|
animationRef.current = window.requestAnimationFrame(whilePlaying);
|
|
145
140
|
};
|
|
141
|
+
var toggleMute = function toggleMute() {
|
|
142
|
+
setIsMuted(!isMuted);
|
|
143
|
+
};
|
|
146
144
|
var calculateTime = function calculateTime(secs) {
|
|
147
145
|
var minutes = Math.floor(secs / 60);
|
|
148
146
|
var returnedMinutes = minutes < 10 ? "0".concat(minutes) : "".concat(minutes);
|
|
@@ -185,16 +183,49 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
|
|
|
185
183
|
changePlayerCurrentTime: changePlayerCurrentTime,
|
|
186
184
|
backThirty: backThirty,
|
|
187
185
|
forwardThirty: forwardThirty,
|
|
186
|
+
play: play,
|
|
187
|
+
pause: pause,
|
|
188
188
|
isPlaying: isPlaying,
|
|
189
|
-
|
|
189
|
+
isFinishedPlaying: isFinishedPlaying,
|
|
190
190
|
currentTime: currentTime,
|
|
191
191
|
duration: duration,
|
|
192
192
|
volumeCtrl: volumeCtrl,
|
|
193
|
-
volumeControl: volumeControl
|
|
193
|
+
volumeControl: volumeControl,
|
|
194
|
+
toggleMute: toggleMute,
|
|
195
|
+
isMuted: isMuted
|
|
194
196
|
};
|
|
195
197
|
};
|
|
196
198
|
|
|
197
|
-
var
|
|
199
|
+
var Play = function Play() {
|
|
200
|
+
return /*#__PURE__*/React__default.createElement("svg", {
|
|
201
|
+
stroke: "currentColor",
|
|
202
|
+
fill: "currentColor",
|
|
203
|
+
strokeWidth: "0",
|
|
204
|
+
viewBox: "0 0 448 512",
|
|
205
|
+
className: "play",
|
|
206
|
+
height: "1em",
|
|
207
|
+
width: "1em",
|
|
208
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
209
|
+
}, /*#__PURE__*/React__default.createElement("path", {
|
|
210
|
+
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"
|
|
211
|
+
}));
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
var Pause = function Pause() {
|
|
215
|
+
return /*#__PURE__*/React__default.createElement("svg", {
|
|
216
|
+
stroke: "currentColor",
|
|
217
|
+
fill: "currentColor",
|
|
218
|
+
strokeWidth: "0",
|
|
219
|
+
viewBox: "0 0 448 512",
|
|
220
|
+
height: "1em",
|
|
221
|
+
width: "1em",
|
|
222
|
+
xmlns: "http://www.w3.org/2000/svg"
|
|
223
|
+
}, /*#__PURE__*/React__default.createElement("path", {
|
|
224
|
+
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"
|
|
225
|
+
}));
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
var ReactAudioPlayerInner = function ReactAudioPlayerInner(props) {
|
|
198
229
|
var _props$audioPlayerRef, _props$progressBarRef;
|
|
199
230
|
// references
|
|
200
231
|
var audioPlayerRef = (_props$audioPlayerRef = props.audioPlayerRef) !== null && _props$audioPlayerRef !== void 0 ? _props$audioPlayerRef : React.useRef(); // reference our audio component
|
|
@@ -207,18 +238,17 @@ var ReactAudioPlayer = function ReactAudioPlayer(props) {
|
|
|
207
238
|
volumeCtrl = props.volumeCtrl,
|
|
208
239
|
playBtnClass = props.playBtnClass,
|
|
209
240
|
customHtml = props.customHtml,
|
|
210
|
-
isLive = props.isLive
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
volumeControl = _useAudioPlayer.volumeControl;
|
|
241
|
+
isLive = props.isLive,
|
|
242
|
+
onLoadedMetadata = props.onLoadedMetadata,
|
|
243
|
+
calculateTime = props.calculateTime,
|
|
244
|
+
togglePlaying = props.togglePlaying,
|
|
245
|
+
changePlayerCurrentTime = props.changePlayerCurrentTime,
|
|
246
|
+
isPlaying = props.isPlaying,
|
|
247
|
+
currentTime = props.currentTime,
|
|
248
|
+
duration = props.duration,
|
|
249
|
+
volumeControl = props.volumeControl,
|
|
250
|
+
toggleMute = props.toggleMute,
|
|
251
|
+
isMuted = props.isMuted;
|
|
222
252
|
return audioSrc && /*#__PURE__*/React__default.createElement("div", {
|
|
223
253
|
className: "audioPlayer",
|
|
224
254
|
style: customStyles && customStyles.audioPlayer
|
|
@@ -226,17 +256,27 @@ var ReactAudioPlayer = function ReactAudioPlayer(props) {
|
|
|
226
256
|
ref: audioPlayerRef,
|
|
227
257
|
src: audioSrc,
|
|
228
258
|
preload: "metadata",
|
|
229
|
-
onLoadedMetadata: onLoadedMetadata
|
|
259
|
+
onLoadedMetadata: onLoadedMetadata,
|
|
260
|
+
muted: isMuted
|
|
230
261
|
}), /*#__PURE__*/React__default.createElement("div", {
|
|
231
262
|
className: "player-layout"
|
|
232
263
|
}, volumeCtrl && /*#__PURE__*/React__default.createElement("div", {
|
|
233
264
|
className: "player-controls-secondary-outer"
|
|
234
265
|
}, /*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement("span", {
|
|
235
266
|
className: "player-volume-text"
|
|
236
|
-
}, /*#__PURE__*/React__default.createElement("
|
|
267
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
268
|
+
className: "player-volume-icon"
|
|
269
|
+
}, /*#__PURE__*/React__default.createElement("button", {
|
|
270
|
+
onClick: toggleMute,
|
|
271
|
+
"aria-label": isMuted === true ? 'Muted' : 'Not Muted',
|
|
272
|
+
title: isMuted === true ? 'Muted' : 'Not Muted'
|
|
273
|
+
}, !isMuted ? /*#__PURE__*/React__default.createElement("img", {
|
|
237
274
|
src: "/img/icon-volume-low.svg",
|
|
238
|
-
alt: ""
|
|
239
|
-
})
|
|
275
|
+
alt: "Volume Button"
|
|
276
|
+
}) : /*#__PURE__*/React__default.createElement("img", {
|
|
277
|
+
src: "/img/icon-volume-mute.svg",
|
|
278
|
+
alt: "Volume Mute Button"
|
|
279
|
+
}))), /*#__PURE__*/React__default.createElement("span", null, "Volume")), /*#__PURE__*/React__default.createElement("div", {
|
|
240
280
|
className: "player-controls player-controls-secondary"
|
|
241
281
|
}, /*#__PURE__*/React__default.createElement("div", {
|
|
242
282
|
className: "player-volume"
|
|
@@ -285,5 +325,43 @@ var ReactAudioPlayer = function ReactAudioPlayer(props) {
|
|
|
285
325
|
}, description || '', " ")))));
|
|
286
326
|
};
|
|
287
327
|
|
|
328
|
+
var ReactAudioPlayer = function ReactAudioPlayer(props) {
|
|
329
|
+
var _props$audioPlayerRef, _props$progressBarRef;
|
|
330
|
+
// references
|
|
331
|
+
var audioPlayerRef = (_props$audioPlayerRef = props.audioPlayerRef) !== null && _props$audioPlayerRef !== void 0 ? _props$audioPlayerRef : React.useRef(); // reference our audio component
|
|
332
|
+
var progressBarRef = (_props$progressBarRef = props.progressBarRef) !== null && _props$progressBarRef !== void 0 ? _props$progressBarRef : React.useRef(); // reference our progress bar
|
|
333
|
+
|
|
334
|
+
var customStyles = props ? props.style : '';
|
|
335
|
+
|
|
336
|
+
// hooks
|
|
337
|
+
var _useAudioPlayer = useAudioPlayer(audioPlayerRef, progressBarRef),
|
|
338
|
+
onLoadedMetadata = _useAudioPlayer.onLoadedMetadata,
|
|
339
|
+
calculateTime = _useAudioPlayer.calculateTime,
|
|
340
|
+
togglePlaying = _useAudioPlayer.togglePlaying,
|
|
341
|
+
changePlayerCurrentTime = _useAudioPlayer.changePlayerCurrentTime,
|
|
342
|
+
isPlaying = _useAudioPlayer.isPlaying,
|
|
343
|
+
currentTime = _useAudioPlayer.currentTime,
|
|
344
|
+
duration = _useAudioPlayer.duration,
|
|
345
|
+
volumeControl = _useAudioPlayer.volumeControl,
|
|
346
|
+
toggleMute = _useAudioPlayer.toggleMute,
|
|
347
|
+
isMuted = _useAudioPlayer.isMuted;
|
|
348
|
+
return /*#__PURE__*/React__default.createElement(ReactAudioPlayerInner, _extends({}, props, {
|
|
349
|
+
audioPlayerRef: audioPlayerRef,
|
|
350
|
+
progressBarRef: progressBarRef,
|
|
351
|
+
customStyles: customStyles,
|
|
352
|
+
onLoadedMetadata: onLoadedMetadata,
|
|
353
|
+
calculateTime: calculateTime,
|
|
354
|
+
togglePlaying: togglePlaying,
|
|
355
|
+
changePlayerCurrentTime: changePlayerCurrentTime,
|
|
356
|
+
isPlaying: isPlaying,
|
|
357
|
+
currentTime: currentTime,
|
|
358
|
+
duration: duration,
|
|
359
|
+
volumeControl: volumeControl,
|
|
360
|
+
toggleMute: toggleMute,
|
|
361
|
+
isMuted: isMuted
|
|
362
|
+
}));
|
|
363
|
+
};
|
|
364
|
+
|
|
288
365
|
exports.ReactAudioPlayer = ReactAudioPlayer;
|
|
366
|
+
exports.ReactAudioPlayerInner = ReactAudioPlayerInner;
|
|
289
367
|
exports.useAudioPlayer = useAudioPlayer;
|