详情如下:- 我使用命令行生成了我的 React Native Expo 项目
npx expo-cli init youtube
然后我参考了这个链接:- 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
此后,在我的命令中运行:-
npm start
扫描二维码并在手机上的 EXPO 应用程序中打开该应用程序
以下是我收到的错误截图
点击这里查看大图:
点击这里查看大图:
点击这里查看大图:
下图是项目在android平台或手机上运行的截图:
点击这里查看大图:
模块“react-native-youtube”不支持 youtube 链接。而不是那样使用
<WebView
style={ styles.styleCode }
javaScriptEnabled={true}
domStorageEnabled={true}
source={{uri: 'https://www.youtube.com/embed/dFKhWe2bBkM' }}
/>
从(分享>嵌入)中找到youtube uri。
尝试降级至
react-native-video: ^5.2.1
。
为我工作,我正在
react-native: 0.74.3