react-native-video 是否与 react-native-navigation 一起工作
Does react-native-video work with react-native-navigation
我正在尝试让视频在我的 React 本机应用程序中播放。 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 并使其正常运行。
所以我的问题是,是否有人遇到过同样的事情,并且可以提供让这两个包协同工作的解决方案?
我的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 模块 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;
}
}
在我的 React Native 项目中:
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>
createAdditionalReactPackages
应该 return 包。
改变这个
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return null;
}
对此:
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return getPackages();
}
我正在尝试让视频在我的 React 本机应用程序中播放。 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 并使其正常运行。
所以我的问题是,是否有人遇到过同样的事情,并且可以提供让这两个包协同工作的解决方案?
我的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 模块 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;
}
}
在我的 React Native 项目中:
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>
createAdditionalReactPackages
应该 return 包。
改变这个
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return null;
}
对此:
@Override
public List<ReactPackage> createAdditionalReactPackages() {
return getPackages();
}