Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In react native, how do you set a video component to the background of the page?

  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>
    );
  }
}

I simply want to make the video the background of the screen. I'm using a windows, so I'm a little lost on how to do that without Xcode. Is there an alternative way?

like image 592
Arron J. Linton Avatar asked May 05 '17 08:05

Arron J. Linton


People also ask

How do you put a video in the background of React?

To add a background video with React, we can add the video element with the autoPlay prop. We add the video element with the loop prop to make the video replay after it's finished. And the autoPlay prop makes the video start automatically when we load the page.

How do I show video on screen in React Native?

Using react-native-video First, we import the video component from the library into the component where we want the video to be displayed. Of course, for the video component to display anything, we need a video file. This can either be a file in your project or a link to an external resource.

How do I set a full background in React Native?

Approach: In this article, we will see that how to set background Image in react-native. In our project, we will simply set a background image and show a text input on top of it. Step 2: Create a components folder inside your project. Inside the components, folder create a file BackgroundImage.


1 Answers

In case you are using react-native-video library you can set the Video component with position: 'absolute'. See this example:

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);

I tested it and works well:

Screenshot

like image 131
rcanovas Avatar answered Sep 17 '22 20:09

rcanovas