apm-react-audio-player 1.0.17 → 1.0.18
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 +12 -36
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -94,42 +94,17 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
|
|
|
94
94
|
isMuted = _useState10[0],
|
|
95
95
|
setIsMuted = _useState10[1];
|
|
96
96
|
var isStream = audioRef.current && audioRef.current.currentSrc.includes('stream');
|
|
97
|
-
|
|
98
|
-
// Add a new state variable
|
|
99
|
-
var _useState11 = React.useState(false),
|
|
100
|
-
_useState12 = _slicedToArray(_useState11, 2),
|
|
101
|
-
isAudioReady = _useState12[0],
|
|
102
|
-
setIsAudioReady = _useState12[1];
|
|
103
|
-
console.log('🟡 audioRef', audioRef);
|
|
104
|
-
console.log('🟡 progressBarRef', progressBarRef);
|
|
105
|
-
console.log(' audioRef.current ', audioRef.current);
|
|
106
97
|
React.useEffect(function () {
|
|
107
98
|
if (currentTime === Number(duration)) {
|
|
108
99
|
// restart()
|
|
109
100
|
setIsFinishedPlaying(true);
|
|
110
|
-
console.log('🟡 audioRef', audioRef);
|
|
111
|
-
console.log('⚪️ progressBarRef', progressBarRef);
|
|
112
|
-
if (progressBarRef.current) {
|
|
113
|
-
progressBarRef.current.style.setProperty('--seek-before-width', '0%');
|
|
114
|
-
}
|
|
115
101
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// Define a function to set isAudioReady to true when the audio is ready
|
|
119
|
-
var handleCanPlayThrough = function handleCanPlayThrough() {
|
|
120
|
-
setIsAudioReady(true);
|
|
121
|
-
};
|
|
122
|
-
audio.addEventListener('canplaythrough', handleCanPlayThrough);
|
|
123
|
-
|
|
124
|
-
// Clean up the event listener on unmount
|
|
125
|
-
return function () {
|
|
126
|
-
audio.removeEventListener('canplaythrough', handleCanPlayThrough);
|
|
127
|
-
};
|
|
128
|
-
}, [isPlaying]);
|
|
102
|
+
}, [currentTime]);
|
|
129
103
|
var onLoadedMetadata = function onLoadedMetadata() {
|
|
104
|
+
var _audioRef$current;
|
|
130
105
|
var seconds = Math.floor(audioRef.current.duration);
|
|
131
106
|
setDuration(seconds);
|
|
132
|
-
if (
|
|
107
|
+
if (!(audioRef !== null && audioRef !== void 0 && (_audioRef$current = audioRef.current) !== null && _audioRef$current !== void 0 && _audioRef$current.currentSrc.includes('stream'))) {
|
|
133
108
|
progressBarRef.current.max = seconds;
|
|
134
109
|
}
|
|
135
110
|
};
|
|
@@ -137,7 +112,10 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
|
|
|
137
112
|
setCurrentTime(progressBarRef.current.value);
|
|
138
113
|
};
|
|
139
114
|
var whilePlaying = function whilePlaying() {
|
|
140
|
-
|
|
115
|
+
var _audioRef$current2;
|
|
116
|
+
if (!(audioRef !== null && audioRef !== void 0 && (_audioRef$current2 = audioRef.current) !== null && _audioRef$current2 !== void 0 && _audioRef$current2.currentSrc.includes('stream'))) {
|
|
117
|
+
// isStream isn't correct here
|
|
118
|
+
|
|
141
119
|
progressBarRef.current.value = Math.floor(audioRef.current.currentTime);
|
|
142
120
|
}
|
|
143
121
|
progressBarRef.current.style.setProperty('--seek-before-width', "".concat(progressBarRef.current.value / duration * 100, "%"));
|
|
@@ -164,13 +142,11 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
|
|
|
164
142
|
// }
|
|
165
143
|
|
|
166
144
|
var play = function play() {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
setIsFinishedPlaying(false);
|
|
173
|
-
audioRef.current.play();
|
|
145
|
+
setIsPlaying(true);
|
|
146
|
+
setIsFinishedPlaying(false);
|
|
147
|
+
audioRef.current.play();
|
|
148
|
+
if (!audioRef.current.currentSrc.includes('stream')) {
|
|
149
|
+
// isStream isn't correctly set here
|
|
174
150
|
animationRef.current = window.requestAnimationFrame(whilePlaying);
|
|
175
151
|
}
|
|
176
152
|
};
|