apm-react-audio-player 1.0.8 → 1.0.9
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 +18 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -93,16 +93,17 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
|
|
|
93
93
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
94
94
|
isMuted = _useState10[0],
|
|
95
95
|
setIsMuted = _useState10[1];
|
|
96
|
+
var isStream = audioRef.current && audioRef.current.currentSrc.includes('stream');
|
|
96
97
|
React.useEffect(function () {
|
|
97
98
|
if (currentTime === Number(duration)) {
|
|
98
|
-
restart()
|
|
99
|
+
// restart()
|
|
99
100
|
setIsFinishedPlaying(true);
|
|
100
101
|
}
|
|
101
102
|
}, [currentTime]);
|
|
102
103
|
var onLoadedMetadata = function onLoadedMetadata() {
|
|
103
104
|
var seconds = Math.floor(audioRef.current.duration);
|
|
104
105
|
setDuration(seconds);
|
|
105
|
-
if (!
|
|
106
|
+
if (!isStream) {
|
|
106
107
|
progressBarRef.current.max = seconds;
|
|
107
108
|
}
|
|
108
109
|
};
|
|
@@ -110,13 +111,15 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
|
|
|
110
111
|
setCurrentTime(progressBarRef.current.value);
|
|
111
112
|
};
|
|
112
113
|
var whilePlaying = function whilePlaying() {
|
|
113
|
-
|
|
114
|
+
if (!isStream) {
|
|
115
|
+
progressBarRef.current.value = Math.floor(audioRef.current.currentTime);
|
|
116
|
+
}
|
|
114
117
|
progressBarRef.current.style.setProperty('--seek-before-width', "".concat(progressBarRef.current.value / duration * 100, "%"));
|
|
115
118
|
updateCurrentTime();
|
|
116
119
|
|
|
117
120
|
// when you reach the end of the song
|
|
118
|
-
if (progressBarRef.current.value === duration) {
|
|
119
|
-
restart()
|
|
121
|
+
if (!isStream && progressBarRef.current.value === duration) {
|
|
122
|
+
// restart()
|
|
120
123
|
setIsFinishedPlaying(true);
|
|
121
124
|
return;
|
|
122
125
|
}
|
|
@@ -127,16 +130,20 @@ var useAudioPlayer = function useAudioPlayer(audioRef, progressBarRef, volumeCtr
|
|
|
127
130
|
audioRef.current.pause();
|
|
128
131
|
window.cancelAnimationFrame(animationRef.current);
|
|
129
132
|
};
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
|
|
134
|
+
// const restart = () => {
|
|
135
|
+
// progressBarRef.current.value = 0
|
|
136
|
+
// updateCurrentTime()
|
|
137
|
+
// pause()
|
|
138
|
+
// }
|
|
139
|
+
|
|
135
140
|
var play = function play() {
|
|
136
141
|
setIsPlaying(true);
|
|
137
142
|
setIsFinishedPlaying(false);
|
|
138
143
|
audioRef.current.play();
|
|
139
|
-
|
|
144
|
+
if (!isStream) {
|
|
145
|
+
animationRef.current = window.requestAnimationFrame(whilePlaying);
|
|
146
|
+
}
|
|
140
147
|
};
|
|
141
148
|
var toggleMute = function toggleMute() {
|
|
142
149
|
setIsMuted(!isMuted);
|