简体   繁体   English

Expo / React Native:视频无法调整大小

[英]Expo / React Native: Video Failing to Resize

I'm using Expo with React Native, testing on the Android simulator on a Galaxy S8+.我正在将 Expo 与 React Native 结合使用,在 Galaxy S8+ 上的 Android 模拟器上进行测试。

I'm using the Video component from the Expo library, as I couldn't get react-native-video to work.我正在使用 Expo 库中的Video组件,因为我无法让react-native-video工作。

I'm using the following code: <Video style={styles.video} source={{ uri: url }} isMuted={false} shouldPlay isLooping usePoster={true} useNativeControls={false} resizeMode="contain" />我正在使用以下代码: <Video style={styles.video} source={{ uri: url }} isMuted={false} shouldPlay isLooping usePoster={true} useNativeControls={false} resizeMode="contain" />

styles.video is simply {width: window.width, height: 650} styles.video只是{width: window.width, height: 650}

Which displays the following: Screenshot of issue显示以下内容:问题的屏幕截图

But, if you load the video in, it actually fits the whole window and is sized the way I want, but only for half a second.但是,如果您加载视频,它实际上适合整个窗口并按我想要的方式调整大小,但只有半秒钟。 After that it immediately goes small like in the screenshot.之后它立即变小,就像屏幕截图一样。 I've tried cover and center as well, and it hasn't worked.我也试过covercenter ,但没有奏效。 Any help would be appreciated.任何帮助,将不胜感激。

Edit: More Details:编辑:更多细节:

What I want it to look like is something like this, which I have working for images: Image of what it should look like我希望它看起来像这样,我为图像工作:它应该是什么样子的图像

With images, I'm using the default Image component from React Native in the following way: <Image style={styles.image} source={{ uri: data.url }} resizeMode="contain" />对于图像,我通过以下方式使用 React Native 的默认Image组件: <Image style={styles.image} source={{ uri: data.url }} resizeMode="contain" />

And styles.images is identical to styles.video at the moment.styles.images是相同的styles.video的时刻。

resizeMode="contain" for the video视频的resizeMode="contain"

And flex:1 for the styleflex:1样式

According to your Screen, your front-end could be designed like this.根据您的屏幕,您的前端可以设计成这样。

return(
   <View style={{ width: "100%",height: "100%", flex: 1}}>
      <View style={{flex:0.7,justifyContent:'center'}}>
          <Video
           source={{ uri: url }}
           isMuted={false} 
           shouldPlay
           isLooping
           usePoster={true} 
           useNativeControls={false}
           />
       </View>
      <View style={{flex:0.1}}/>
      <TouchableOpacity style={{flex:0.1,paddingHorizontal:10}}>
           <View style={{width:"100%",justifyContent:"center",alignItems:"center",backgroundColor:"blue"}}>
            <Text>Next</Text>
           </View>
      </TouchableOpacity>
   </View>
 )

Do not forget to import TouchableOpacity !不要忘记导入 TouchableOpacity !

Hope I could help you.希望我能帮到你。 Do comment if need more assistance.如果需要更多帮助,请发表评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM