react-native-video TypeError:未定义不是对象 [英] react-native-video TypeError: undefined is not an object
问题描述
所以我尝试使用 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 onLibraries
folder and chooseadd files to projectname
option then go tonode_modules/react-native-video/ios/
and chooseRCTVIdeo.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屋!