apm-react-audio-player 1.1.3 → 1.2.0
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 +15 -8
- package/dist/index.modern.js +15 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -323,7 +323,7 @@ var ReactAudioPlayerInner = function ReactAudioPlayerInner(props) {
|
|
|
323
323
|
// references
|
|
324
324
|
var audioPlayerRef = (_props$audioPlayerRef = props.audioPlayerRef) !== null && _props$audioPlayerRef !== void 0 ? _props$audioPlayerRef : React.useRef(); // reference our audio component
|
|
325
325
|
var progressBarRef = (_props$progressBarRef = props.progressBarRef) !== null && _props$progressBarRef !== void 0 ? _props$progressBarRef : React.useRef(); // reference our progress bar
|
|
326
|
-
|
|
326
|
+
var hasInitializedRef = React.useRef(false);
|
|
327
327
|
var customStyles = props ? props.style : '';
|
|
328
328
|
var title = props.title,
|
|
329
329
|
audioSrc = props.audioSrc,
|
|
@@ -349,16 +349,23 @@ var ReactAudioPlayerInner = function ReactAudioPlayerInner(props) {
|
|
|
349
349
|
var audioDuration = duration && !isNaN(duration) && calculateTime(duration);
|
|
350
350
|
var formatDuration = duration && !isNaN(duration) && audioDuration && formatCalculateTime(audioDuration);
|
|
351
351
|
|
|
352
|
-
// Reload audio when audioSrc changes
|
|
353
|
-
//
|
|
352
|
+
// Reload audio when audioSrc changes.
|
|
353
|
+
// Skip load() on initial mount — calling it pre-buffers live streams so that
|
|
354
|
+
// by the time the user clicks play the seekable window has advanced and
|
|
355
|
+
// segments are stale. On first play the browser fetches the live edge
|
|
356
|
+
// naturally. On subsequent src changes we do call load() to reset the element.
|
|
357
|
+
// Use JSON.stringify to handle array comparisons by value instead of reference.
|
|
354
358
|
React.useEffect(function () {
|
|
355
359
|
if (audioPlayerRef.current && audioSrc) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
360
|
+
if (hasInitializedRef.current) {
|
|
361
|
+
resetDuration === null || resetDuration === void 0 ? void 0 : resetDuration();
|
|
362
|
+
try {
|
|
363
|
+
audioPlayerRef.current.load();
|
|
364
|
+
} catch (err) {
|
|
365
|
+
console.warn('Failed to reload audio source:', err);
|
|
366
|
+
}
|
|
361
367
|
}
|
|
368
|
+
hasInitializedRef.current = true;
|
|
362
369
|
}
|
|
363
370
|
}, [JSON.stringify(audioSrc)]);
|
|
364
371
|
|
package/dist/index.modern.js
CHANGED
|
@@ -321,7 +321,7 @@ var ReactAudioPlayerInner = function ReactAudioPlayerInner(props) {
|
|
|
321
321
|
// references
|
|
322
322
|
var audioPlayerRef = (_props$audioPlayerRef = props.audioPlayerRef) !== null && _props$audioPlayerRef !== void 0 ? _props$audioPlayerRef : useRef(); // reference our audio component
|
|
323
323
|
var progressBarRef = (_props$progressBarRef = props.progressBarRef) !== null && _props$progressBarRef !== void 0 ? _props$progressBarRef : useRef(); // reference our progress bar
|
|
324
|
-
|
|
324
|
+
var hasInitializedRef = useRef(false);
|
|
325
325
|
var customStyles = props ? props.style : '';
|
|
326
326
|
var title = props.title,
|
|
327
327
|
audioSrc = props.audioSrc,
|
|
@@ -347,16 +347,23 @@ var ReactAudioPlayerInner = function ReactAudioPlayerInner(props) {
|
|
|
347
347
|
var audioDuration = duration && !isNaN(duration) && calculateTime(duration);
|
|
348
348
|
var formatDuration = duration && !isNaN(duration) && audioDuration && formatCalculateTime(audioDuration);
|
|
349
349
|
|
|
350
|
-
// Reload audio when audioSrc changes
|
|
351
|
-
//
|
|
350
|
+
// Reload audio when audioSrc changes.
|
|
351
|
+
// Skip load() on initial mount — calling it pre-buffers live streams so that
|
|
352
|
+
// by the time the user clicks play the seekable window has advanced and
|
|
353
|
+
// segments are stale. On first play the browser fetches the live edge
|
|
354
|
+
// naturally. On subsequent src changes we do call load() to reset the element.
|
|
355
|
+
// Use JSON.stringify to handle array comparisons by value instead of reference.
|
|
352
356
|
useEffect(function () {
|
|
353
357
|
if (audioPlayerRef.current && audioSrc) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
358
|
+
if (hasInitializedRef.current) {
|
|
359
|
+
resetDuration === null || resetDuration === void 0 ? void 0 : resetDuration();
|
|
360
|
+
try {
|
|
361
|
+
audioPlayerRef.current.load();
|
|
362
|
+
} catch (err) {
|
|
363
|
+
console.warn('Failed to reload audio source:', err);
|
|
364
|
+
}
|
|
359
365
|
}
|
|
366
|
+
hasInitializedRef.current = true;
|
|
360
367
|
}
|
|
361
368
|
}, [JSON.stringify(audioSrc)]);
|
|
362
369
|
|