我试图在我的本机应用中播放视频。 I'm trying to use react-native-video但是当通过react-native run-android
运行应用时,我收到错误消息:
" undefined不是对象(评估' _reactNative.NativeModules.UIManager.RCT Video.Constants')
这条消息并没有真正告诉我多少,但在尝试让它工作一段时间之后我开始怀疑react-native-navigation,这是我用于我的应用程序的导航,有一些东西与它有关。因此,我创建了一个新的react-native项目,并为其添加了react-native-video,并使其工作没有太多麻烦。
所以我的问题是,是否有人经历过相同的事情,并且可以提供解决方案来让这两个包一起工作?
我的设置。格式:
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模块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'
}
build.grade模块: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;
}
}
在我的反应原生项目中:
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>
答案 0 :(得分:1)
createAdditionalReactPackages
应该返回包裹。
更改此
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return null;
}
到此:
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return getPackages();
}