@exode-team/react-recorder 1.1.8 → 1.1.9

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.
@@ -6,6 +6,7 @@
6
6
  export interface VoiceMessagePlayerRef {
7
7
  play: () => void;
8
8
  prefetch: () => void;
9
+ seekToTime: (seconds: number) => void;
9
10
  }
10
11
  declare const VoiceMessagePlayer: any;
11
12
  export { VoiceMessagePlayer };
@@ -1 +1 @@
1
- {"version":3,"file":"VoiceMessagePlayer.d.ts","sourceRoot":"","sources":["../../../src/components/VoiceMessagePlayer/VoiceMessagePlayer.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AA0BH,MAAM,WAAW,qBAAqB;IAClC,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,QAAQ,EAAE,MAAM,IAAI,CAAC;CACxB;AAeD,QAAA,MAAM,kBAAkB,KA8MtB,CAAC;AAGH,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
1
+ {"version":3,"file":"VoiceMessagePlayer.d.ts","sourceRoot":"","sources":["../../../src/components/VoiceMessagePlayer/VoiceMessagePlayer.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AA0BH,MAAM,WAAW,qBAAqB;IAClC,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAeD,QAAA,MAAM,kBAAkB,KAuNtB,CAAC;AAGH,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"useVoiceMessagePlayer.d.ts","sourceRoot":"","sources":["../../src/hooks/useVoiceMessagePlayer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,KAAK,EAAE,4BAA4B,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAG1F,QAAA,MAAM,qBAAqB,GAAI,SAAS,4BAA4B,KAAG,2BA6JtE,CAAC;AAGF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
1
+ {"version":3,"file":"useVoiceMessagePlayer.d.ts","sourceRoot":"","sources":["../../src/hooks/useVoiceMessagePlayer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,KAAK,EAAE,4BAA4B,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAG1F,QAAA,MAAM,qBAAqB,GAAI,SAAS,4BAA4B,KAAG,2BAqMtE,CAAC;AAGF,OAAO,EAAE,qBAAqB,EAAE,CAAC"}
package/dist/index.cjs CHANGED
@@ -1045,15 +1045,44 @@ const useVoiceMessagePlayer = (options) => {
1045
1045
  setIsPlaying(false);
1046
1046
  }
1047
1047
  }, [isLoading, stopThis, audioRef]);
1048
- const seekTo = React.useCallback((seekProgress) => {
1048
+ const seekTo = React.useCallback((seekPercent) => {
1049
1049
  const audio = audioRef.current;
1050
1050
  if (!audio || !isFinite(audio.duration)) {
1051
1051
  return;
1052
1052
  }
1053
- const time = seekProgress * audio.duration;
1053
+ const time = seekPercent * audio.duration;
1054
1054
  audio.currentTime = time;
1055
1055
  setCurrentTime(time);
1056
1056
  }, [audioRef]);
1057
+ /** Seek to a specific time in seconds and start playback */
1058
+ const seekToTime = React.useCallback((seconds) => {
1059
+ const audio = audioRef.current;
1060
+ if (audio && isFinite(audio.duration)) {
1061
+ audioPlaybackManager.stopOthers(stopThis);
1062
+ audio.currentTime = Math.max(0, Math.min(seconds, audio.duration));
1063
+ setCurrentTime(audio.currentTime);
1064
+ audio.play()
1065
+ .then(() => setIsPlaying(true))
1066
+ .catch(() => setIsPlaying(false));
1067
+ }
1068
+ else {
1069
+ void ensureAudioLoaded().then(() => {
1070
+ const loadedAudio = audioRef.current;
1071
+ if (loadedAudio) {
1072
+ audioPlaybackManager.stopOthers(stopThis);
1073
+ loadedAudio.currentTime = Math.max(0, Math.min(seconds, loadedAudio.duration || seconds));
1074
+ setCurrentTime(loadedAudio.currentTime);
1075
+ loadedAudio.play()
1076
+ .then(() => setIsPlaying(true))
1077
+ .catch(() => setIsPlaying(false));
1078
+ }
1079
+ });
1080
+ }
1081
+ }, [
1082
+ audioRef,
1083
+ stopThis,
1084
+ ensureAudioLoaded,
1085
+ ]);
1057
1086
  /** Sync external duration */
1058
1087
  React.useEffect(() => {
1059
1088
  if (externalDuration) {
@@ -1070,6 +1099,7 @@ const useVoiceMessagePlayer = (options) => {
1070
1099
  currentTime,
1071
1100
  waveformLevels,
1072
1101
  seekTo,
1102
+ seekToTime,
1073
1103
  prefetch,
1074
1104
  preload,
1075
1105
  formatTime,
@@ -2215,14 +2245,18 @@ const VoiceMessagePlayer = React.forwardRef((props, ref) => {
2215
2245
  VoicePlaybackChain.playNext(chainId);
2216
2246
  }
2217
2247
  }, [onEnded, chainId]);
2218
- const { play, progress, isLoaded, isPlaying, isLoading, currentTime, waveformLevels, seekTo, prefetch, preload, formatTime, togglePlayback, duration: resolvedDuration, } = useVoiceMessagePlayer({
2248
+ const { play, progress, isLoaded, isPlaying, isLoading, currentTime, waveformLevels, seekTo, seekToTime, prefetch, preload, formatTime, togglePlayback, duration: resolvedDuration, } = useVoiceMessagePlayer({
2219
2249
  src,
2220
2250
  duration,
2221
2251
  waveformData,
2222
2252
  preloadedBlob: props.preloadedBlob,
2223
2253
  onEnded: handleEnded,
2224
2254
  });
2225
- React.useImperativeHandle(ref, () => ({ play, prefetch }), [play, prefetch]);
2255
+ React.useImperativeHandle(ref, () => ({ play, prefetch, seekToTime }), [
2256
+ play,
2257
+ prefetch,
2258
+ seekToTime,
2259
+ ]);
2226
2260
  /** Auto-preload audio when player enters viewport */
2227
2261
  React.useEffect(() => {
2228
2262
  if (!autoPreload || isLoaded || isLoading) {