1.安装react-native-video
yarn add react-native-video --save
react-native link react-native-video
2.使用
import Video from 'react-native-video'; <Video source={{uri: "background"}} // Can be a URL or a local file. ref={(ref) => { this.player = ref }} // Store reference onBuffer={this.onBuffer} // Callback when remote video is buffering onEnd={this.onEnd} // Callback when playback finishes onError={this.videoError} // Callback when video cannot be loaded style={styles.backgroundVideo} /> // Later on in your styles.. var styles = StyleSheet.create({ backgroundVideo: { position: 'absolute', top: 0, left: 0, bottom: 0, right: 0, }, });
详细的使用详情请前往:
3.出错
将node_modules >>> react-native-video >>> android >>> build.gradle
dependencies { provided "com.facebook.react:react-native:+" ... }
改为
dependencies { compile "com.facebook.react:react-native:+" ... }