@micromag/element-audio 0.3.547 → 0.3.567
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/es/index.js +39 -20
- package/package.json +2 -2
package/es/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
3
|
import classNames from 'classnames';
|
|
3
4
|
import isFunction from 'lodash/isFunction';
|
|
4
5
|
import isNumber from 'lodash/isNumber';
|
|
@@ -7,7 +8,6 @@ import React, { useState, useMemo, useCallback, useRef, useEffect } from 'react'
|
|
|
7
8
|
import { PropTypes as PropTypes$1 } from '@micromag/core';
|
|
8
9
|
import { useDimensionObserver, useMediaCurrentTime, useMediaReady, useMediaDuration, useMediaLoad, useProgressSteps } from '@micromag/core/hooks';
|
|
9
10
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
10
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
11
11
|
import { useGesture } from '@use-gesture/react';
|
|
12
12
|
import { useIntl } from 'react-intl';
|
|
13
13
|
import { useSpring } from '@react-spring/core';
|
|
@@ -263,18 +263,37 @@ var Audio = function Audio(_ref) {
|
|
|
263
263
|
onPlayError = _ref.onPlayError;
|
|
264
264
|
var _ref2 = media || {},
|
|
265
265
|
_ref2$url = _ref2.url,
|
|
266
|
-
url = _ref2$url === void 0 ? null : _ref2$url
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
266
|
+
url = _ref2$url === void 0 ? null : _ref2$url,
|
|
267
|
+
_ref2$files = _ref2.files,
|
|
268
|
+
files = _ref2$files === void 0 ? null : _ref2$files;
|
|
269
|
+
var srcUrl = useMemo(function () {
|
|
270
|
+
if (files) {
|
|
271
|
+
var filesAsEntries = Object.entries(files);
|
|
272
|
+
var _ref3 = filesAsEntries.find(function (_ref5) {
|
|
273
|
+
var _ref6 = _slicedToArray(_ref5, 1),
|
|
274
|
+
key = _ref6[0];
|
|
275
|
+
return key === 'mp3';
|
|
276
|
+
}) || [],
|
|
277
|
+
_ref4 = _slicedToArray(_ref3, 2),
|
|
278
|
+
_ref4$ = _ref4[1],
|
|
279
|
+
mp3File = _ref4$ === void 0 ? null : _ref4$;
|
|
280
|
+
if (mp3File) {
|
|
281
|
+
return mp3File.url;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return url;
|
|
285
|
+
}, [files, url]);
|
|
286
|
+
var _ref8 = useRef(null);
|
|
287
|
+
var currentTime = useMediaCurrentTime(_ref8.current, {
|
|
288
|
+
id: srcUrl,
|
|
270
289
|
disabled: paused || !withWave && onProgressStep === null,
|
|
271
290
|
updateInterval: updateInterval
|
|
272
291
|
});
|
|
273
|
-
var ready = useMediaReady(
|
|
274
|
-
id:
|
|
292
|
+
var ready = useMediaReady(_ref8.current, {
|
|
293
|
+
id: srcUrl
|
|
275
294
|
});
|
|
276
|
-
var duration = useMediaDuration(
|
|
277
|
-
id:
|
|
295
|
+
var duration = useMediaDuration(_ref8.current, {
|
|
296
|
+
id: srcUrl
|
|
278
297
|
});
|
|
279
298
|
|
|
280
299
|
// const audioLevels = useMediaWaveform(media, {
|
|
@@ -282,7 +301,7 @@ var Audio = function Audio(_ref) {
|
|
|
282
301
|
// reduceBufferFactor,
|
|
283
302
|
// });
|
|
284
303
|
|
|
285
|
-
useMediaLoad(
|
|
304
|
+
useMediaLoad(_ref8.current, {
|
|
286
305
|
preload: preload,
|
|
287
306
|
shouldLoad: shouldLoad
|
|
288
307
|
});
|
|
@@ -293,7 +312,7 @@ var Audio = function Audio(_ref) {
|
|
|
293
312
|
}
|
|
294
313
|
}, [duration, customOnDurationChange]);
|
|
295
314
|
var onVolumeChange = useCallback(function () {
|
|
296
|
-
var _ref$current =
|
|
315
|
+
var _ref$current = _ref8.current,
|
|
297
316
|
element = _ref$current === void 0 ? null : _ref$current;
|
|
298
317
|
if (element === null) {
|
|
299
318
|
return;
|
|
@@ -301,17 +320,17 @@ var Audio = function Audio(_ref) {
|
|
|
301
320
|
if (customOnVolumeChange !== null) {
|
|
302
321
|
customOnVolumeChange(element.volume);
|
|
303
322
|
}
|
|
304
|
-
}, [
|
|
323
|
+
}, [_ref8.current, customOnVolumeChange]);
|
|
305
324
|
var onWavePlay = useCallback(function () {
|
|
306
|
-
var _ref$current2 =
|
|
325
|
+
var _ref$current2 = _ref8.current,
|
|
307
326
|
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
308
327
|
if (element === null) {
|
|
309
328
|
return;
|
|
310
329
|
}
|
|
311
330
|
element.play();
|
|
312
|
-
}, [
|
|
331
|
+
}, [_ref8.current]);
|
|
313
332
|
var onWaveSeek = useCallback(function (newTime) {
|
|
314
|
-
var _ref$current3 =
|
|
333
|
+
var _ref$current3 = _ref8.current,
|
|
315
334
|
element = _ref$current3 === void 0 ? null : _ref$current3;
|
|
316
335
|
if (element === null) {
|
|
317
336
|
return;
|
|
@@ -319,14 +338,14 @@ var Audio = function Audio(_ref) {
|
|
|
319
338
|
if (isNumber(newTime)) {
|
|
320
339
|
element.currentTime = newTime;
|
|
321
340
|
}
|
|
322
|
-
}, [
|
|
341
|
+
}, [_ref8.current]);
|
|
323
342
|
useEffect(function () {
|
|
324
343
|
if (waveReady && onReady !== null) {
|
|
325
344
|
onReady();
|
|
326
345
|
}
|
|
327
346
|
}, [waveReady, onReady]);
|
|
328
347
|
useEffect(function () {
|
|
329
|
-
var _ref$current4 =
|
|
348
|
+
var _ref$current4 = _ref8.current,
|
|
330
349
|
element = _ref$current4 === void 0 ? null : _ref$current4;
|
|
331
350
|
if (element === null) {
|
|
332
351
|
return;
|
|
@@ -352,16 +371,16 @@ var Audio = function Audio(_ref) {
|
|
|
352
371
|
return /*#__PURE__*/React.createElement("div", {
|
|
353
372
|
className: classNames([styles$1.container, _defineProperty({}, className, className !== null)])
|
|
354
373
|
}, /*#__PURE__*/React.createElement("audio", {
|
|
355
|
-
key:
|
|
374
|
+
key: srcUrl,
|
|
356
375
|
ref: function ref(newRef) {
|
|
357
|
-
|
|
376
|
+
_ref8.current = newRef;
|
|
358
377
|
if (mediaRef !== null && isFunction(mediaRef)) {
|
|
359
378
|
mediaRef(newRef);
|
|
360
379
|
} else if (mediaRef !== null) {
|
|
361
380
|
mediaRef.current = newRef;
|
|
362
381
|
}
|
|
363
382
|
},
|
|
364
|
-
src:
|
|
383
|
+
src: srcUrl,
|
|
365
384
|
autoPlay: autoPlay,
|
|
366
385
|
muted: muted,
|
|
367
386
|
loop: loop,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/element-audio",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.567",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"access": "public",
|
|
75
75
|
"registry": "https://registry.npmjs.org/"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "e39cb9da7eac1d14d3d914bc1cdb6b86b44aedbf"
|
|
78
78
|
}
|