@micromag/element-audio 0.3.310 → 0.3.318
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/assets/css/styles.css +2 -2
- package/es/index.js +108 -143
- package/lib/index.js +108 -143
- package/package.json +8 -8
package/assets/css/styles.css
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
.micromag-element-audio-audio-bars-container .micromag-element-audio-audio-bars-seekButton{
|
|
1
|
+
.micromag-element-audio-audio-bars-container .micromag-element-audio-audio-bars-seekButton{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:transparent;border:0;color:inherit;cursor:pointer;display:inline-block;font-family:inherit;height:100%;left:0;padding:0;position:relative;top:0;width:100%}.micromag-element-audio-audio-bars-container{height:100%;position:relative;width:100%}.micromag-element-audio-audio-bars-container .micromag-element-audio-audio-bars-seekButton{position:absolute;-ms-touch-action:none;touch-action:none}
|
|
2
2
|
.micromag-element-audio-container .micromag-element-audio-wave{height:150px}
|
|
3
|
-
.micromag-element-audio-audio-wave-container .micromag-element-audio-audio-wave-button{
|
|
3
|
+
.micromag-element-audio-audio-wave-container .micromag-element-audio-audio-wave-button{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:transparent;border:0;color:inherit;cursor:pointer;display:inline-block;font-family:inherit;padding:0;position:relative}.micromag-element-audio-audio-wave-container .micromag-element-audio-audio-wave-button,.micromag-element-audio-audio-wave-container .micromag-element-audio-audio-wave-canvasBackground,.micromag-element-audio-audio-wave-container .micromag-element-audio-audio-wave-canvasProgress{height:100%;left:0;position:absolute;top:0;width:100%}.micromag-element-audio-audio-wave-container{height:100px;position:relative;-ms-touch-action:pan-y;touch-action:pan-y}
|
package/es/index.js
CHANGED
|
@@ -35,32 +35,27 @@ var defaultProps$2 = {
|
|
|
35
35
|
// onReady: null,
|
|
36
36
|
className: null
|
|
37
37
|
};
|
|
38
|
-
|
|
39
38
|
function AudioBars(_ref) {
|
|
40
39
|
var progress = _ref.progress,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
playing = _ref.playing,
|
|
41
|
+
duration = _ref.duration,
|
|
42
|
+
seek = _ref.seek,
|
|
43
|
+
play = _ref.play,
|
|
44
|
+
className = _ref.className;
|
|
46
45
|
var intl = useIntl();
|
|
47
|
-
|
|
48
46
|
var _useDimensionObserver = useDimensionObserver(),
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
elRef = _useDimensionObserver.ref,
|
|
48
|
+
_useDimensionObserver2 = _useDimensionObserver.width,
|
|
49
|
+
elWidth = _useDimensionObserver2 === void 0 ? null : _useDimensionObserver2,
|
|
50
|
+
elHeight = _useDimensionObserver.height;
|
|
54
51
|
var barWidth = 1;
|
|
55
52
|
var barGap = 1;
|
|
56
53
|
var barSize = barWidth + barGap;
|
|
57
54
|
var current = progress * elWidth;
|
|
58
|
-
|
|
59
55
|
var _useState = useState(null),
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
56
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
57
|
+
currentSeek = _useState2[0],
|
|
58
|
+
setCurrentSeek = _useState2[1];
|
|
64
59
|
var items = useMemo(function () {
|
|
65
60
|
var count = Math.floor(elWidth / barSize);
|
|
66
61
|
return _toConsumableArray(Array(count).keys()).map(function () {
|
|
@@ -69,62 +64,57 @@ function AudioBars(_ref) {
|
|
|
69
64
|
}, [elWidth, barSize]);
|
|
70
65
|
var seekFromX = useCallback(function () {
|
|
71
66
|
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
72
|
-
|
|
73
67
|
if (x === null) {
|
|
74
68
|
return;
|
|
75
69
|
}
|
|
76
|
-
|
|
77
70
|
var _elRef$current$getBou = elRef.current.getBoundingClientRect(),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
elX = _elRef$current$getBou.left,
|
|
72
|
+
width = _elRef$current$getBou.width;
|
|
81
73
|
var distance = Math.max(0, Math.min(1, (x - elX) / width));
|
|
82
|
-
|
|
83
74
|
if (seek !== null && duration !== null) {
|
|
84
75
|
seek(parseFloat(distance * duration, 10));
|
|
85
76
|
}
|
|
86
|
-
|
|
87
77
|
if (!playing && play != null) {
|
|
88
78
|
play();
|
|
89
79
|
}
|
|
90
80
|
}, [elRef.current, elWidth, duration, playing, seek, play]);
|
|
91
81
|
var seekTemporary = useCallback(function (x) {
|
|
92
82
|
var _elRef$current$getBou2 = elRef.current.getBoundingClientRect(),
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
83
|
+
elX = _elRef$current$getBou2.left,
|
|
84
|
+
width = _elRef$current$getBou2.width;
|
|
96
85
|
var distance = Math.max(0, Math.min(1, (x - elX) / width));
|
|
97
86
|
setCurrentSeek(distance * elWidth);
|
|
98
87
|
}, [elRef.current, elWidth, setCurrentSeek]);
|
|
88
|
+
var onClick = useCallback(function (e) {
|
|
89
|
+
if (e) {
|
|
90
|
+
seekFromX(e.clientX || null);
|
|
91
|
+
setCurrentSeek(null);
|
|
92
|
+
}
|
|
93
|
+
}, [seekFromX, setCurrentSeek]);
|
|
99
94
|
var bind = useGesture({
|
|
100
95
|
onDrag: function onDrag(_ref2) {
|
|
101
96
|
var _ref2$xy = _slicedToArray(_ref2.xy, 1),
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
x = _ref2$xy[0],
|
|
98
|
+
elapsedTime = _ref2.elapsedTime,
|
|
99
|
+
active = _ref2.active;
|
|
106
100
|
if (!active && elapsedTime > 300) {
|
|
107
101
|
return;
|
|
108
102
|
}
|
|
109
|
-
|
|
110
103
|
seekTemporary(x);
|
|
111
104
|
},
|
|
112
105
|
onDragStart: function onDragStart(_ref3) {
|
|
113
106
|
var _ref3$xy = _slicedToArray(_ref3.xy, 1),
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
107
|
+
x = _ref3$xy[0],
|
|
108
|
+
elapsedTime = _ref3.elapsedTime,
|
|
109
|
+
active = _ref3.active;
|
|
118
110
|
if (!active && elapsedTime > 300) {
|
|
119
111
|
return;
|
|
120
112
|
}
|
|
121
|
-
|
|
122
113
|
seekTemporary(x);
|
|
123
114
|
},
|
|
124
115
|
onDragEnd: function onDragEnd(_ref4) {
|
|
125
116
|
var _ref4$xy = _slicedToArray(_ref4.xy, 1),
|
|
126
|
-
|
|
127
|
-
|
|
117
|
+
x = _ref4$xy[0];
|
|
128
118
|
seekFromX(x);
|
|
129
119
|
setTimeout(function () {
|
|
130
120
|
setCurrentSeek(null);
|
|
@@ -164,9 +154,7 @@ function AudioBars(_ref) {
|
|
|
164
154
|
strokeLinecap: "round"
|
|
165
155
|
});
|
|
166
156
|
})), /*#__PURE__*/React.createElement("button", Object.assign({}, bind(), {
|
|
167
|
-
onClick:
|
|
168
|
-
return e.target !== null ? seekFromX(e.target.clientX) : null;
|
|
169
|
-
},
|
|
157
|
+
onClick: onClick,
|
|
170
158
|
type: "button",
|
|
171
159
|
className: styles$2.seekButton,
|
|
172
160
|
title: intl.formatMessage({
|
|
@@ -185,7 +173,6 @@ function AudioBars(_ref) {
|
|
|
185
173
|
})
|
|
186
174
|
})));
|
|
187
175
|
}
|
|
188
|
-
|
|
189
176
|
AudioBars.propTypes = propTypes$2;
|
|
190
177
|
AudioBars.defaultProps = defaultProps$2;
|
|
191
178
|
|
|
@@ -245,35 +232,31 @@ var defaultProps$1 = {
|
|
|
245
232
|
onDurationChange: null,
|
|
246
233
|
onVolumeChange: null
|
|
247
234
|
};
|
|
248
|
-
|
|
249
235
|
var Audio = function Audio(_ref) {
|
|
250
236
|
var media = _ref.media,
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
237
|
+
mediaRef = _ref.mediaRef,
|
|
238
|
+
muted = _ref.muted,
|
|
239
|
+
autoPlay = _ref.autoPlay,
|
|
240
|
+
paused = _ref.paused,
|
|
241
|
+
loop = _ref.loop,
|
|
242
|
+
preload = _ref.preload,
|
|
243
|
+
shouldLoad = _ref.shouldLoad,
|
|
244
|
+
waveFake = _ref.waveFake,
|
|
245
|
+
withWave = _ref.withWave,
|
|
246
|
+
className = _ref.className,
|
|
247
|
+
onReady = _ref.onReady,
|
|
248
|
+
onPlay = _ref.onPlay,
|
|
249
|
+
onPause = _ref.onPause,
|
|
250
|
+
onEnded = _ref.onEnded,
|
|
251
|
+
onSeeked = _ref.onSeeked,
|
|
252
|
+
onTimeUpdate = _ref.onTimeUpdate,
|
|
253
|
+
onProgressStep = _ref.onProgressStep,
|
|
254
|
+
customOnDurationChange = _ref.onDurationChange,
|
|
255
|
+
customOnVolumeChange = _ref.onVolumeChange;
|
|
271
256
|
var _ref2 = media || {},
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
257
|
+
_ref2$url = _ref2.url,
|
|
258
|
+
url = _ref2$url === void 0 ? null : _ref2$url;
|
|
275
259
|
var _ref4 = useRef(null);
|
|
276
|
-
|
|
277
260
|
var currentTime = useMediaCurrentTime(_ref4.current, {
|
|
278
261
|
id: url,
|
|
279
262
|
disabled: paused || !withWave && onProgressStep === null
|
|
@@ -283,7 +266,9 @@ var Audio = function Audio(_ref) {
|
|
|
283
266
|
});
|
|
284
267
|
var duration = useMediaDuration(_ref4.current, {
|
|
285
268
|
id: url
|
|
286
|
-
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// const audioLevels = useMediaWaveform(media, {
|
|
287
272
|
// fake: waveFake,
|
|
288
273
|
// reduceBufferFactor,
|
|
289
274
|
// });
|
|
@@ -300,36 +285,28 @@ var Audio = function Audio(_ref) {
|
|
|
300
285
|
}, [duration, customOnDurationChange]);
|
|
301
286
|
var onVolumeChange = useCallback(function () {
|
|
302
287
|
var _ref$current = _ref4.current,
|
|
303
|
-
|
|
304
|
-
|
|
288
|
+
element = _ref$current === void 0 ? null : _ref$current;
|
|
305
289
|
if (element === null) {
|
|
306
290
|
return;
|
|
307
291
|
}
|
|
308
|
-
|
|
309
292
|
if (customOnVolumeChange !== null) {
|
|
310
293
|
customOnVolumeChange(element.volume);
|
|
311
294
|
}
|
|
312
295
|
}, [_ref4.current, customOnVolumeChange]);
|
|
313
296
|
var onWavePlay = useCallback(function () {
|
|
314
297
|
var _ref$current2 = _ref4.current,
|
|
315
|
-
|
|
316
|
-
|
|
298
|
+
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
317
299
|
if (element === null) {
|
|
318
300
|
return;
|
|
319
301
|
}
|
|
320
|
-
|
|
321
302
|
element.play();
|
|
322
303
|
}, [_ref4.current]);
|
|
323
304
|
var onWaveSeek = useCallback(function (newTime) {
|
|
324
305
|
var _ref$current3 = _ref4.current,
|
|
325
|
-
|
|
326
|
-
|
|
306
|
+
element = _ref$current3 === void 0 ? null : _ref$current3;
|
|
327
307
|
if (element === null) {
|
|
328
308
|
return;
|
|
329
309
|
}
|
|
330
|
-
|
|
331
|
-
console.log('fuck off', newTime);
|
|
332
|
-
|
|
333
310
|
if (isNumber(newTime)) {
|
|
334
311
|
element.currentTime = newTime;
|
|
335
312
|
}
|
|
@@ -341,14 +318,11 @@ var Audio = function Audio(_ref) {
|
|
|
341
318
|
}, [waveReady, onReady]);
|
|
342
319
|
useEffect(function () {
|
|
343
320
|
var _ref$current4 = _ref4.current,
|
|
344
|
-
|
|
345
|
-
|
|
321
|
+
element = _ref$current4 === void 0 ? null : _ref$current4;
|
|
346
322
|
if (element === null) {
|
|
347
323
|
return;
|
|
348
324
|
}
|
|
349
|
-
|
|
350
325
|
var isPaused = element.paused;
|
|
351
|
-
|
|
352
326
|
if (paused && !isPaused) {
|
|
353
327
|
element.pause();
|
|
354
328
|
} else if (!paused && isPaused) {
|
|
@@ -368,7 +342,6 @@ var Audio = function Audio(_ref) {
|
|
|
368
342
|
key: url,
|
|
369
343
|
ref: function ref(newRef) {
|
|
370
344
|
_ref4.current = newRef;
|
|
371
|
-
|
|
372
345
|
if (mediaRef !== null && isFunction(mediaRef)) {
|
|
373
346
|
mediaRef(newRef);
|
|
374
347
|
} else if (mediaRef !== null) {
|
|
@@ -389,7 +362,8 @@ var Audio = function Audio(_ref) {
|
|
|
389
362
|
onVolumeChange: onVolumeChange
|
|
390
363
|
}), withWave ? /*#__PURE__*/React.createElement(AudioBars, {
|
|
391
364
|
className: styles$1.wave,
|
|
392
|
-
progress: progress
|
|
365
|
+
progress: progress
|
|
366
|
+
// {...waveProps}
|
|
393
367
|
,
|
|
394
368
|
duration: duration,
|
|
395
369
|
playing: !paused,
|
|
@@ -397,7 +371,6 @@ var Audio = function Audio(_ref) {
|
|
|
397
371
|
play: onWavePlay
|
|
398
372
|
}) : null);
|
|
399
373
|
};
|
|
400
|
-
|
|
401
374
|
Audio.propTypes = propTypes$1;
|
|
402
375
|
Audio.defaultProps = defaultProps$1;
|
|
403
376
|
var Audio$1 = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
@@ -438,58 +411,54 @@ var defaultProps = {
|
|
|
438
411
|
onResume: null,
|
|
439
412
|
onReady: null
|
|
440
413
|
};
|
|
441
|
-
|
|
442
414
|
function AudioWave(_ref) {
|
|
443
415
|
var currentTime = _ref.currentTime,
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
416
|
+
duration = _ref.duration,
|
|
417
|
+
playing = _ref.playing,
|
|
418
|
+
sampleWidth = _ref.sampleWidth,
|
|
419
|
+
sampleMargin = _ref.sampleMargin,
|
|
420
|
+
minSampleHeight = _ref.minSampleHeight,
|
|
421
|
+
backgroundColor = _ref.backgroundColor,
|
|
422
|
+
progressColor = _ref.progressColor,
|
|
423
|
+
audioLevels = _ref.audioLevels,
|
|
424
|
+
className = _ref.className,
|
|
425
|
+
onSeek = _ref.onSeek,
|
|
426
|
+
onResume = _ref.onResume,
|
|
427
|
+
onReady = _ref.onReady;
|
|
456
428
|
var canvasBackgroundRef = useRef(null);
|
|
457
429
|
var canvasProgressRef = useRef(null);
|
|
458
430
|
var mainColor = useMemo(function () {
|
|
459
431
|
var _ref2 = backgroundColor || {},
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
432
|
+
_ref2$color = _ref2.color,
|
|
433
|
+
color = _ref2$color === void 0 ? 'white' : _ref2$color;
|
|
463
434
|
return color;
|
|
464
435
|
}, [backgroundColor]);
|
|
465
436
|
var alternateColor = useMemo(function () {
|
|
466
437
|
return getContrastingColor(backgroundColor, progressColor);
|
|
467
438
|
}, [progressColor, backgroundColor]);
|
|
468
|
-
|
|
469
439
|
var _useDimensionObserver = useDimensionObserver(),
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
440
|
+
elRef = _useDimensionObserver.ref,
|
|
441
|
+
_useDimensionObserver2 = _useDimensionObserver.width,
|
|
442
|
+
elWidth = _useDimensionObserver2 === void 0 ? null : _useDimensionObserver2,
|
|
443
|
+
elHeight = _useDimensionObserver.height;
|
|
474
444
|
|
|
445
|
+
// Linear animation for progress bar
|
|
475
446
|
|
|
476
447
|
var _useSpring = useSpring(function () {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
448
|
+
return {
|
|
449
|
+
x: 0,
|
|
450
|
+
config: {
|
|
451
|
+
duration: 0
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
}),
|
|
455
|
+
_useSpring2 = _slicedToArray(_useSpring, 2),
|
|
456
|
+
springProps = _useSpring2[0],
|
|
457
|
+
setSpringProps = _useSpring2[1];
|
|
488
458
|
useEffect(function () {
|
|
489
459
|
if (currentTime === null || duration === null) {
|
|
490
460
|
return;
|
|
491
461
|
}
|
|
492
|
-
|
|
493
462
|
var progress = currentTime / duration;
|
|
494
463
|
setSpringProps.start({
|
|
495
464
|
reset: true,
|
|
@@ -504,32 +473,35 @@ function AudioWave(_ref) {
|
|
|
504
473
|
duration: (duration - currentTime) * 1000
|
|
505
474
|
}
|
|
506
475
|
});
|
|
507
|
-
}, [playing, duration, currentTime, setSpringProps]);
|
|
476
|
+
}, [playing, duration, currentTime, setSpringProps]);
|
|
477
|
+
|
|
478
|
+
// draw canvas
|
|
508
479
|
|
|
509
480
|
useEffect(function () {
|
|
510
481
|
if (audioLevels === null || audioLevels.length === 0 || elRef.current === null) {
|
|
511
482
|
return;
|
|
512
483
|
}
|
|
513
|
-
|
|
514
484
|
var sampleOuterWidth = sampleWidth + sampleMargin * 2;
|
|
515
|
-
var samplesCount = Math.floor(elWidth / sampleOuterWidth);
|
|
485
|
+
var samplesCount = Math.floor(elWidth / sampleOuterWidth);
|
|
486
|
+
|
|
487
|
+
// const amplitudes = [];
|
|
488
|
+
|
|
516
489
|
// get samples
|
|
517
490
|
|
|
518
491
|
var levelsBySamples = audioLevels.length / samplesCount;
|
|
519
|
-
|
|
520
492
|
var amplitudes = _toConsumableArray(Array(samplesCount).keys()).reduce(function (newAmplitudes, index) {
|
|
521
493
|
var levelStartIndex = index * levelsBySamples;
|
|
522
494
|
var levelEndIndex = levelStartIndex + levelsBySamples;
|
|
523
495
|
var newValues = [];
|
|
524
|
-
|
|
525
496
|
for (var i = Math.floor(levelStartIndex); i < Math.round(levelEndIndex); i += 1) {
|
|
526
497
|
newValues.push(audioLevels[i]);
|
|
527
498
|
}
|
|
528
|
-
|
|
529
499
|
return levelsBySamples >= 1 ? [].concat(_toConsumableArray(newAmplitudes), [newValues.reduce(function (total, value) {
|
|
530
500
|
return total + value;
|
|
531
501
|
}, 0) / newValues.length]) : [].concat(_toConsumableArray(newAmplitudes), newValues);
|
|
532
|
-
}, []);
|
|
502
|
+
}, []);
|
|
503
|
+
|
|
504
|
+
// for (let sampleI = 0; sampleI < samplesCount; sampleI += levelsBySamples) {
|
|
533
505
|
// // if (levelsBySamples >= 1) {
|
|
534
506
|
// // const sampleSize = Math.floor(levelsBySamples);
|
|
535
507
|
// // const sampleStart = sampleSize * sampleI;
|
|
@@ -547,15 +519,14 @@ function AudioWave(_ref) {
|
|
|
547
519
|
// // }
|
|
548
520
|
// // }
|
|
549
521
|
// }
|
|
550
|
-
|
|
551
|
-
|
|
552
522
|
var minAmplitude = Math.min.apply(Math, _toConsumableArray(amplitudes));
|
|
553
523
|
var maxAmplitude = Math.max.apply(Math, _toConsumableArray(amplitudes));
|
|
554
524
|
var delta = maxAmplitude - minAmplitude;
|
|
555
525
|
var normalizedAmplitudes = amplitudes.map(function (n) {
|
|
556
526
|
return (n - minAmplitude) / delta;
|
|
557
|
-
});
|
|
527
|
+
});
|
|
558
528
|
|
|
529
|
+
// draw samples
|
|
559
530
|
var canvasBg = canvasBackgroundRef.current;
|
|
560
531
|
var canvasProgress = canvasProgressRef.current;
|
|
561
532
|
var scale = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
@@ -577,23 +548,20 @@ function AudioWave(_ref) {
|
|
|
577
548
|
ctxBG.fillRect(Math.round(sampleX), Math.round(sampleY), sampleWidth, Math.round(sampleHeight));
|
|
578
549
|
ctxProgress.fillRect(Math.round(sampleX), Math.round(sampleY), sampleWidth, Math.round(sampleHeight));
|
|
579
550
|
});
|
|
580
|
-
|
|
581
551
|
if (onReady !== null) {
|
|
582
552
|
onReady();
|
|
583
553
|
}
|
|
584
|
-
}, [audioLevels, sampleWidth, sampleMargin, minSampleHeight, elWidth, elHeight, mainColor, alternateColor, onReady]);
|
|
554
|
+
}, [audioLevels, sampleWidth, sampleMargin, minSampleHeight, elWidth, elHeight, mainColor, alternateColor, onReady]);
|
|
585
555
|
|
|
556
|
+
// User events
|
|
586
557
|
var seekFromX = useCallback(function (x) {
|
|
587
558
|
var _elRef$current$getBou = elRef.current.getBoundingClientRect(),
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
559
|
+
elX = _elRef$current$getBou.left,
|
|
560
|
+
width = _elRef$current$getBou.width;
|
|
591
561
|
var progress = Math.max(0, Math.min(1, (x - elX) / width));
|
|
592
|
-
|
|
593
562
|
if (onSeek !== null && duration !== null) {
|
|
594
563
|
onSeek(progress * duration);
|
|
595
564
|
}
|
|
596
|
-
|
|
597
565
|
if (!playing) {
|
|
598
566
|
onResume();
|
|
599
567
|
}
|
|
@@ -601,14 +569,12 @@ function AudioWave(_ref) {
|
|
|
601
569
|
var bind = useGesture({
|
|
602
570
|
onDrag: function onDrag(_ref3) {
|
|
603
571
|
var _ref3$xy = _slicedToArray(_ref3.xy, 1),
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
572
|
+
x = _ref3$xy[0],
|
|
573
|
+
elapsedTime = _ref3.elapsedTime,
|
|
574
|
+
active = _ref3.active;
|
|
608
575
|
if (!active && elapsedTime > 300) {
|
|
609
576
|
return;
|
|
610
577
|
}
|
|
611
|
-
|
|
612
578
|
seekFromX(x);
|
|
613
579
|
}
|
|
614
580
|
}, {
|
|
@@ -633,7 +599,6 @@ function AudioWave(_ref) {
|
|
|
633
599
|
}
|
|
634
600
|
}));
|
|
635
601
|
}
|
|
636
|
-
|
|
637
602
|
AudioWave.propTypes = propTypes;
|
|
638
603
|
AudioWave.defaultProps = defaultProps;
|
|
639
604
|
|
package/lib/index.js
CHANGED
|
@@ -50,32 +50,27 @@ var defaultProps$2 = {
|
|
|
50
50
|
// onReady: null,
|
|
51
51
|
className: null
|
|
52
52
|
};
|
|
53
|
-
|
|
54
53
|
function AudioBars(_ref) {
|
|
55
54
|
var progress = _ref.progress,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
playing = _ref.playing,
|
|
56
|
+
duration = _ref.duration,
|
|
57
|
+
seek = _ref.seek,
|
|
58
|
+
play = _ref.play,
|
|
59
|
+
className = _ref.className;
|
|
61
60
|
var intl = reactIntl.useIntl();
|
|
62
|
-
|
|
63
61
|
var _useDimensionObserver = hooks.useDimensionObserver(),
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
elRef = _useDimensionObserver.ref,
|
|
63
|
+
_useDimensionObserver2 = _useDimensionObserver.width,
|
|
64
|
+
elWidth = _useDimensionObserver2 === void 0 ? null : _useDimensionObserver2,
|
|
65
|
+
elHeight = _useDimensionObserver.height;
|
|
69
66
|
var barWidth = 1;
|
|
70
67
|
var barGap = 1;
|
|
71
68
|
var barSize = barWidth + barGap;
|
|
72
69
|
var current = progress * elWidth;
|
|
73
|
-
|
|
74
70
|
var _useState = React.useState(null),
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
_useState2 = _slicedToArray__default["default"](_useState, 2),
|
|
72
|
+
currentSeek = _useState2[0],
|
|
73
|
+
setCurrentSeek = _useState2[1];
|
|
79
74
|
var items = React.useMemo(function () {
|
|
80
75
|
var count = Math.floor(elWidth / barSize);
|
|
81
76
|
return _toConsumableArray__default["default"](Array(count).keys()).map(function () {
|
|
@@ -84,62 +79,57 @@ function AudioBars(_ref) {
|
|
|
84
79
|
}, [elWidth, barSize]);
|
|
85
80
|
var seekFromX = React.useCallback(function () {
|
|
86
81
|
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
87
|
-
|
|
88
82
|
if (x === null) {
|
|
89
83
|
return;
|
|
90
84
|
}
|
|
91
|
-
|
|
92
85
|
var _elRef$current$getBou = elRef.current.getBoundingClientRect(),
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
elX = _elRef$current$getBou.left,
|
|
87
|
+
width = _elRef$current$getBou.width;
|
|
96
88
|
var distance = Math.max(0, Math.min(1, (x - elX) / width));
|
|
97
|
-
|
|
98
89
|
if (seek !== null && duration !== null) {
|
|
99
90
|
seek(parseFloat(distance * duration, 10));
|
|
100
91
|
}
|
|
101
|
-
|
|
102
92
|
if (!playing && play != null) {
|
|
103
93
|
play();
|
|
104
94
|
}
|
|
105
95
|
}, [elRef.current, elWidth, duration, playing, seek, play]);
|
|
106
96
|
var seekTemporary = React.useCallback(function (x) {
|
|
107
97
|
var _elRef$current$getBou2 = elRef.current.getBoundingClientRect(),
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
98
|
+
elX = _elRef$current$getBou2.left,
|
|
99
|
+
width = _elRef$current$getBou2.width;
|
|
111
100
|
var distance = Math.max(0, Math.min(1, (x - elX) / width));
|
|
112
101
|
setCurrentSeek(distance * elWidth);
|
|
113
102
|
}, [elRef.current, elWidth, setCurrentSeek]);
|
|
103
|
+
var onClick = React.useCallback(function (e) {
|
|
104
|
+
if (e) {
|
|
105
|
+
seekFromX(e.clientX || null);
|
|
106
|
+
setCurrentSeek(null);
|
|
107
|
+
}
|
|
108
|
+
}, [seekFromX, setCurrentSeek]);
|
|
114
109
|
var bind = react.useGesture({
|
|
115
110
|
onDrag: function onDrag(_ref2) {
|
|
116
111
|
var _ref2$xy = _slicedToArray__default["default"](_ref2.xy, 1),
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
112
|
+
x = _ref2$xy[0],
|
|
113
|
+
elapsedTime = _ref2.elapsedTime,
|
|
114
|
+
active = _ref2.active;
|
|
121
115
|
if (!active && elapsedTime > 300) {
|
|
122
116
|
return;
|
|
123
117
|
}
|
|
124
|
-
|
|
125
118
|
seekTemporary(x);
|
|
126
119
|
},
|
|
127
120
|
onDragStart: function onDragStart(_ref3) {
|
|
128
121
|
var _ref3$xy = _slicedToArray__default["default"](_ref3.xy, 1),
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
122
|
+
x = _ref3$xy[0],
|
|
123
|
+
elapsedTime = _ref3.elapsedTime,
|
|
124
|
+
active = _ref3.active;
|
|
133
125
|
if (!active && elapsedTime > 300) {
|
|
134
126
|
return;
|
|
135
127
|
}
|
|
136
|
-
|
|
137
128
|
seekTemporary(x);
|
|
138
129
|
},
|
|
139
130
|
onDragEnd: function onDragEnd(_ref4) {
|
|
140
131
|
var _ref4$xy = _slicedToArray__default["default"](_ref4.xy, 1),
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
x = _ref4$xy[0];
|
|
143
133
|
seekFromX(x);
|
|
144
134
|
setTimeout(function () {
|
|
145
135
|
setCurrentSeek(null);
|
|
@@ -179,9 +169,7 @@ function AudioBars(_ref) {
|
|
|
179
169
|
strokeLinecap: "round"
|
|
180
170
|
});
|
|
181
171
|
})), /*#__PURE__*/React__default["default"].createElement("button", Object.assign({}, bind(), {
|
|
182
|
-
onClick:
|
|
183
|
-
return e.target !== null ? seekFromX(e.target.clientX) : null;
|
|
184
|
-
},
|
|
172
|
+
onClick: onClick,
|
|
185
173
|
type: "button",
|
|
186
174
|
className: styles$2.seekButton,
|
|
187
175
|
title: intl.formatMessage({
|
|
@@ -200,7 +188,6 @@ function AudioBars(_ref) {
|
|
|
200
188
|
})
|
|
201
189
|
})));
|
|
202
190
|
}
|
|
203
|
-
|
|
204
191
|
AudioBars.propTypes = propTypes$2;
|
|
205
192
|
AudioBars.defaultProps = defaultProps$2;
|
|
206
193
|
|
|
@@ -260,35 +247,31 @@ var defaultProps$1 = {
|
|
|
260
247
|
onDurationChange: null,
|
|
261
248
|
onVolumeChange: null
|
|
262
249
|
};
|
|
263
|
-
|
|
264
250
|
var Audio = function Audio(_ref) {
|
|
265
251
|
var media = _ref.media,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
252
|
+
mediaRef = _ref.mediaRef,
|
|
253
|
+
muted = _ref.muted,
|
|
254
|
+
autoPlay = _ref.autoPlay,
|
|
255
|
+
paused = _ref.paused,
|
|
256
|
+
loop = _ref.loop,
|
|
257
|
+
preload = _ref.preload,
|
|
258
|
+
shouldLoad = _ref.shouldLoad,
|
|
259
|
+
waveFake = _ref.waveFake,
|
|
260
|
+
withWave = _ref.withWave,
|
|
261
|
+
className = _ref.className,
|
|
262
|
+
onReady = _ref.onReady,
|
|
263
|
+
onPlay = _ref.onPlay,
|
|
264
|
+
onPause = _ref.onPause,
|
|
265
|
+
onEnded = _ref.onEnded,
|
|
266
|
+
onSeeked = _ref.onSeeked,
|
|
267
|
+
onTimeUpdate = _ref.onTimeUpdate,
|
|
268
|
+
onProgressStep = _ref.onProgressStep,
|
|
269
|
+
customOnDurationChange = _ref.onDurationChange,
|
|
270
|
+
customOnVolumeChange = _ref.onVolumeChange;
|
|
286
271
|
var _ref2 = media || {},
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
272
|
+
_ref2$url = _ref2.url,
|
|
273
|
+
url = _ref2$url === void 0 ? null : _ref2$url;
|
|
290
274
|
var _ref4 = React.useRef(null);
|
|
291
|
-
|
|
292
275
|
var currentTime = hooks.useMediaCurrentTime(_ref4.current, {
|
|
293
276
|
id: url,
|
|
294
277
|
disabled: paused || !withWave && onProgressStep === null
|
|
@@ -298,7 +281,9 @@ var Audio = function Audio(_ref) {
|
|
|
298
281
|
});
|
|
299
282
|
var duration = hooks.useMediaDuration(_ref4.current, {
|
|
300
283
|
id: url
|
|
301
|
-
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// const audioLevels = useMediaWaveform(media, {
|
|
302
287
|
// fake: waveFake,
|
|
303
288
|
// reduceBufferFactor,
|
|
304
289
|
// });
|
|
@@ -315,36 +300,28 @@ var Audio = function Audio(_ref) {
|
|
|
315
300
|
}, [duration, customOnDurationChange]);
|
|
316
301
|
var onVolumeChange = React.useCallback(function () {
|
|
317
302
|
var _ref$current = _ref4.current,
|
|
318
|
-
|
|
319
|
-
|
|
303
|
+
element = _ref$current === void 0 ? null : _ref$current;
|
|
320
304
|
if (element === null) {
|
|
321
305
|
return;
|
|
322
306
|
}
|
|
323
|
-
|
|
324
307
|
if (customOnVolumeChange !== null) {
|
|
325
308
|
customOnVolumeChange(element.volume);
|
|
326
309
|
}
|
|
327
310
|
}, [_ref4.current, customOnVolumeChange]);
|
|
328
311
|
var onWavePlay = React.useCallback(function () {
|
|
329
312
|
var _ref$current2 = _ref4.current,
|
|
330
|
-
|
|
331
|
-
|
|
313
|
+
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
332
314
|
if (element === null) {
|
|
333
315
|
return;
|
|
334
316
|
}
|
|
335
|
-
|
|
336
317
|
element.play();
|
|
337
318
|
}, [_ref4.current]);
|
|
338
319
|
var onWaveSeek = React.useCallback(function (newTime) {
|
|
339
320
|
var _ref$current3 = _ref4.current,
|
|
340
|
-
|
|
341
|
-
|
|
321
|
+
element = _ref$current3 === void 0 ? null : _ref$current3;
|
|
342
322
|
if (element === null) {
|
|
343
323
|
return;
|
|
344
324
|
}
|
|
345
|
-
|
|
346
|
-
console.log('fuck off', newTime);
|
|
347
|
-
|
|
348
325
|
if (isNumber__default["default"](newTime)) {
|
|
349
326
|
element.currentTime = newTime;
|
|
350
327
|
}
|
|
@@ -356,14 +333,11 @@ var Audio = function Audio(_ref) {
|
|
|
356
333
|
}, [waveReady, onReady]);
|
|
357
334
|
React.useEffect(function () {
|
|
358
335
|
var _ref$current4 = _ref4.current,
|
|
359
|
-
|
|
360
|
-
|
|
336
|
+
element = _ref$current4 === void 0 ? null : _ref$current4;
|
|
361
337
|
if (element === null) {
|
|
362
338
|
return;
|
|
363
339
|
}
|
|
364
|
-
|
|
365
340
|
var isPaused = element.paused;
|
|
366
|
-
|
|
367
341
|
if (paused && !isPaused) {
|
|
368
342
|
element.pause();
|
|
369
343
|
} else if (!paused && isPaused) {
|
|
@@ -383,7 +357,6 @@ var Audio = function Audio(_ref) {
|
|
|
383
357
|
key: url,
|
|
384
358
|
ref: function ref(newRef) {
|
|
385
359
|
_ref4.current = newRef;
|
|
386
|
-
|
|
387
360
|
if (mediaRef !== null && isFunction__default["default"](mediaRef)) {
|
|
388
361
|
mediaRef(newRef);
|
|
389
362
|
} else if (mediaRef !== null) {
|
|
@@ -404,7 +377,8 @@ var Audio = function Audio(_ref) {
|
|
|
404
377
|
onVolumeChange: onVolumeChange
|
|
405
378
|
}), withWave ? /*#__PURE__*/React__default["default"].createElement(AudioBars, {
|
|
406
379
|
className: styles$1.wave,
|
|
407
|
-
progress: progress
|
|
380
|
+
progress: progress
|
|
381
|
+
// {...waveProps}
|
|
408
382
|
,
|
|
409
383
|
duration: duration,
|
|
410
384
|
playing: !paused,
|
|
@@ -412,7 +386,6 @@ var Audio = function Audio(_ref) {
|
|
|
412
386
|
play: onWavePlay
|
|
413
387
|
}) : null);
|
|
414
388
|
};
|
|
415
|
-
|
|
416
389
|
Audio.propTypes = propTypes$1;
|
|
417
390
|
Audio.defaultProps = defaultProps$1;
|
|
418
391
|
var Audio$1 = /*#__PURE__*/React__default["default"].forwardRef(function (props, ref) {
|
|
@@ -453,58 +426,54 @@ var defaultProps = {
|
|
|
453
426
|
onResume: null,
|
|
454
427
|
onReady: null
|
|
455
428
|
};
|
|
456
|
-
|
|
457
429
|
function AudioWave(_ref) {
|
|
458
430
|
var currentTime = _ref.currentTime,
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
431
|
+
duration = _ref.duration,
|
|
432
|
+
playing = _ref.playing,
|
|
433
|
+
sampleWidth = _ref.sampleWidth,
|
|
434
|
+
sampleMargin = _ref.sampleMargin,
|
|
435
|
+
minSampleHeight = _ref.minSampleHeight,
|
|
436
|
+
backgroundColor = _ref.backgroundColor,
|
|
437
|
+
progressColor = _ref.progressColor,
|
|
438
|
+
audioLevels = _ref.audioLevels,
|
|
439
|
+
className = _ref.className,
|
|
440
|
+
onSeek = _ref.onSeek,
|
|
441
|
+
onResume = _ref.onResume,
|
|
442
|
+
onReady = _ref.onReady;
|
|
471
443
|
var canvasBackgroundRef = React.useRef(null);
|
|
472
444
|
var canvasProgressRef = React.useRef(null);
|
|
473
445
|
var mainColor = React.useMemo(function () {
|
|
474
446
|
var _ref2 = backgroundColor || {},
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
447
|
+
_ref2$color = _ref2.color,
|
|
448
|
+
color = _ref2$color === void 0 ? 'white' : _ref2$color;
|
|
478
449
|
return color;
|
|
479
450
|
}, [backgroundColor]);
|
|
480
451
|
var alternateColor = React.useMemo(function () {
|
|
481
452
|
return utils.getContrastingColor(backgroundColor, progressColor);
|
|
482
453
|
}, [progressColor, backgroundColor]);
|
|
483
|
-
|
|
484
454
|
var _useDimensionObserver = hooks.useDimensionObserver(),
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
455
|
+
elRef = _useDimensionObserver.ref,
|
|
456
|
+
_useDimensionObserver2 = _useDimensionObserver.width,
|
|
457
|
+
elWidth = _useDimensionObserver2 === void 0 ? null : _useDimensionObserver2,
|
|
458
|
+
elHeight = _useDimensionObserver.height;
|
|
489
459
|
|
|
460
|
+
// Linear animation for progress bar
|
|
490
461
|
|
|
491
462
|
var _useSpring = core$1.useSpring(function () {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
463
|
+
return {
|
|
464
|
+
x: 0,
|
|
465
|
+
config: {
|
|
466
|
+
duration: 0
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}),
|
|
470
|
+
_useSpring2 = _slicedToArray__default["default"](_useSpring, 2),
|
|
471
|
+
springProps = _useSpring2[0],
|
|
472
|
+
setSpringProps = _useSpring2[1];
|
|
503
473
|
React.useEffect(function () {
|
|
504
474
|
if (currentTime === null || duration === null) {
|
|
505
475
|
return;
|
|
506
476
|
}
|
|
507
|
-
|
|
508
477
|
var progress = currentTime / duration;
|
|
509
478
|
setSpringProps.start({
|
|
510
479
|
reset: true,
|
|
@@ -519,32 +488,35 @@ function AudioWave(_ref) {
|
|
|
519
488
|
duration: (duration - currentTime) * 1000
|
|
520
489
|
}
|
|
521
490
|
});
|
|
522
|
-
}, [playing, duration, currentTime, setSpringProps]);
|
|
491
|
+
}, [playing, duration, currentTime, setSpringProps]);
|
|
492
|
+
|
|
493
|
+
// draw canvas
|
|
523
494
|
|
|
524
495
|
React.useEffect(function () {
|
|
525
496
|
if (audioLevels === null || audioLevels.length === 0 || elRef.current === null) {
|
|
526
497
|
return;
|
|
527
498
|
}
|
|
528
|
-
|
|
529
499
|
var sampleOuterWidth = sampleWidth + sampleMargin * 2;
|
|
530
|
-
var samplesCount = Math.floor(elWidth / sampleOuterWidth);
|
|
500
|
+
var samplesCount = Math.floor(elWidth / sampleOuterWidth);
|
|
501
|
+
|
|
502
|
+
// const amplitudes = [];
|
|
503
|
+
|
|
531
504
|
// get samples
|
|
532
505
|
|
|
533
506
|
var levelsBySamples = audioLevels.length / samplesCount;
|
|
534
|
-
|
|
535
507
|
var amplitudes = _toConsumableArray__default["default"](Array(samplesCount).keys()).reduce(function (newAmplitudes, index) {
|
|
536
508
|
var levelStartIndex = index * levelsBySamples;
|
|
537
509
|
var levelEndIndex = levelStartIndex + levelsBySamples;
|
|
538
510
|
var newValues = [];
|
|
539
|
-
|
|
540
511
|
for (var i = Math.floor(levelStartIndex); i < Math.round(levelEndIndex); i += 1) {
|
|
541
512
|
newValues.push(audioLevels[i]);
|
|
542
513
|
}
|
|
543
|
-
|
|
544
514
|
return levelsBySamples >= 1 ? [].concat(_toConsumableArray__default["default"](newAmplitudes), [newValues.reduce(function (total, value) {
|
|
545
515
|
return total + value;
|
|
546
516
|
}, 0) / newValues.length]) : [].concat(_toConsumableArray__default["default"](newAmplitudes), newValues);
|
|
547
|
-
}, []);
|
|
517
|
+
}, []);
|
|
518
|
+
|
|
519
|
+
// for (let sampleI = 0; sampleI < samplesCount; sampleI += levelsBySamples) {
|
|
548
520
|
// // if (levelsBySamples >= 1) {
|
|
549
521
|
// // const sampleSize = Math.floor(levelsBySamples);
|
|
550
522
|
// // const sampleStart = sampleSize * sampleI;
|
|
@@ -562,15 +534,14 @@ function AudioWave(_ref) {
|
|
|
562
534
|
// // }
|
|
563
535
|
// // }
|
|
564
536
|
// }
|
|
565
|
-
|
|
566
|
-
|
|
567
537
|
var minAmplitude = Math.min.apply(Math, _toConsumableArray__default["default"](amplitudes));
|
|
568
538
|
var maxAmplitude = Math.max.apply(Math, _toConsumableArray__default["default"](amplitudes));
|
|
569
539
|
var delta = maxAmplitude - minAmplitude;
|
|
570
540
|
var normalizedAmplitudes = amplitudes.map(function (n) {
|
|
571
541
|
return (n - minAmplitude) / delta;
|
|
572
|
-
});
|
|
542
|
+
});
|
|
573
543
|
|
|
544
|
+
// draw samples
|
|
574
545
|
var canvasBg = canvasBackgroundRef.current;
|
|
575
546
|
var canvasProgress = canvasProgressRef.current;
|
|
576
547
|
var scale = typeof window !== 'undefined' ? window.devicePixelRatio : 1;
|
|
@@ -592,23 +563,20 @@ function AudioWave(_ref) {
|
|
|
592
563
|
ctxBG.fillRect(Math.round(sampleX), Math.round(sampleY), sampleWidth, Math.round(sampleHeight));
|
|
593
564
|
ctxProgress.fillRect(Math.round(sampleX), Math.round(sampleY), sampleWidth, Math.round(sampleHeight));
|
|
594
565
|
});
|
|
595
|
-
|
|
596
566
|
if (onReady !== null) {
|
|
597
567
|
onReady();
|
|
598
568
|
}
|
|
599
|
-
}, [audioLevels, sampleWidth, sampleMargin, minSampleHeight, elWidth, elHeight, mainColor, alternateColor, onReady]);
|
|
569
|
+
}, [audioLevels, sampleWidth, sampleMargin, minSampleHeight, elWidth, elHeight, mainColor, alternateColor, onReady]);
|
|
600
570
|
|
|
571
|
+
// User events
|
|
601
572
|
var seekFromX = React.useCallback(function (x) {
|
|
602
573
|
var _elRef$current$getBou = elRef.current.getBoundingClientRect(),
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
574
|
+
elX = _elRef$current$getBou.left,
|
|
575
|
+
width = _elRef$current$getBou.width;
|
|
606
576
|
var progress = Math.max(0, Math.min(1, (x - elX) / width));
|
|
607
|
-
|
|
608
577
|
if (onSeek !== null && duration !== null) {
|
|
609
578
|
onSeek(progress * duration);
|
|
610
579
|
}
|
|
611
|
-
|
|
612
580
|
if (!playing) {
|
|
613
581
|
onResume();
|
|
614
582
|
}
|
|
@@ -616,14 +584,12 @@ function AudioWave(_ref) {
|
|
|
616
584
|
var bind = react.useGesture({
|
|
617
585
|
onDrag: function onDrag(_ref3) {
|
|
618
586
|
var _ref3$xy = _slicedToArray__default["default"](_ref3.xy, 1),
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
587
|
+
x = _ref3$xy[0],
|
|
588
|
+
elapsedTime = _ref3.elapsedTime,
|
|
589
|
+
active = _ref3.active;
|
|
623
590
|
if (!active && elapsedTime > 300) {
|
|
624
591
|
return;
|
|
625
592
|
}
|
|
626
|
-
|
|
627
593
|
seekFromX(x);
|
|
628
594
|
}
|
|
629
595
|
}, {
|
|
@@ -648,7 +614,6 @@ function AudioWave(_ref) {
|
|
|
648
614
|
}
|
|
649
615
|
}));
|
|
650
616
|
}
|
|
651
|
-
|
|
652
617
|
AudioWave.propTypes = propTypes;
|
|
653
618
|
AudioWave.defaultProps = defaultProps;
|
|
654
619
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-audio",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.318",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -52,21 +52,21 @@
|
|
|
52
52
|
"@fortawesome/fontawesome-svg-core": "^1.2.32",
|
|
53
53
|
"@fortawesome/free-solid-svg-icons": "^5.15.1",
|
|
54
54
|
"@fortawesome/react-fontawesome": "^0.1.13",
|
|
55
|
-
"@micromag/core": "^0.3.
|
|
56
|
-
"@micromag/element-closed-captions": "^0.3.
|
|
57
|
-
"@micromag/element-media-controls": "^0.3.
|
|
58
|
-
"@react-spring/core": "^9.
|
|
59
|
-
"@react-spring/web": "^9.
|
|
55
|
+
"@micromag/core": "^0.3.318",
|
|
56
|
+
"@micromag/element-closed-captions": "^0.3.318",
|
|
57
|
+
"@micromag/element-media-controls": "^0.3.318",
|
|
58
|
+
"@react-spring/core": "^9.6.1",
|
|
59
|
+
"@react-spring/web": "^9.6.1",
|
|
60
60
|
"@use-gesture/react": "^10.2.4",
|
|
61
61
|
"classnames": "^2.2.6",
|
|
62
62
|
"lodash": "^4.17.21",
|
|
63
63
|
"prop-types": "^15.7.2",
|
|
64
64
|
"react-intl": "^5.12.1",
|
|
65
|
-
"uuid": "^
|
|
65
|
+
"uuid": "^9.0.0",
|
|
66
66
|
"whatwg-fetch": "^3.6.1"
|
|
67
67
|
},
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "7d1a296e0c0d410e1225279e1f19e3a7715bfa96"
|
|
72
72
|
}
|