apm-react-audio-player 1.1.1 → 1.1.2

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 CHANGED
@@ -27,15 +27,15 @@ function _iterableToArrayLimit(r, l) {
27
27
  i,
28
28
  u,
29
29
  a = [],
30
- f = true,
31
- o = false;
30
+ f = !0,
31
+ o = !1;
32
32
  try {
33
33
  if (i = (t = t.call(r)).next, 0 === l) {
34
34
  if (Object(t) !== t) return;
35
35
  f = !1;
36
36
  } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
37
37
  } catch (r) {
38
- o = true, n = r;
38
+ o = !0, n = r;
39
39
  } finally {
40
40
  try {
41
41
  if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
@@ -104,6 +104,13 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
104
104
  progressBarRef.current.max = seconds;
105
105
  }
106
106
  };
107
+ var resetDuration = function resetDuration() {
108
+ setDuration(undefined);
109
+ setCurrentTime(0);
110
+ if (progressBarRef.current) {
111
+ progressBarRef.current.value = 0;
112
+ }
113
+ };
107
114
  var updateCurrentTime = function updateCurrentTime() {
108
115
  if (progressBarRef.current) {
109
116
  setCurrentTime(progressBarRef.current.value);
@@ -114,9 +121,10 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
114
121
  if (!progressBarRef.current || !audioRef.current) {
115
122
  return;
116
123
  }
117
- if (audioRef.current.duration !== Infinity) {
124
+ var liveDuration = audioRef.current.duration;
125
+ if (liveDuration !== Infinity) {
118
126
  progressBarRef.current.value = Math.floor(audioRef.current.currentTime);
119
- progressBarRef.current.style.setProperty('--seek-before-width', "".concat(progressBarRef.current.value / duration * 100, "%"));
127
+ progressBarRef.current.style.setProperty('--seek-before-width', liveDuration > 0 ? "".concat(progressBarRef.current.value / liveDuration * 100, "%") : '0%');
120
128
  }
121
129
  updateCurrentTime();
122
130
 
@@ -183,7 +191,8 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
183
191
  if (!progressBarRef.current || !audioRef.current) return;
184
192
  audioRef.current.currentTime = progressBarRef.current.value;
185
193
  setCurrentTime(progressBarRef.current.value);
186
- progressBarRef.current.style.setProperty('--seek-before-width', "".concat(progressBarRef.current.value / duration * 100, "%"));
194
+ var liveDuration = audioRef.current.duration;
195
+ progressBarRef.current.style.setProperty('--seek-before-width', liveDuration > 0 ? "".concat(progressBarRef.current.value / liveDuration * 100, "%") : '0%');
187
196
  };
188
197
  var changeRange = function changeRange() {
189
198
  if (!progressBarRef.current || !audioRef.current) return;
@@ -226,6 +235,7 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
226
235
  };
227
236
  return {
228
237
  onLoadedMetadata: onLoadedMetadata,
238
+ resetDuration: resetDuration,
229
239
  calculateTime: calculateTime,
230
240
  togglePlaying: togglePlaying,
231
241
  changePlayerCurrentTime: changePlayerCurrentTime,
@@ -317,6 +327,7 @@ var ReactAudioPlayerInner = function ReactAudioPlayerInner(props) {
317
327
  playBtnClass = props.playBtnClass,
318
328
  customHtml = props.customHtml,
319
329
  onLoadedMetadata = props.onLoadedMetadata,
330
+ resetDuration = props.resetDuration,
320
331
  calculateTime = props.calculateTime,
321
332
  togglePlaying = props.togglePlaying,
322
333
  changePlayerCurrentTime = props.changePlayerCurrentTime,
@@ -338,6 +349,7 @@ var ReactAudioPlayerInner = function ReactAudioPlayerInner(props) {
338
349
  // Use JSON.stringify to handle array comparisons by value instead of reference
339
350
  React.useEffect(function () {
340
351
  if (audioPlayerRef.current && audioSrc) {
352
+ resetDuration === null || resetDuration === void 0 ? void 0 : resetDuration();
341
353
  try {
342
354
  audioPlayerRef.current.load();
343
355
  } catch (err) {
@@ -25,15 +25,15 @@ function _iterableToArrayLimit(r, l) {
25
25
  i,
26
26
  u,
27
27
  a = [],
28
- f = true,
29
- o = false;
28
+ f = !0,
29
+ o = !1;
30
30
  try {
31
31
  if (i = (t = t.call(r)).next, 0 === l) {
32
32
  if (Object(t) !== t) return;
33
33
  f = !1;
34
34
  } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
35
35
  } catch (r) {
36
- o = true, n = r;
36
+ o = !0, n = r;
37
37
  } finally {
38
38
  try {
39
39
  if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
@@ -102,6 +102,13 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
102
102
  progressBarRef.current.max = seconds;
103
103
  }
104
104
  };
105
+ var resetDuration = function resetDuration() {
106
+ setDuration(undefined);
107
+ setCurrentTime(0);
108
+ if (progressBarRef.current) {
109
+ progressBarRef.current.value = 0;
110
+ }
111
+ };
105
112
  var updateCurrentTime = function updateCurrentTime() {
106
113
  if (progressBarRef.current) {
107
114
  setCurrentTime(progressBarRef.current.value);
@@ -112,9 +119,10 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
112
119
  if (!progressBarRef.current || !audioRef.current) {
113
120
  return;
114
121
  }
115
- if (audioRef.current.duration !== Infinity) {
122
+ var liveDuration = audioRef.current.duration;
123
+ if (liveDuration !== Infinity) {
116
124
  progressBarRef.current.value = Math.floor(audioRef.current.currentTime);
117
- progressBarRef.current.style.setProperty('--seek-before-width', "".concat(progressBarRef.current.value / duration * 100, "%"));
125
+ progressBarRef.current.style.setProperty('--seek-before-width', liveDuration > 0 ? "".concat(progressBarRef.current.value / liveDuration * 100, "%") : '0%');
118
126
  }
119
127
  updateCurrentTime();
120
128
 
@@ -181,7 +189,8 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
181
189
  if (!progressBarRef.current || !audioRef.current) return;
182
190
  audioRef.current.currentTime = progressBarRef.current.value;
183
191
  setCurrentTime(progressBarRef.current.value);
184
- progressBarRef.current.style.setProperty('--seek-before-width', "".concat(progressBarRef.current.value / duration * 100, "%"));
192
+ var liveDuration = audioRef.current.duration;
193
+ progressBarRef.current.style.setProperty('--seek-before-width', liveDuration > 0 ? "".concat(progressBarRef.current.value / liveDuration * 100, "%") : '0%');
185
194
  };
186
195
  var changeRange = function changeRange() {
187
196
  if (!progressBarRef.current || !audioRef.current) return;
@@ -224,6 +233,7 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
224
233
  };
225
234
  return {
226
235
  onLoadedMetadata: onLoadedMetadata,
236
+ resetDuration: resetDuration,
227
237
  calculateTime: calculateTime,
228
238
  togglePlaying: togglePlaying,
229
239
  changePlayerCurrentTime: changePlayerCurrentTime,
@@ -315,6 +325,7 @@ var ReactAudioPlayerInner = function ReactAudioPlayerInner(props) {
315
325
  playBtnClass = props.playBtnClass,
316
326
  customHtml = props.customHtml,
317
327
  onLoadedMetadata = props.onLoadedMetadata,
328
+ resetDuration = props.resetDuration,
318
329
  calculateTime = props.calculateTime,
319
330
  togglePlaying = props.togglePlaying,
320
331
  changePlayerCurrentTime = props.changePlayerCurrentTime,
@@ -336,6 +347,7 @@ var ReactAudioPlayerInner = function ReactAudioPlayerInner(props) {
336
347
  // Use JSON.stringify to handle array comparisons by value instead of reference
337
348
  useEffect(function () {
338
349
  if (audioPlayerRef.current && audioSrc) {
350
+ resetDuration === null || resetDuration === void 0 ? void 0 : resetDuration();
339
351
  try {
340
352
  audioPlayerRef.current.load();
341
353
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apm-react-audio-player",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "author": "Jason Phan <jphan@mpr.org>",
5
5
  "license": "MIT",
6
6
  "private": false,