我正在尝试将youtube视频插入我的react-native项目。我添加了 - react-native-video库,然后是这段代码:
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Video
} from 'react-native';
export default class video extends Component {
render() {
return (
<Video source={{uri: "Gladiator trailer.mp4"}}
ref={(ref) => {
this.player = ref
}} // Store reference
rate={1.0} // 0 is paused, 1 is normal.
volume={1.0} // 0 is muted, 1 is normal.
muted={false} // Mutes the audio entirely.
paused={false} // Pauses playback entirely.
resizeMode="cover" // Fill the whole screen at aspect ratio.
repeat={true} // Repeat forever.
playInBackground={false} // Audio continues to play when app entering background.
playWhenInactive={false} // [iOS] Video continues to play when control or notification center are shown.
progressUpdateInterval={250.0} // [iOS] Interval to fire onProgress (default to ~250ms)
onLoadStart={this.loadStart} // Callback when video starts to load
onLoad={this.setDuration} // Callback when video loads
onProgress={this.setTime} // Callback every ~250ms with currentTime
onEnd={this.onEnd} // Callback when playback finishes
onError={this.videoError} // Callback when video cannot be loaded
style={styles.backgroundVideo} />
);
}
}
const styles = StyleSheet.create({
backgroundVideo: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
}
});
AppRegistry.registerComponent('video', () => video);
我收到此错误:元素类型无效:期望一个字符串(用于内置组件)或一个类/函数(用于复合组件)但得到:undefined。检查'video'的渲染方法。
答案 0 :(得分:0)
如果您在渲染方法中返回的组件出现问题,则会抛出该错误。在这种情况下,我认为它是您的视频组件,据我所知,我不相信RN提供的视频组件。如果您从另一个库中提取它,请确保从那里导入它而不是RN。
例如:
import Video from 'react-native-video';