1

我正在尝试让视频在我的本机应用程序中播放。我正在尝试使用 react-native-video但是在通过运行应用程序时react-native run-android收到错误消息:

“未定义不是对象(评估'_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;
    }

}

在我的反应原生项目中:

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>
4

1 回答 1

1

createAdditionalReactPackages应该退回包裹。

改变这个

@Override
public List<ReactPackage> createAdditionalReactPackages() {
    return null;
}

对此:

@Override
public List<ReactPackage> createAdditionalReactPackages() {
    return getPackages();
}
于 2017-07-18T03:20:23.197 回答