首页 > 解决方案 > 使用视频的第一帧作为缩略图

问题描述

我正在使用react-native-video

它有一个名为的道具poster,它工作正常。但我的要求是从视频(视频的第一帧)中获取该缩略图。如果我不使用poster(接受 url),那么它会显示空白屏幕。

知道如何将视频的第一帧用作缩略图吗?

谢谢你!!!

标签: react-nativereact-native-androidreact-native-iosreact-native-video

解决方案


您可以使用onLoad函数回调来实现它,

const player = useRef(null);
<Video
  source={{uri: uri}}
  ref={player}
  paused={true}
  style={styles.backgroundVideo}
  onLoad={() => {
    player.current.seek(0); // this will set first frame of video as thumbnail
  }}
/>

有关onLoad道具的更多详细信息:这里


推荐阅读