I'm trying to get videos to play in my react native app. I'm trying to use react-native-video but when running the app via react-native run-android I get the error message:
"undefined is not an object (evaluating'_reactNative.NativeModules.UIManager.RCT Video.Constants')
This message doesn't really tell me much, but after trying to get this to work for a while I started to suspect that react-native-navigation, , which is the navigation I use for my app, has something to do with it. So I created a new react-native project and added react-native-video to it and got it working without too much trouble.
So my question is if anyone has experienced the same thing, and could provide a solution to getting these two packages working together?
My settings.gradle:
rootProject.name = 'newproj'
include ':react-native-video'
project(':react-native-video').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-video/android')
include ':app'
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-navigation/android/app/')
build.gradle Module react-native-video
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '25.0.1'
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
}
dependencies {
provided 'com.facebook.react:react-native:+'
compile 'com.yqritc:android-scalablevideoview:1.0.1'
}
dependencies in build.grade Module: app
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile project(':react-native-navigation')
compile project(':react-native-video')
}
MainApplication.java
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.brentvatne.react.ReactVideoPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.reactnativenavigation.NavigationApplication;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends NavigationApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactVideoPackage()
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
@Override
public boolean isDebug() {
// Make sure you are using BuildConfig from your own application
return BuildConfig.DEBUG;
}
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return null;
}
}
And in my react native project:
import Video from 'react-native-video';
<View style={styles.container}>
<Video source={{uri: "youtube.com"}}
ref={(ref) => {
this.player = ref
}}
resizeMode="cover"
style={styles.backgroundVideo}
/>
</View>
react-navigationandreact-native-video, theundefined is not an objectusually occurs when you forgot to declare the param. So it would be helpful if you post the complete code of that particular screen(js code not the java code) - Jeffrey Rajan