【问题标题】:How to resize video without changing it's aspect ratio?如何在不改变宽高比的情况下调整视频大小?
【发布时间】:2019-01-30 05:54:55
【问题描述】:
  constructor(props) {
    super(props);
    this.state = {
        screenWidth: Dimensions.get('window').width,
        heightScaled: null,
    };  
  }   

<View style={styles.videoView}>
       <Video 
          source={video}
          ref={(ref) => { this.player = ref }}  
          repeat={true}
          resizeMode={"contain"}
          style={{
              width: this.state.screenWidth,
              height: this.state.heightScaled,
           }}
          onLoad={response => {
                const { width, height } = response.naturalSize;
                const heightScaled = height * (this.state.screenWidth / width);

                response.naturalSize.orientation = "horizontal";
                this.setState({ heightScaled: heightScaled });
          }}
       />
</View>

样式

videoView: {
  flex: 1,
  width: Dimensions.get('window').width,
  height: 350
}

我正在从 api 获取视频,然后使用 react-native-video 在视频组件中使用它。我不知道如何在不拉伸视频的情况下调整视频大小以适应视图。

这是上面代码的结果。

我不希望我的视频越过我在图片中标记的红线。 请帮我。过去 3 天我一直被这个问题困扰。

【问题讨论】:

标签: android reactjs react-native react-native-video


【解决方案1】:

在包含&lt;Video /&gt;的父&lt;View /&gt;中再添加一个&lt;View /&gt;将解决视频溢出问题。

<View style={styles.videoView}>
  <Video
    resizeMode={"contain"}
    style={{
      flex: 1
    }}
  />
  <View style={{flex: 1}}>
     {/* Components after red line can be rendered here */}
  </View>
</View>

【讨论】:

    猜你喜欢
    • 2017-09-05
    • 2014-09-04
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    相关资源
    最近更新 更多