简体   繁体   English

react-native-video [android] undefined 不是一个对象(评估 NativeModuels.UIManager.RCTVideo.Constants')

[英]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 组件在应用程序上显示视频。

  • React-native: 0.42.0反应原生:0.42.0
  • react-native-video: 1.0.0反应原生视频:1.0.0

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.

相关问题 未定义不是对象(评估&#39;_reactNative.Nativemodules.UIManager.RCTVideo.Constants&#39;) - Undefined is not an object (evaluating '_reactNative.Nativemodules.UIManager.RCTVideo.Constants') "react-native-video 未定义不是一个对象(评估&#39;_reactNative ...)" - react-native-video Undefined is not an object (evaluating '_reactNative ...) Android上的react-native-video崩溃 - react-native-video crashes on Android background React-Native-Video 在 Android 中禁用 TouchableOpacity - React-Native-Video disables TouchableOpacity in Android react-native-video 示例抛出“TypeError:undefined”错误 - react-native-video example throws “TypeError:undefined” error React-Native-Video 控件在 iOS 中工作但在 android 中不工作? (滞后 state?) - React-Native-Video controls working in iOS but not android? (Laggy state?) 如何修复“TypeError: undefined is not an object (evaluating &#39;_reactNativeCamera.default.constants&#39;)” 在本机反应中的错误? - How to fix "TypeError: undefined is not an object (evaluating '_reactNativeCamera.default.constants')" error in react native? Android undefined不是评估自定义模块的对象-React Native - Android undefined is not an object evaluating custom module - React Native React Native,Android,未定义不是对象(评估&#39;this.props.navigator.push&#39;) - React Native, Android, undefined is not an object (evaluating 'this.props.navigator.push') 视频不播放(卡住)在 react-native-video 中 - Video not playing (stuck) in react-native-video
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM