【问题标题】:In react native, how do you set a video component to the background of the page?在 react native 中,如何将视频组件设置为页面背景?
【发布时间】:2017-10-03 15:56:23
【问题描述】:
  render() {
    return (

      <View style={styles.container}>


        <Video
          source={{ uri: 'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4' }}
          rate={1.0}
          volume={1.0}
          muted={false}
          resizeMode="cover"
          repeat
          style={{ width: 300, height: 300 }}
        />


      </View>
    );
  }
}

我只是想让视频成为屏幕的背景。我正在使用 Windows,所以我对如何在没有 Xcode 的情况下做到这一点有点迷茫。有其他方法吗?

【问题讨论】:

    标签: ios video react-native background components


    【解决方案1】:

    如果您使用react-native-video 库,您可以使用position: 'absolute' 设置Video 组件。看这个例子:

    import React, { Component } from 'react';
    
    import { AppRegistry, StyleSheet, Text, View } from 'react-native';
    import Video from 'react-native-video';
    
    export default class App extends Component {
      render() {
        return (
          <View style={styles.container}>
    
            <Video
              source={require('./video.mp4')}
              rate={1.0}
              volume={1.0}
              muted={false}
              resizeMode={"cover"}
              repeat
              style={styles.video}
            />
    
            <View style={styles.content}>
              <Text style={styles.text}>Hello</Text>
            </View>
    
          </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
      },
      video: {
        position: 'absolute',
        top: 0,
        left: 0,
        bottom: 0,
        right: 0,
      },
      content: {
        flex: 1,
        justifyContent: 'center',
      },
      text: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
      },
    });
    
    AppRegistry.registerComponent('App', () => App);
    

    我测试过,效果很好:

    Screenshot

    【讨论】:

    • @rcanovas 我对如何设置库有点迷茫。我做了 npm install 并做了 react-native 链接。但是,它不起作用。我错过了什么吗?
    • 您是否按照库的安装步骤进行操作?您需要进入您的项目目录并运行:npm i -S react-native-videoreact-native link。然后在您的视图中添加顶部 import Video from 'react-native-video'; 就像我的帖子和视频的代码等。
    • 如果要保存缩略图怎么办?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 2016-01-31
    • 2017-10-16
    相关资源
    最近更新 更多