react-native-video TypeError:未定义不是对象 [英] react-native-video TypeError: undefined is not an object

查看:40
本文介绍了react-native-video TypeError:未定义不是对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我尝试使用 npm 中的 react-native-video 包来播放 youtube 视频:

So I tried using react-native-video package from npm to play a youtube video:

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Video
          source={{uri: 'https://www.youtube.com/watch?v=swigQ10SL_w'}}
          style={{ width: 800, height: 800 }}
          muted={true}
          repeat={true}
          resizeMode={"cover"}
          volume={1.0}
          rate={1.0}
          ignoreSilentSwitch={"obey"}
        />
      </View>
    );
  }
}

出现错误:

推荐答案

通过使用 npm,将 react-native-video 包安装到你的 react-native 项目.

By using npm, install react-native-video package to your react-native project.

npm install --save react-native-video

使用

react-native link

要在 iOS 上链接库,如果它们尚未链接,请执行以下步骤:

To link library on iOS, if they are not linked already do next steps:

  • XCode 项目导航器中,右键单击 Libraries 文件夹并选择 add files to projectname 选项,然后转到 node_modules/react-native-video/ios/ 并选择 RCTVIdeo.xcodeproj

  • In XCode project navigator, right click on Libraries folder and choose add files to projectname option then go to node_modules/react-native-video/ios/ and choose RCTVIdeo.xcodeproj

转到<代码>目标->构建阶段 ->Link Binary With Libraries 点击 + 并选择 libRCTVideo.a

Go to targets -> Build Phases -> Link Binary With Libraries hit + and choose libRCTVideo.a

严格注意:

不要在 react-native-video 中播放 youtube 视频,因为代码没有问题,你可以试试这个.http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4

Don't play youtube video in react-native-video as there is no issue in the code, instead you can try this. http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4

对于 youtube 视频

npm install react-native-youtube-player@latest --save

https://www.npmjs.com/package/react-native-youtube

这篇关于react-native-video TypeError:未定义不是对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆