@micromag/element-audio 0.3.547 → 0.3.566
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 +38 -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,36 @@ 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 _filesAsEntries$find = filesAsEntries.find(function (_ref3) {
|
|
273
|
+
var _ref4 = _slicedToArray(_ref3, 1),
|
|
274
|
+
key = _ref4[0];
|
|
275
|
+
return key === 'mp3';
|
|
276
|
+
}),
|
|
277
|
+
_filesAsEntries$find2 = _slicedToArray(_filesAsEntries$find, 2),
|
|
278
|
+
mp3File = _filesAsEntries$find2[1];
|
|
279
|
+
if (mp3File) {
|
|
280
|
+
return mp3File.url;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return url;
|
|
284
|
+
}, [files, url]);
|
|
285
|
+
var _ref6 = useRef(null);
|
|
286
|
+
var currentTime = useMediaCurrentTime(_ref6.current, {
|
|
287
|
+
id: srcUrl,
|
|
270
288
|
disabled: paused || !withWave && onProgressStep === null,
|
|
271
289
|
updateInterval: updateInterval
|
|
272
290
|
});
|
|
273
|
-
var ready = useMediaReady(
|
|
274
|
-
id:
|
|
291
|
+
var ready = useMediaReady(_ref6.current, {
|
|
292
|
+
id: srcUrl
|
|
275
293
|
});
|
|
276
|
-
var duration = useMediaDuration(
|
|
277
|
-
id:
|
|
294
|
+
var duration = useMediaDuration(_ref6.current, {
|
|
295
|
+
id: srcUrl
|
|
278
296
|
});
|
|
279
297
|
|
|
280
298
|
// const audioLevels = useMediaWaveform(media, {
|
|
@@ -282,7 +300,7 @@ var Audio = function Audio(_ref) {
|
|
|
282
300
|
// reduceBufferFactor,
|
|
283
301
|
// });
|
|
284
302
|
|
|
285
|
-
useMediaLoad(
|
|
303
|
+
useMediaLoad(_ref6.current, {
|
|
286
304
|
preload: preload,
|
|
287
305
|
shouldLoad: shouldLoad
|
|
288
306
|
});
|
|
@@ -293,7 +311,7 @@ var Audio = function Audio(_ref) {
|
|
|
293
311
|
}
|
|
294
312
|
}, [duration, customOnDurationChange]);
|
|
295
313
|
var onVolumeChange = useCallback(function () {
|
|
296
|
-
var _ref$current =
|
|
314
|
+
var _ref$current = _ref6.current,
|
|
297
315
|
element = _ref$current === void 0 ? null : _ref$current;
|
|
298
316
|
if (element === null) {
|
|
299
317
|
return;
|
|
@@ -301,17 +319,17 @@ var Audio = function Audio(_ref) {
|
|
|
301
319
|
if (customOnVolumeChange !== null) {
|
|
302
320
|
customOnVolumeChange(element.volume);
|
|
303
321
|
}
|
|
304
|
-
}, [
|
|
322
|
+
}, [_ref6.current, customOnVolumeChange]);
|
|
305
323
|
var onWavePlay = useCallback(function () {
|
|
306
|
-
var _ref$current2 =
|
|
324
|
+
var _ref$current2 = _ref6.current,
|
|
307
325
|
element = _ref$current2 === void 0 ? null : _ref$current2;
|
|
308
326
|
if (element === null) {
|
|
309
327
|
return;
|
|
310
328
|
}
|
|
311
329
|
element.play();
|
|
312
|
-
}, [
|
|
330
|
+
}, [_ref6.current]);
|
|
313
331
|
var onWaveSeek = useCallback(function (newTime) {
|
|
314
|
-
var _ref$current3 =
|
|
332
|
+
var _ref$current3 = _ref6.current,
|
|
315
333
|
element = _ref$current3 === void 0 ? null : _ref$current3;
|
|
316
334
|
if (element === null) {
|
|
317
335
|
return;
|
|
@@ -319,14 +337,14 @@ var Audio = function Audio(_ref) {
|
|
|
319
337
|
if (isNumber(newTime)) {
|
|
320
338
|
element.currentTime = newTime;
|
|
321
339
|
}
|
|
322
|
-
}, [
|
|
340
|
+
}, [_ref6.current]);
|
|
323
341
|
useEffect(function () {
|
|
324
342
|
if (waveReady && onReady !== null) {
|
|
325
343
|
onReady();
|
|
326
344
|
}
|
|
327
345
|
}, [waveReady, onReady]);
|
|
328
346
|
useEffect(function () {
|
|
329
|
-
var _ref$current4 =
|
|
347
|
+
var _ref$current4 = _ref6.current,
|
|
330
348
|
element = _ref$current4 === void 0 ? null : _ref$current4;
|
|
331
349
|
if (element === null) {
|
|
332
350
|
return;
|
|
@@ -352,16 +370,16 @@ var Audio = function Audio(_ref) {
|
|
|
352
370
|
return /*#__PURE__*/React.createElement("div", {
|
|
353
371
|
className: classNames([styles$1.container, _defineProperty({}, className, className !== null)])
|
|
354
372
|
}, /*#__PURE__*/React.createElement("audio", {
|
|
355
|
-
key:
|
|
373
|
+
key: srcUrl,
|
|
356
374
|
ref: function ref(newRef) {
|
|
357
|
-
|
|
375
|
+
_ref6.current = newRef;
|
|
358
376
|
if (mediaRef !== null && isFunction(mediaRef)) {
|
|
359
377
|
mediaRef(newRef);
|
|
360
378
|
} else if (mediaRef !== null) {
|
|
361
379
|
mediaRef.current = newRef;
|
|
362
380
|
}
|
|
363
381
|
},
|
|
364
|
-
src:
|
|
382
|
+
src: srcUrl,
|
|
365
383
|
autoPlay: autoPlay,
|
|
366
384
|
muted: muted,
|
|
367
385
|
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.566",
|
|
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": "7ee1998bfc00f5a841711346ac8ca21dba439df7"
|
|
78
78
|
}
|