我如何访问react

编程入门 行业动态 更新时间:2024-10-07 22:20:56
本文介绍了我如何访问react-native-camera的视频功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在尝试使react-native-camera的视频功能正常工作,但是尝试了很多方法,但始终遇到相同的错误.这是我的代码:

I've been attempting to get the react-native-camera's video feature to work, but and have tried a vast number of methods but keep getting the same errors. Here is my code:

class MainCamera extends Component { constructor() { super(); this.render = this.render.bind(this) this.state = { cameraType: Camera.constants.Type.back } } render() { return ( <View style={styles.container}> <Camera ref='camera' style={styles.preview} aspect={Camera.constants.Aspect.fill} type={this.state.cameraType} captureMode={Camera.constants.CaptureMode.video} captureAudio={false} target={Camera.constants.CaptureTarget.disk}> <TouchableHighlight onPressIn={this.onPressIn.bind(this)} onPressOut={this.stopVideo.bind(this)}> <Icon name="video-camera" size={40} /> </TouchableHighlight> </Camera> </View> ); } onPressIn() { recordVideo = setTimeout(this.takeVideo.bind(this), 100); } takeVideo() { this.refs.camera.capture({ target: Camera.constants.CaptureTarget.disk }) .then(data => { console.log(data); }) .catch(err => console.log(err)); } stopVideo() { this.refs.camera.stopCapture({}) .then(data => console.log(data)) .catch(err => console.log(err)); } }

当我在stopCapture()方法上使用'.then'承诺时,收到错误消息无法读取未定义的'then'属性",但是如果我不添加'.then',则什么也不会发生而且我没有收到任何数据有人有什么建议吗?

When I use the '.then' promise on the stopCapture() method, I receive the error "Cannot read property 'then' of undefined", but if I don't add the '.then', then nothing happens and I don't receive any data. Does anybody have any suggestions?

推荐答案

takeVideo() { this.refs.camera.capture({ audio: true, mode: Camera.constants.CaptureMode.video, target: Camera.constants.CaptureTarget.disk }) .then((data) => { console.log(data); }) .catch((err) => console.log(err)); } stopVideo() { this.refs.camera.stopCapture(); }

stopCapture()功能不是一个承诺.

更多推荐

我如何访问react

本文发布于:2023-11-27 21:30:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639674.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:react

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!