始终违规:requireNativeComponent:在UIManager中找不到“ RCTYouTube”

时间:2020-09-30 14:20:24

标签: react-native youtube youtube-api

这是详细信息:- 我使用命令行npx expo-cli init youtube生成了我的react native expo项目。 然后我引用了此链接:-https://www.npmjs.com/package/react-native-youtube

我使用以下命令安装了react-native-youtube依赖项:-npm i react-native-youtube 我还从https://developers.google.com/youtube/android/player/register

获得了我的官方youtube API。

在App.js文件中,以下是编写的代码

`import React from 'react'
import {View,StyleSheet,Text,SafeAreaView} from 'react-native'
import YouTube from 'react-native-youtube';


 

const App=()=>{
    
  
  const linkTest="https://www.youtube.com/watch?v=aqz-KE-bpKQ"

    return (
      
      
      <SafeAreaView style={styles.container}>
  
      <YouTube
      apiKey="*******************"
      videoId={linkTest} // The YouTube video ID
      play // control playback of video with true/false
      fullscreen // control whether the video should play in fullscreen or inline
      loop // control whether the video should loop when ended
      onReady={e => this.setState({ isReady: true })}
      onChangeState={e => this.setState({ status: e.state })}
      onChangeQuality={e => this.setState({ quality: e.quality })}
      onError={e => this.setState({ error: e.error })}
      style={{ alignSelf: 'stretch', height: 300 }}
    />  
      
     
        </SafeAreaView>
        
        
         )
}


const styles= StyleSheet.create({
    container:{ backgroundColor:"white", flex:1},
    
    

})
export default App

此后,我在cmd中跑了:-npm start 扫描QRCode并在手机上的EXPO App中打开该应用程序 以下是我收到的错误的屏幕截图

点击here以显示大图:

enter image description here

点击here以显示大图:

enter image description here

点击here以显示大图:

enter image description here

下图是在android平台或移动设备上的expo上运行的项目的屏幕截图:

点击here以显示大图:

enter image description here

1 个答案:

答案 0 :(得分:1)

模块“react-native-youtube”不支持 YouTube 链接。而不是那个使用

<WebView
      style={ styles.styleCode }
      javaScriptEnabled={true}
      domStorageEnabled={true}
      source={{uri: 'https://www.youtube.com/embed/dFKhWe2bBkM' }}
/>

从 ( share > embed ) 中查找 youtube uri。