首页 > 解决方案 > React Native 播放 iOS 慢动作视频

问题描述

我正在使用 react-native-image-crop-picker (v0.34.1) 从 iPhone 中选择慢动作视频。

选择视频后,我正在使用 react-native-video (v5.0.2) 播放视频。

视频的慢动作效果不会反映在视频的播放中。我找不到有关如何实现这一目标的任何信息。谁能指出我正确的方向?

谢谢

标签: iosreact-nativevideo-playerreact-native-videoslowmotion

解决方案


就像我说的,你必须使用它来达到你想要的效果。

试试看:

const [rate,setRate] = useState(1);
const durationRef = useRef();
const checkCurrentTime = useCallback(({currentTime}) => {
  const percentagePlayed = currentTime/durationRef.current;
  setRate(percentagePlayed < 0.1 || percentagePlayed > 0.9 ? 1 : 0.2)
},[durationRef]);

return (
   <Video
     ...
     rate={rate}
     onLoad(({duration}) => durationRef.current = duration)
     onProgress={checkCurrentTime}
   />
)

推荐阅读