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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With