开发者问题收集

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

2020-05-05
8229

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

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

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

  3. 然后我使用了这个: 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

非常感谢...

2个回答

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

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

monsty
2020-05-05

你可以像这样将 jcenter 添加到 android/build.gradle:

 allprojects {
  repositories {
    .... # Keep the rest
    jcenter() {
        content {
            includeModule("com.yqritc", "android-scalablevideoview")
        }
    }
   }
 }

这对我有用,希望它也能对你有用

AbdulmateenChitrali
2022-07-26