react-native-video在实例化时崩溃应用程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了react-native-video在实例化时崩溃应用程序相关的知识,希望对你有一定的参考价值。
Current behavior
当我尝试调用视频库(从'react-native-video'导入{Video})时,我的应用程序因Module AppRegistry is not a registered callable module (calling runApplication)
错误而中断
Reproduction steps
我的视频组件如下:
import React, { Component } from 'react';
import { Video } from 'react-native-video';
import {
View,
Dimensions,
TouchableOpacity,
TouchableWithoutFeedback,
Animated,
Text,
Slider,
NetInfo,
StyleSheet
} from 'react-native';
class VideoPlayer extends Component {
state = {
paused: true
};
render() {
const videoWidth = Dimensions.get('window').width;
const videoHeight = videoWidth * (9 / 16);
const styles = StyleSheet.create({
videoContainer: {
width: videoWidth,
height: videoHeight,
backgroundColor: 'rgb(255,255,255)',
paddingTop: 0
}
})
return (
<Video
source={{ uri: 'https://www.youtube.com/embed/3NhHqPA8nIs?rel=0&autoplay=0&showinfo=0&controls=0' }}
paused={this.state.pause}
style={styles.videoContainer}
/>
)
}
}
export default VideoPlayer;
和App.js
import React, {Component} from 'react';
import {StyleSheet, Text, View} from 'react-native';
import Header from './components/Header';
import VideoPlayer from './components/Video';
export default class App extends Component {
render () {
return (
<View style={styles.container}>
<View style={styles.headerContainer}>
<Header />
</View>
<View style={styles.videoContainer}>
<VideoPlayer />
</View>
<Text style={{color: 'white'}}>Hello Wilbur!</Text>
<Text style={{color: 'white'}}>Some text</Text>
<Text style={{color: 'white'}}>some other text</Text>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'rgb(4,4,4)',
alignItems: 'center',
justifyContent: 'center',
},
headerContainer: {
position: 'absolute',
flex: 1,
top: 0,
height: 72,
alignSelf: 'stretch',
paddingTop: 20,
paddingLeft: 12,
paddingRight: 12,
flexDirection: 'row',
backgroundColor: 'white'
},
videoContainer: {
flex: 0,
backgroundColor: 'rgb(4,4,4)',
alignItems: 'center',
justifyContent: 'center',
paddingTop: 0
}
});
如果我没有实例化组件,我可以正常渲染应用程序,甚至可以使用WebView,但是当我尝试导入我的VideoPlayer组件时,我收到上述错误。
Expected behavior
功能视频组件,或至少与视频播放器相关的错误。
Platform
- ios版
Video sample
https://www.youtube.com/embed/3NhHqPA8nIs?rel=0&autoplay=0&showinfo=0&controls=0
有谁看到我做错了什么?谢谢。
答案
react-native-video目前不支持youtube ... https://github.com/react-native-community/react-native-video/issues/1147
以上是关于react-native-video在实例化时崩溃应用程序的主要内容,如果未能解决你的问题,请参考以下文章
在实例化时将对象传递给 Fragment 或 DialogFragment