如何将视频海报适合视频播放器高度在Expo React本地视频播放器中

发布于 2025-01-22 16:57:13 字数 926 浏览 4 评论 0原文

我正在使用 https://github.com/github.com/ihmpavel/expo/expo-video-player 此库在React Native应用中添加视频播放器并将海报图像设置为视频播放器。如下所示:

<VideoPlayer
      videoProps={{
        resizeMode: Video.RESIZE_MODE_CONTAIN,
        source: {
          uri: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
        },
        usePoster: true,
        posterSource: {
          uri: props.thumbnail,
        },
        posterStyle: {
          width: FULL_WIDTH - 35,
          height: FULL_WIDTH - 35,
        },
      }}
      style={{
        width: FULL_WIDTH - 35,
        height: FULL_WIDTH - 35,
      }}
      defaultControlsVisible
    />

显示如下:

输出

海报 ?

I'm using https://github.com/ihmpavel/expo-video-player this library to add video player in react native app and setting poster image to video player. as shown below:

<VideoPlayer
      videoProps={{
        resizeMode: Video.RESIZE_MODE_CONTAIN,
        source: {
          uri: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
        },
        usePoster: true,
        posterSource: {
          uri: props.thumbnail,
        },
        posterStyle: {
          width: FULL_WIDTH - 35,
          height: FULL_WIDTH - 35,
        },
      }}
      style={{
        width: FULL_WIDTH - 35,
        height: FULL_WIDTH - 35,
      }}
      defaultControlsVisible
    />

poster is displayed as below:

output

How to fit poster image in video player exactly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

隱形的亼 2025-01-29 16:57:13

只需这样做:

posterStyle={{
  resizeMode: 'cover',
}}

Simply do this:

posterStyle={{
  resizeMode: 'cover',
}}
北城挽邺 2025-01-29 16:57:13

博览会视频不支持recizemode postersource,因此您可以在加载视频时显示覆盖层。

    const [status, setStatus] = React.useState({});

    const imageHeight =  FULL_WIDTH - 35;
    const renderPoster = () => {
        if(status.isLoaded){
            return null;
        }
        return (
            <ImageBackground source={{uri: props.imageUrl}} style={{height:imageHeight, zIndex:99999}} resizeMode="cover"/>
        )
    }

      <Video
                ref={video}
                source={{
                    uri: props.videoUrl,
                }}
                style={{ zIndex: -1, height: imageHeight }}
                resizeMode={"cover"}
                shouldPlay={true}
                isLooping
                useNativeControls
                onPlaybackStatusUpdate={status => setStatus(() => status)}
            >
       {renderPoster()}

   </Video>

Expo video doesn't support resizeMode for posterSource so you can show an overlay while video is being loaded.

    const [status, setStatus] = React.useState({});

    const imageHeight =  FULL_WIDTH - 35;
    const renderPoster = () => {
        if(status.isLoaded){
            return null;
        }
        return (
            <ImageBackground source={{uri: props.imageUrl}} style={{height:imageHeight, zIndex:99999}} resizeMode="cover"/>
        )
    }

      <Video
                ref={video}
                source={{
                    uri: props.videoUrl,
                }}
                style={{ zIndex: -1, height: imageHeight }}
                resizeMode={"cover"}
                shouldPlay={true}
                isLooping
                useNativeControls
                onPlaybackStatusUpdate={status => setStatus(() => status)}
            >
       {renderPoster()}

   </Video>

屋檐 2025-01-29 16:57:13
<Video
              source={{ uri: '' }}
              resizeMode={ResizeMode.CONTAIN}
              style={styles.video}
              isLooping={true}
              shouldPlay={true}
              isMuted={true}
              usePoster={true}
              PosterComponent={() => {
                return (
                  <ImageBackground
                    style={styles.loadingImage}
                    source={require('loadingImage.png')}
                    resizeMode={ResizeMode.CONTAIN}
                  />
                );
              }}>
            </Video>
<Video
              source={{ uri: '' }}
              resizeMode={ResizeMode.CONTAIN}
              style={styles.video}
              isLooping={true}
              shouldPlay={true}
              isMuted={true}
              usePoster={true}
              PosterComponent={() => {
                return (
                  <ImageBackground
                    style={styles.loadingImage}
                    source={require('loadingImage.png')}
                    resizeMode={ResizeMode.CONTAIN}
                  />
                );
              }}>
            </Video>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文