反应式插入YouTube视频



我正在尝试将YouTube视频插入我的反应本地项目。我添加了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);

我正在收到此错误:元素类型无效:预期的字符串(用于构建组件)或类/函数(对于复合组件),但got:不确定。检查"视频"的渲染方法。

当您要在渲染方法中返回的组件出现问题时,它会引发错误。在这种情况下,我认为这是您的视频组件,据我所知,我不相信RN提供的视频组件。如果您将其从另一个库中拉入,请确保从那里导入它,而不是RN。

例如:

import Video from 'react-native-video';

最新更新