错误 react-native-video:未定义不是对象(评估“RCTVideoInstance.Constants”)

Posted

技术标签:

【中文标题】错误 react-native-video:未定义不是对象(评估“RCTVideoInstance.Constants”)【英文标题】:Error react-native-video : undefined is not an object (evaluating 'RCTVideoInstance.Constants') 【发布时间】:2020-05-05 13:06:43 【问题描述】:

我想在我的应用中使用 react-native-video。但是,我所做的不起作用:

    我使用expo init Project1创建了一个新项目

    然后我安装了 react-native-video :npm install --save react-native-video

    我当时用这个:react-native link react-native-video

我目前只有 App.js :

import React from 'react';
import  StyleSheet, Text, View  from 'react-native';
import Video from 'react-native-video';

export default function App() 
  return (
    <View style=styles.container>
      <Video source=uri: './small.mp4'   // Can be a URL or a local file.
       ref=(ref) => 
         this.player = ref
                                             // Store reference
       o.nBuffer=this.onBuffer                // Callback when remote video is buffering
       onError=this.videoError               // Callback when video cannot be loaded
       style=styles.backgroundVideo />

    </View>
  );

最后我用npm start

我有这个错误信息:

undefined is not an object (evaluating 'RCTVideoInstance.Constants')

Stack trace:
  node_modules/react-native-video/Video.js:265:11 in render
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:13042:21 in finishClassComponent
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:12970:4 in updateClassComponent
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:307:15 in invokeGuardedCallbackImpl
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:531:36 in invokeGuardedCallback
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:20488:8 in beginWork$$1
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:19370:24 in performUnitOfWork
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:19347:39 in workLoopSync
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:18997:22 in renderRoot
  [native code]:null in renderRoot
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:18709:28 in runRootCallback
  [native code]:null in runRootCallback
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:5642:32 in runWithPriority$argument_1
  node_modules/scheduler/cjs/scheduler.development.js:643:23 in unstable_runWithPriority
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:5638:22 in flushSyncCallbackQueueImpl
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:5627:28 in flushSyncCallbackQueue
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:18556:30 in scheduleUpdateOnFiber
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:21822:15 in scheduleRootUpdate
  node_modules/react-native/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js:23042:20 in ReactNativeRenderer.render
  node_modules/react-native/Libraries/ReactNative/renderApplication.js:52:52 in renderApplication
  node_modules/react-native/Libraries/ReactNative/AppRegistry.js:116:10 in runnables.appKey.run
  node_modules/react-native/Libraries/ReactNative/AppRegistry.js:197:26 in runApplication
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:436:47 in __callFunction
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:26 in __guard$argument_0
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:110:17 in __guard$argument_0
  [native code]:null in callFunctionReturnFlushedQueue
  ...

我按照 react-native-video 的说明进行操作:https://www.npmjs.com/package/react-native-video

非常感谢...

【问题讨论】:

【参考方案1】:

如果您想使用“react-native-video”,您必须从 expo 中退出您的应用并使用裸工作流。

顺便说一句,您可以使用 Expo Video 代替 react-native-video :https://docs.expo.io/versions/latest/sdk/video/

【讨论】:

以上是关于错误 react-native-video:未定义不是对象(评估“RCTVideoInstance.Constants”)的主要内容,如果未能解决你的问题,请参考以下文章

当我链接 react-native-video 时显示错误

无法读取未定义的属性“寻求”

如何为 react-native-video 构建自定义搜索栏

['react-native-video'中包含{Video}后出现此错误。否则我的代码可以正常工作

react-native-video:无法读取 null 的属性“常量”

react-native-video在实例化时崩溃应用程序