@wavv/ui 2.4.15-alpha.3 → 2.4.15-alpha.5

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.
@@ -12,7 +12,9 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
12
12
  const [totalDuration, setTotalDuration] = useState(0);
13
13
  const [displayCurrent, setDisplayCurrent] = useState('');
14
14
  const [displayDuration, setDisplayDuration] = useState('0:00');
15
+ const [playbackUrl, setPlaybackUrl] = useState(src);
15
16
  const audioRef = useRef(null);
17
+ const objectUrlRef = useRef(null);
16
18
  const isSeekingRef = useRef(false);
17
19
  const seekedTimeoutRef = useRef(null);
18
20
  const lastRequestedSeekSecondsRef = useRef(null);
@@ -100,9 +102,52 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
100
102
  }, [
101
103
  isPlaying
102
104
  ]);
105
+ useEffect(()=>{
106
+ setPlaybackUrl(src);
107
+ if (objectUrlRef.current) {
108
+ try {
109
+ URL.revokeObjectURL(objectUrlRef.current);
110
+ } catch (_e) {}
111
+ objectUrlRef.current = null;
112
+ }
113
+ if (!waveform || !src || !src.startsWith('http')) return;
114
+ let cancelled = false;
115
+ const buildBlobUrl = async ()=>{
116
+ try {
117
+ const resp = await fetch(src, {
118
+ cache: 'force-cache'
119
+ });
120
+ const buf = await resp.arrayBuffer();
121
+ if (cancelled) return;
122
+ if ('bytes' !== resp.headers.get('accept-ranges')) {
123
+ try {
124
+ if (objectUrlRef.current) URL.revokeObjectURL(objectUrlRef.current);
125
+ } catch (_e) {}
126
+ const blob = new Blob([
127
+ buf
128
+ ], {
129
+ type: resp.headers.get('content-type') || 'audio/mpeg'
130
+ });
131
+ const objectUrl = URL.createObjectURL(blob);
132
+ objectUrlRef.current = objectUrl;
133
+ if (!cancelled) setPlaybackUrl(objectUrl);
134
+ }
135
+ } catch (_e) {}
136
+ };
137
+ buildBlobUrl();
138
+ return ()=>{
139
+ cancelled = true;
140
+ try {
141
+ if (objectUrlRef.current) URL.revokeObjectURL(objectUrlRef.current);
142
+ } catch (_e) {}
143
+ };
144
+ }, [
145
+ src,
146
+ waveform
147
+ ]);
103
148
  useEffect(()=>{
104
149
  const { current: audio } = audioRef;
105
- if (audio && src) {
150
+ if (audio && playbackUrl) {
106
151
  audio.load();
107
152
  const checkDuration = setTimeout(()=>{
108
153
  if (audio.duration && Number.isFinite(audio.duration) && audio.duration > 0 && audio.duration !== 1 / 0) {
@@ -116,7 +161,7 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
116
161
  return ()=>clearTimeout(checkDuration);
117
162
  }
118
163
  }, [
119
- src,
164
+ playbackUrl,
120
165
  fallbackDuration
121
166
  ]);
122
167
  useEffect(()=>()=>{
@@ -249,7 +294,7 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
249
294
  alignData: infoPosition,
250
295
  children: [
251
296
  !hideSlider && (waveform ? /*#__PURE__*/ jsx(Waveform, {
252
- src: src,
297
+ src: playbackUrl,
253
298
  value: progress,
254
299
  maxValue: totalDuration,
255
300
  onChange: handleControlGrab,
@@ -281,7 +326,7 @@ const Audio = ({ src, title, width, infoPosition, centerAlignContent, small, tin
281
326
  'center' === infoPosition && timeData,
282
327
  /*#__PURE__*/ jsx("audio", {
283
328
  ref: audioRef,
284
- src: src,
329
+ src: playbackUrl,
285
330
  onPlay: handleAudioPlay,
286
331
  onPause: handleAudioPause,
287
332
  onEmptied: handleAudioStop,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavv/ui",
3
- "version": "2.4.15-alpha.3",
3
+ "version": "2.4.15-alpha.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {