@micromag/core 0.4.65 → 0.4.66

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/contexts.d.ts CHANGED
@@ -369,6 +369,7 @@ interface PlaybackContext {
369
369
  controlsVisible: boolean;
370
370
  media: MediaElement | null;
371
371
  hasAudio: boolean | null;
372
+ isBackground: boolean;
372
373
  controlsTheme: PlaybackControlsTheme | null;
373
374
  currentQualityLevel: number | null;
374
375
  setMuted: (muted: boolean) => void;
package/es/contexts.js CHANGED
@@ -1006,6 +1006,9 @@ function PanelsProvider(_ref2) {
1006
1006
  });
1007
1007
  }
1008
1008
 
1009
+ function mediaElementIsPlaying(media) {
1010
+ return media !== null && !!(media.currentTime > 0 && !media.paused && !media.ended && media.readyState > 2);
1011
+ }
1009
1012
  var defaultControlsThemeValue = {
1010
1013
  seekBarOnly: false,
1011
1014
  color: null,
@@ -1019,6 +1022,7 @@ var PlaybackContext = /*#__PURE__*/createContext({
1019
1022
  controlsSuggestPlay: false,
1020
1023
  controlsVisible: false,
1021
1024
  hasAudio: false,
1025
+ isBackground: false,
1022
1026
  media: null,
1023
1027
  controlsTheme: defaultControlsThemeValue,
1024
1028
  currentQualityLevel: null,
@@ -1044,26 +1048,37 @@ var usePlaybackMediaRef = function usePlaybackMediaRef() {
1044
1048
  setMedia = _usePlaybackContext.setMedia,
1045
1049
  setIsBackground = _usePlaybackContext.setIsBackground,
1046
1050
  media = _usePlaybackContext.media,
1047
- isBackground = _usePlaybackContext.isBackground;
1051
+ isBackground = _usePlaybackContext.isBackground,
1052
+ playing = _usePlaybackContext.playing;
1048
1053
  var mediaRef = useRef(null);
1049
1054
 
1050
1055
  // Cleanup: clear media registration when this screen deactivates or unmounts.
1051
1056
  // Note: we cannot check mediaRef.current here because React clears callback refs
1052
1057
  // before running effect cleanups, so mediaRef.current is always null at this point.
1053
1058
  useEffect(function () {
1054
- var currentMedia = mediaRef.current;
1059
+ var _mediaRef$current = mediaRef.current,
1060
+ currentMedia = _mediaRef$current === void 0 ? null : _mediaRef$current;
1055
1061
  return function () {
1056
1062
  if (active) {
1057
- var playing = currentMedia !== null && !!(currentMedia.currentTime > 0 && !currentMedia.paused && !currentMedia.ended && currentMedia.readyState > 2);
1063
+ var shouldPause = currentMedia !== null && mediaElementIsPlaying(currentMedia);
1058
1064
  setMedia(null);
1059
1065
  setIsBackground(false);
1060
- if (playing) {
1066
+ if (shouldPause) {
1061
1067
  currentMedia.pause();
1062
1068
  }
1063
1069
  }
1064
1070
  };
1065
1071
  }, [active, setMedia, setIsBackground, updateKey]);
1066
1072
 
1073
+ // Play early in the process
1074
+ var currentMedia = mediaRef.current;
1075
+ var forcePlayingRef = useRef(false);
1076
+ var shouldForcePlaying = active && currentMedia !== null && playing && !forcePlayingRef.current && !mediaElementIsPlaying(currentMedia);
1077
+ if (shouldForcePlaying) {
1078
+ forcePlayingRef.current = true;
1079
+ currentMedia.play();
1080
+ }
1081
+
1067
1082
  // Register media with context when active and no media is registered
1068
1083
  useEffect(function () {
1069
1084
  if (!active || mediaRef.current === null || mediaRef.current === media && background === isBackground) {
package/lib/contexts.js CHANGED
@@ -1006,6 +1006,9 @@ function PanelsProvider(_ref2) {
1006
1006
  });
1007
1007
  }
1008
1008
 
1009
+ function mediaElementIsPlaying(media) {
1010
+ return media !== null && !!(media.currentTime > 0 && !media.paused && !media.ended && media.readyState > 2);
1011
+ }
1009
1012
  var defaultControlsThemeValue = {
1010
1013
  seekBarOnly: false,
1011
1014
  color: null,
@@ -1019,6 +1022,7 @@ var PlaybackContext = /*#__PURE__*/React.createContext({
1019
1022
  controlsSuggestPlay: false,
1020
1023
  controlsVisible: false,
1021
1024
  hasAudio: false,
1025
+ isBackground: false,
1022
1026
  media: null,
1023
1027
  controlsTheme: defaultControlsThemeValue,
1024
1028
  currentQualityLevel: null,
@@ -1044,26 +1048,37 @@ var usePlaybackMediaRef = function usePlaybackMediaRef() {
1044
1048
  setMedia = _usePlaybackContext.setMedia,
1045
1049
  setIsBackground = _usePlaybackContext.setIsBackground,
1046
1050
  media = _usePlaybackContext.media,
1047
- isBackground = _usePlaybackContext.isBackground;
1051
+ isBackground = _usePlaybackContext.isBackground,
1052
+ playing = _usePlaybackContext.playing;
1048
1053
  var mediaRef = React.useRef(null);
1049
1054
 
1050
1055
  // Cleanup: clear media registration when this screen deactivates or unmounts.
1051
1056
  // Note: we cannot check mediaRef.current here because React clears callback refs
1052
1057
  // before running effect cleanups, so mediaRef.current is always null at this point.
1053
1058
  React.useEffect(function () {
1054
- var currentMedia = mediaRef.current;
1059
+ var _mediaRef$current = mediaRef.current,
1060
+ currentMedia = _mediaRef$current === void 0 ? null : _mediaRef$current;
1055
1061
  return function () {
1056
1062
  if (active) {
1057
- var playing = currentMedia !== null && !!(currentMedia.currentTime > 0 && !currentMedia.paused && !currentMedia.ended && currentMedia.readyState > 2);
1063
+ var shouldPause = currentMedia !== null && mediaElementIsPlaying(currentMedia);
1058
1064
  setMedia(null);
1059
1065
  setIsBackground(false);
1060
- if (playing) {
1066
+ if (shouldPause) {
1061
1067
  currentMedia.pause();
1062
1068
  }
1063
1069
  }
1064
1070
  };
1065
1071
  }, [active, setMedia, setIsBackground, updateKey]);
1066
1072
 
1073
+ // Play early in the process
1074
+ var currentMedia = mediaRef.current;
1075
+ var forcePlayingRef = React.useRef(false);
1076
+ var shouldForcePlaying = active && currentMedia !== null && playing && !forcePlayingRef.current && !mediaElementIsPlaying(currentMedia);
1077
+ if (shouldForcePlaying) {
1078
+ forcePlayingRef.current = true;
1079
+ currentMedia.play();
1080
+ }
1081
+
1067
1082
  // Register media with context when active and no media is registered
1068
1083
  React.useEffect(function () {
1069
1084
  if (!active || mediaRef.current === null || mediaRef.current === media && background === isBackground) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/core",
3
- "version": "0.4.65",
3
+ "version": "0.4.66",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -161,6 +161,6 @@
161
161
  "access": "public",
162
162
  "registry": "https://registry.npmjs.org/"
163
163
  },
164
- "gitHead": "33460a352e56298ae450392b04c09503ecfeae05",
164
+ "gitHead": "61e9d9511073041dc7900185d49a559126119450",
165
165
  "types": "es/index.d.ts"
166
166
  }