@micromag/element-video 0.4.66 → 0.4.69

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.
Files changed (2) hide show
  1. package/es/index.js +14 -12
  2. package/package.json +4 -4
package/es/index.js CHANGED
@@ -6,8 +6,8 @@ import classNames from 'classnames';
6
6
  import isFunction from 'lodash/isFunction';
7
7
  import { useMemo, useState, useEffect, useRef, useCallback } from 'react';
8
8
  import { Spinner } from '@micromag/core/components';
9
+ import { useSetting, mediaElementIsPlaying } from '@micromag/core/contexts';
9
10
  import { useMediaThumbnail, useMediaCurrentTime, useMediaDuration, useMediaReady, useProgressSteps } from '@micromag/core/hooks';
10
- import { useSetting } from '@micromag/core/contexts';
11
11
  import { getMediaFilesAsArray, getVideoSupportedMimes } from '@micromag/core/utils';
12
12
  import { jsx, jsxs } from 'react/jsx-runtime';
13
13
 
@@ -250,38 +250,40 @@ function Video(_ref) {
250
250
  onReady();
251
251
  }
252
252
  }, [ready, onReady]);
253
- var finalPreload = shouldLoad ? preload : 'none';
254
- var _useState5 = useState(finalPreload === 'auto' || finalPreload === 'metadata'),
255
- _useState6 = _slicedToArray(_useState5, 2),
256
- wasPreloaded = _useState6[0],
257
- setWasPreloaded = _useState6[1];
253
+ var _useState5 = useState(shouldLoad ? preload : 'none'),
254
+ _useState6 = _slicedToArray(_useState5, 1),
255
+ finalPreload = _useState6[0];
256
+ var _useState7 = useState(finalPreload === 'auto' || finalPreload === 'metadata'),
257
+ _useState8 = _slicedToArray(_useState7, 2),
258
+ wasPreloaded = _useState8[0],
259
+ setWasPreloaded = _useState8[1];
258
260
  useEffect(function () {
259
261
  var _ref$current2 = _ref6.current,
260
262
  element = _ref$current2 === void 0 ? null : _ref$current2;
261
- if (shouldLoad && !wasPreloaded && element !== null) {
263
+ if (element !== null && shouldLoad && (!wasPreloaded || element.readyState === 0)) {
262
264
  try {
263
265
  element.load();
264
266
  } catch (_unused) {}
265
267
  setWasPreloaded(true);
266
268
  }
267
- }, [shouldLoad, wasPreloaded]);
269
+ }, [shouldLoad, wasPreloaded, mediaUrl, paused]);
268
270
  useEffect(function () {
269
271
  var _ref$current3 = _ref6.current,
270
272
  element = _ref$current3 === void 0 ? null : _ref$current3;
271
273
  if (element === null || mediaUrl === null) {
272
274
  return;
273
275
  }
274
- var isPaused = element.paused;
275
- if (paused && !isPaused) {
276
+ var isPlaying = mediaElementIsPlaying(element);
277
+ if (paused && isPlaying) {
276
278
  element.pause();
277
- } else if (!paused && isPaused) {
279
+ } else if (!paused && !isPlaying) {
278
280
  element.play()["catch"](function (e) {
279
281
  if (onPlayError !== null) {
280
282
  onPlayError(e);
281
283
  }
282
284
  });
283
285
  }
284
- }, [paused, media, mediaUrl, onPlayError]);
286
+ }, [paused, media, mediaUrl, shouldLoad, wasPreloaded]);
285
287
  useProgressSteps({
286
288
  currentTime: currentTime,
287
289
  duration: duration,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/element-video",
3
- "version": "0.4.66",
3
+ "version": "0.4.69",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -60,8 +60,8 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "@babel/runtime": "^7.28.6",
63
- "@micromag/core": "^0.4.66",
64
- "@micromag/element-closed-captions": "^0.4.66",
63
+ "@micromag/core": "^0.4.69",
64
+ "@micromag/element-closed-captions": "^0.4.69",
65
65
  "classnames": "^2.2.6",
66
66
  "hls.js": "^1.5.15",
67
67
  "lodash": "^4.17.23",
@@ -72,6 +72,6 @@
72
72
  "access": "public",
73
73
  "registry": "https://registry.npmjs.org/"
74
74
  },
75
- "gitHead": "61e9d9511073041dc7900185d49a559126119450",
75
+ "gitHead": "509e113dc06022d6092e4aac9f47ccd5facfd59d",
76
76
  "types": "es/index.d.ts"
77
77
  }