@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.
package/dist/index.js CHANGED
@@ -1043,15 +1043,44 @@ const useVoiceMessagePlayer = (options) => {
1043
1043
  setIsPlaying(false);
1044
1044
  }
1045
1045
  }, [isLoading, stopThis, audioRef]);
1046
- const seekTo = useCallback((seekProgress) => {
1046
+ const seekTo = useCallback((seekPercent) => {
1047
1047
  const audio = audioRef.current;
1048
1048
  if (!audio || !isFinite(audio.duration)) {
1049
1049
  return;
1050
1050
  }
1051
- const time = seekProgress * audio.duration;
1051
+ const time = seekPercent * audio.duration;
1052
1052
  audio.currentTime = time;
1053
1053
  setCurrentTime(time);
1054
1054
  }, [audioRef]);
1055
+ /** Seek to a specific time in seconds and start playback */
1056
+ const seekToTime = useCallback((seconds) => {
1057
+ const audio = audioRef.current;
1058
+ if (audio && isFinite(audio.duration)) {
1059
+ audioPlaybackManager.stopOthers(stopThis);
1060
+ audio.currentTime = Math.max(0, Math.min(seconds, audio.duration));
1061
+ setCurrentTime(audio.currentTime);
1062
+ audio.play()
1063
+ .then(() => setIsPlaying(true))
1064
+ .catch(() => setIsPlaying(false));
1065
+ }
1066
+ else {
1067
+ void ensureAudioLoaded().then(() => {
1068
+ const loadedAudio = audioRef.current;
1069
+ if (loadedAudio) {
1070
+ audioPlaybackManager.stopOthers(stopThis);
1071
+ loadedAudio.currentTime = Math.max(0, Math.min(seconds, loadedAudio.duration || seconds));
1072
+ setCurrentTime(loadedAudio.currentTime);
1073
+ loadedAudio.play()
1074
+ .then(() => setIsPlaying(true))
1075
+ .catch(() => setIsPlaying(false));
1076
+ }
1077
+ });
1078
+ }
1079
+ }, [
1080
+ audioRef,
1081
+ stopThis,
1082
+ ensureAudioLoaded,
1083
+ ]);
1055
1084
  /** Sync external duration */
1056
1085
  useEffect(() => {
1057
1086
  if (externalDuration) {
@@ -1068,6 +1097,7 @@ const useVoiceMessagePlayer = (options) => {
1068
1097
  currentTime,
1069
1098
  waveformLevels,
1070
1099
  seekTo,
1100
+ seekToTime,
1071
1101
  prefetch,
1072
1102
  preload,
1073
1103
  formatTime,
@@ -2213,14 +2243,18 @@ const VoiceMessagePlayer = React.forwardRef((props, ref) => {
2213
2243
  VoicePlaybackChain.playNext(chainId);
2214
2244
  }
2215
2245
  }, [onEnded, chainId]);
2216
- const { play, progress, isLoaded, isPlaying, isLoading, currentTime, waveformLevels, seekTo, prefetch, preload, formatTime, togglePlayback, duration: resolvedDuration, } = useVoiceMessagePlayer({
2246
+ const { play, progress, isLoaded, isPlaying, isLoading, currentTime, waveformLevels, seekTo, seekToTime, prefetch, preload, formatTime, togglePlayback, duration: resolvedDuration, } = useVoiceMessagePlayer({
2217
2247
  src,
2218
2248
  duration,
2219
2249
  waveformData,
2220
2250
  preloadedBlob: props.preloadedBlob,
2221
2251
  onEnded: handleEnded,
2222
2252
  });
2223
- useImperativeHandle(ref, () => ({ play, prefetch }), [play, prefetch]);
2253
+ useImperativeHandle(ref, () => ({ play, prefetch, seekToTime }), [
2254
+ play,
2255
+ prefetch,
2256
+ seekToTime,
2257
+ ]);
2224
2258
  /** Auto-preload audio when player enters viewport */
2225
2259
  useEffect(() => {
2226
2260
  if (!autoPreload || isLoaded || isLoading) {