react-native - 视频预览(来自 react-native-video)未显示
问题描述
我按照文档进行了操作,但我无法弄清楚为什么视频没有播放。
console.log mp4 文件:这就是我在记录itemToPreview 时从相机中检索 mp4 文件的方式: file:///data/user/0/com.sentinel/cache/Camera/550b75a0-e1bd-4d0d-90ee-e8012a087e35.mp4 ,
然后我将它传递给视频源: source={{uri: 'itemToPreview'}}
请帮助我做错了什么?
onLoad = (data) => {
//set duration
this.setState({duration: data.duration});
}
onProgress = (data)=> {
//set current time
this.setState({currentTime: data.currentTime});
}
onEnd = ()=>{
//set pausedText and paused, set video current time to 0
this.setState({pausedText: 'Play', paused: true});
this.video.seek(0);
}
render()
{
const { itemToPreview } = this.props.route.params;
console.log("itemToPreview :"+ itemToPreview);
return(
<View style={styles.container}>
<TouchableOpacity
style={styles.fullScreen}
onPress={()=> this.setState({paused: !this.state.paused})}
>
<Video source={{uri: 'itemToPreview'}}
ref={(ref)=> {this.video = ref }}
style ={styles.fullScreen}
repeat={this.state.repeat}
rate={this.state.rate}
volume ={this.state.volume}
muted = {this.state.muted}
resizeMode={this.state.resizeMode}
paused = {this.state.paused}
onLoad ={this.onLoad}
onProgress = {this.onProgress}
onEnd = {this.onEnd}
/>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'black'
},
text: {
fontFamily: 'roboto',
fontSize: 16,
fontWeight: 'bold',
},
fullScreen: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
}
解决方案
itemToPreview 是从参数中提取的变量,您将其用作字符串
尝试这个:
source={{uri: itemToPreview}}
推荐阅读
- stm32 - 刷新 uC 时更新 STM32F4 上的 RTC
- vba - 浏览 excel 文件,然后将数据从浏览的文件复制到活动文件
- javascript - 当值突出显示时,允许用户在仅数字字段中输入小数点作为第一个字符 JavaScript
- ruby-on-rails - device_token_auth 令牌生成问题
- selenium - 如何为 span 标签使用“not(contains())”谓词编写 Xpath
- javascript - 带有重复参数的Angularjs $location.search
- go - Golang中是否有等效的番石榴表?如果不是,那么在 Go 中正确的做法是什么
- angularjs - 看起来您正试图在本机驱动程序端口上通过 HTTP 访问 MongoDB
- stm32 - I2C 与 stm32f4 使用 HMC5883l
- python - python如何在循环中填充列表