apm-react-audio-player 1.0.1 → 1.0.3
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 +51 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,8 +6,35 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
var React = require('react');
|
|
8
8
|
var React__default = _interopDefault(React);
|
|
9
|
-
|
|
10
|
-
var
|
|
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
|
+
};
|
|
11
38
|
|
|
12
39
|
function _iterableToArrayLimit(arr, i) {
|
|
13
40
|
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
@@ -72,6 +99,10 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef) {
|
|
|
72
99
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
73
100
|
currentTime = _useState6[0],
|
|
74
101
|
setCurrentTime = _useState6[1];
|
|
102
|
+
var _useState7 = React.useState(false),
|
|
103
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
104
|
+
isFinishedPlaying = _useState8[0],
|
|
105
|
+
setIsFinishedPlaying = _useState8[1];
|
|
75
106
|
var animationRef = React.useRef(); // reference the animation
|
|
76
107
|
|
|
77
108
|
var onLoadedMetadata = function onLoadedMetadata() {
|
|
@@ -90,11 +121,13 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef) {
|
|
|
90
121
|
// when you reach the end of the song
|
|
91
122
|
if (progressBarRef.current.value === duration) {
|
|
92
123
|
restart();
|
|
124
|
+
setIsFinishedPlaying(true);
|
|
93
125
|
return;
|
|
94
126
|
}
|
|
95
127
|
animationRef.current = window.requestAnimationFrame(whilePlaying);
|
|
96
128
|
};
|
|
97
129
|
var pause = function pause() {
|
|
130
|
+
setIsPlaying(false);
|
|
98
131
|
audioRef.current.pause();
|
|
99
132
|
window.cancelAnimationFrame(animationRef.current);
|
|
100
133
|
};
|
|
@@ -104,6 +137,7 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef) {
|
|
|
104
137
|
pause();
|
|
105
138
|
};
|
|
106
139
|
var play = function play() {
|
|
140
|
+
setIsPlaying(true);
|
|
107
141
|
audioRef.current.play();
|
|
108
142
|
animationRef.current = window.requestAnimationFrame(whilePlaying);
|
|
109
143
|
};
|
|
@@ -115,9 +149,7 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef) {
|
|
|
115
149
|
return "".concat(returnedMinutes, ":").concat(returnedSeconds);
|
|
116
150
|
};
|
|
117
151
|
var togglePlaying = function togglePlaying() {
|
|
118
|
-
|
|
119
|
-
setIsPlaying(!prevState);
|
|
120
|
-
if (!prevState) {
|
|
152
|
+
if (!isPlaying) {
|
|
121
153
|
play();
|
|
122
154
|
} else {
|
|
123
155
|
pause();
|
|
@@ -147,30 +179,29 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef) {
|
|
|
147
179
|
backThirty: backThirty,
|
|
148
180
|
forwardThirty: forwardThirty,
|
|
149
181
|
isPlaying: isPlaying,
|
|
182
|
+
isFinished: isFinishedPlaying,
|
|
150
183
|
currentTime: currentTime,
|
|
151
184
|
duration: duration
|
|
152
185
|
};
|
|
153
186
|
};
|
|
154
187
|
|
|
155
188
|
var ReactAudioPlayer = function ReactAudioPlayer(props) {
|
|
189
|
+
var _props$audioPlayerRef, _props$progressBarRef;
|
|
156
190
|
// references
|
|
157
|
-
var
|
|
158
|
-
var
|
|
191
|
+
var audioPlayerRef = (_props$audioPlayerRef = props.audioPlayerRef) !== null && _props$audioPlayerRef !== void 0 ? _props$audioPlayerRef : React.useRef(); // reference our audio component
|
|
192
|
+
var progressBarRef = (_props$progressBarRef = props.progressBarRef) !== null && _props$progressBarRef !== void 0 ? _props$progressBarRef : React.useRef(); // reference our progress bar
|
|
159
193
|
|
|
160
194
|
var customStyles = props ? props.style : '';
|
|
161
195
|
var title = props.title,
|
|
162
196
|
description = props.description,
|
|
163
|
-
audioSrc = props.audioSrc
|
|
164
|
-
forwardBackward = props.forwardBackward;
|
|
197
|
+
audioSrc = props.audioSrc;
|
|
165
198
|
|
|
166
199
|
// hooks
|
|
167
|
-
var _useAudioPlayer = useAudioPlayer(
|
|
200
|
+
var _useAudioPlayer = useAudioPlayer(audioPlayerRef, progressBarRef),
|
|
168
201
|
onLoadedMetadata = _useAudioPlayer.onLoadedMetadata,
|
|
169
202
|
calculateTime = _useAudioPlayer.calculateTime,
|
|
170
203
|
togglePlaying = _useAudioPlayer.togglePlaying,
|
|
171
204
|
changePlayerCurrentTime = _useAudioPlayer.changePlayerCurrentTime,
|
|
172
|
-
backThirty = _useAudioPlayer.backThirty,
|
|
173
|
-
forwardThirty = _useAudioPlayer.forwardThirty,
|
|
174
205
|
isPlaying = _useAudioPlayer.isPlaying,
|
|
175
206
|
currentTime = _useAudioPlayer.currentTime,
|
|
176
207
|
duration = _useAudioPlayer.duration;
|
|
@@ -178,25 +209,19 @@ var ReactAudioPlayer = function ReactAudioPlayer(props) {
|
|
|
178
209
|
className: "audioPlayer",
|
|
179
210
|
style: customStyles && customStyles.audioPlayer
|
|
180
211
|
}, /*#__PURE__*/React__default.createElement("audio", {
|
|
181
|
-
ref:
|
|
212
|
+
ref: audioPlayerRef,
|
|
182
213
|
src: audioSrc,
|
|
183
214
|
preload: "metadata",
|
|
184
215
|
onLoadedMetadata: onLoadedMetadata
|
|
185
|
-
}),
|
|
186
|
-
className: "forwardBackward",
|
|
187
|
-
onClick: backThirty
|
|
188
|
-
}, "30", /*#__PURE__*/React__default.createElement(bs.BsArrowLeftShort, null)), /*#__PURE__*/React__default.createElement("div", {
|
|
216
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
|
189
217
|
className: "playPauseContainer"
|
|
190
218
|
}, /*#__PURE__*/React__default.createElement("button", {
|
|
191
219
|
onClick: togglePlaying,
|
|
192
220
|
className: "playPause",
|
|
193
221
|
style: customStyles && customStyles.playPause
|
|
194
|
-
}, isPlaying ? /*#__PURE__*/React__default.createElement(
|
|
222
|
+
}, isPlaying ? /*#__PURE__*/React__default.createElement(Pause, null) : /*#__PURE__*/React__default.createElement(Play, {
|
|
195
223
|
className: "play"
|
|
196
|
-
}))),
|
|
197
|
-
className: "forwardBackward",
|
|
198
|
-
onClick: forwardThirty
|
|
199
|
-
}, /*#__PURE__*/React__default.createElement(bs.BsArrowRightShort, null), "30"), /*#__PURE__*/React__default.createElement("div", {
|
|
224
|
+
}))), /*#__PURE__*/React__default.createElement("div", {
|
|
200
225
|
className: "currentTime"
|
|
201
226
|
}, calculateTime(currentTime)), /*#__PURE__*/React__default.createElement("div", {
|
|
202
227
|
className: "progressBarContainer"
|
|
@@ -204,7 +229,7 @@ var ReactAudioPlayer = function ReactAudioPlayer(props) {
|
|
|
204
229
|
type: "range",
|
|
205
230
|
className: "progressBar",
|
|
206
231
|
defaultValue: "0",
|
|
207
|
-
ref:
|
|
232
|
+
ref: progressBarRef,
|
|
208
233
|
onChange: changePlayerCurrentTime
|
|
209
234
|
})), /*#__PURE__*/React__default.createElement("div", {
|
|
210
235
|
className: "duration",
|
|
@@ -213,9 +238,10 @@ var ReactAudioPlayer = function ReactAudioPlayer(props) {
|
|
|
213
238
|
className: "textBox"
|
|
214
239
|
}, /*#__PURE__*/React__default.createElement("div", {
|
|
215
240
|
className: "textBoxTitle"
|
|
216
|
-
}, title || '
|
|
241
|
+
}, " ", title || '', " "), /*#__PURE__*/React__default.createElement("div", {
|
|
217
242
|
className: "textBoxDescription"
|
|
218
|
-
}, description || '
|
|
243
|
+
}, " ", description || '', " ")));
|
|
219
244
|
};
|
|
220
245
|
|
|
221
246
|
exports.ReactAudioPlayer = ReactAudioPlayer;
|
|
247
|
+
exports.useAudioPlayer = useAudioPlayer;
|