react native video[android]undefined不是对象(评估NativeModuels.UIManager.RCTVideo.Constants';)
我将react native集成到现有的android应用程序中,我尝试使用react native视频组件在应用程序上显示视频react native video[android]undefined不是对象(评估NativeModuels.UIManager.RCTVideo.Constants';),android,react-native,Android,React Native,我将react native集成到现有的android应用程序中,我尝试使用react native视频组件在应用程序上显示视频 反应本机:0.42.0 react本地视频:1.0.0 我按照这里的指示: 在MainApplication.java上,我添加了以下内容: import com.brentvatne.react.ReactVideoPackage; .... @Override public List<ReactPackage> getPackages()
- 反应本机:0.42.0
- react本地视频:1.0.0
import com.brentvatne.react.ReactVideoPackage;
....
@Override
public List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactVideoPackage()
);
}
在我的android/app/build.gradle中
compile project(':react-native-video')
在我的react native组件上:
import Video from 'react-native-video';
....
render() {
return (
<View>
<Video source={{uri: 'https://vjs.zencdn.net/v/oceans.mp4'}} resizeMode="cover" repeat={true} />
....
谢谢 修复了在创建ReactInstanceManager时添加ReactVideoPackage的问题
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new ReactVideoPackage())//<-- this line fixed
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactInstanceManager=ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName(“index.android.bundle”)
.setJSMainModuleName(“index.android”)
.addPackage(新的MainReactPackage())
.addPackage(新的ReactVideoPackage())/
cd ios和pod安装
并再次链接库
import React, {Component} from 'react';
import {
View,
Button,
Text,
Platform,
StyleSheet,
TouchableOpacity,
TouchableHighlight,
Animated,
ScrollView,
Image,
} from 'react-native';
import Video from 'react-native-video';
export default class App extends Component {
render() {
return (
<View style={{flex: 1, marginTop: 50}}>
<Video
source={{uri: 'YOUR_URL'}} // Can be a URL or a local file.
ref={ref => {
this.player = ref;
}} // Store reference
onBuffer={this.onBuffer} // Callback when remote video is buffering
onError={this.videoError} // Callback when video cannot be loaded
style={styles.backgroundVideo}
/>
</View>
);
}
}
const styles = StyleSheet.create({
field: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
paddingTop: 10,
paddingBottom:10,
},
backgroundVideo: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
},
});
import React,{Component}来自'React';
进口{
看法
按钮
文本,
平台,
样式表,
可触摸不透明度,
触控高光,
有生气的
滚动视图,
形象,,
}从“反应本机”;
从“react native Video”导入视频;
导出默认类应用程序扩展组件{
render(){
返回(
{
this.player=ref;
}}//存储引用
onBuffer={this.onBuffer}//远程视频缓冲时的回调
OneError={this.videoError}//无法加载视频时回调
style={style.backgroundVideo}
/>
);
}
}
const styles=StyleSheet.create({
字段:{
弹性:1,
flexDirection:'行',
justifyContent:'之间的空间',
paddingTop:10,
填充底部:10,
},
背景视频:{
位置:'绝对',
排名:0,
左:0,,
底部:0,
右:0,,
},
});
注意反应本机链接反应本机视频
或者,运行react native link react native video
可以为您在Android和iOS上自动对链接库进行所有必要的更改。什么是ReactVideoPackage()??是实例化导入的com.brentvatne.react.ReactVideoPackage类的构造函数。您可以在此处找到更多信息:[链接]()
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new ReactVideoPackage())//<-- this line fixed
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
import React, {Component} from 'react';
import {
View,
Button,
Text,
Platform,
StyleSheet,
TouchableOpacity,
TouchableHighlight,
Animated,
ScrollView,
Image,
} from 'react-native';
import Video from 'react-native-video';
export default class App extends Component {
render() {
return (
<View style={{flex: 1, marginTop: 50}}>
<Video
source={{uri: 'YOUR_URL'}} // Can be a URL or a local file.
ref={ref => {
this.player = ref;
}} // Store reference
onBuffer={this.onBuffer} // Callback when remote video is buffering
onError={this.videoError} // Callback when video cannot be loaded
style={styles.backgroundVideo}
/>
</View>
);
}
}
const styles = StyleSheet.create({
field: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
paddingTop: 10,
paddingBottom:10,
},
backgroundVideo: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
},
});