[英]react-native-video [android] undefined is not an object (evaluating NativeModuels.UIManager.RCTVideo.Constants')
I integrated react native to an existing android app, I am trying to use react-native-video component for displaying video on the application.我将 react native 集成到现有的 android 应用程序中,我正在尝试使用 react-native-video 组件在应用程序上显示视频。
I followed the instructions here: https://github.com/react-native-community/react-native-video我按照这里的说明操作: https : //github.com/react-native-community/react-native-video
On the MainApplication.java I added this:在 MainApplication.java 我添加了这个:
import com.brentvatne.react.ReactVideoPackage;
....
@Override
public List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactVideoPackage()
);
}
I added this to my settings.gradle (only one in app)我将此添加到我的 settings.gradle (应用程序中只有一个)
include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android')
In my android/app/build.gradle在我的 android/app/build.gradle
compile project(':react-native-video')
And on my react native component:在我的本机组件上:
import Video from 'react-native-video';
....
render() {
return (
<View>
<Video source={{uri: 'https://vjs.zencdn.net/v/oceans.mp4'}} resizeMode="cover" repeat={true} />
....
The react native component builds correctly but end up showing this warning on a yellow screen and nothing else:反应原生组件正确构建,但最终在黄色屏幕上显示此警告,没有其他内容:
Possible Unhandled Promise Rejection (id: 0):
undefined is not an object (evaluating '_reactNative.NativeModules.UIManager.RCTVideo.Constants')
render@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:46677:73
http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12555:27
measureLifeCyclePerf@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12015:14
_renderValidatedComponentWithoutOwnerOrContext@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12554:45
_renderValidatedComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12575:78
performInitialMount@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12227:55
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12130:40
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11170:49
mountChildren@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11615:56
initializeChildren@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:9929:41
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:10012:28
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11170:49
performInitialMount@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12235:48
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12130:40
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11170:49
performInitialMount@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12235:48
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12130:40
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11170:49
performInitialMount@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12235:48
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12130:40
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11170:49
mountChildren@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11615:56
initializeChildren@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:9929:41
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:10012:28
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11170:49
performInitialMount@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12235:48
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:12130:40
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11170:49
mountChildren@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11615:56
initializeChildren@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:9929:41
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:10012:28
mountComponent@http://localhost:8081/reactnative/wall.bundle?platform=android&dev=true&hot=false&minify=false:11170:49
performInitialMount@http://localhost:8081/reactnati
Thanks!谢谢!
Fixed adding the ReactVideoPackage when creating the ReactInstanceManager修复了在创建 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();
cd ios and pod install and again link library cd ios 和 pod install 并再次链接库
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,
},
});
Note react-native link react-native-video注意react-native 链接 react-native-video
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.