首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用react-native-camera模块进行视频采集?

如何使用react-native-camera模块进行视频采集?
EN

Stack Overflow用户
提问于 2018-02-06 15:25:23
回答 1查看 666关注 0票数 0

我可以用这个模块捕获图片,没有任何问题,但是当我尝试录制视频时,我似乎找不到录制的视频在哪里(或者甚至根本没有录制过视频)。这是我的CameraScreen

代码语言:javascript
复制
import Camera from 'react-native-camera';

const { CaptureMode, CaptureTarget } = Camera.constants;
const { video: captureModeVideo, still: captureModePhoto } = CaptureMode;

class CameraScreen extends Component {
    constructor(props) {
        super(props);
        this.state = {
            captureMode: captureModePhoto,
            isRecording: false
        };

        this.onCapture = this.onCapture.bind(this);
        this.onSwitchCaptureMode = this.onSwitchCameraMode.bind(this);
    }

    onCapture() {
        const { captureMode, isRecording } = this.state;

        if (isRecording) {
            this._camera.stopCapture();
            this.setState({ isRecording: false });
            return;
        }

        if (captureMode === captureModeVideo) {
            this.setState({ isRecording: true });
        }

        this._camera.capture({ mode: captureMode })
            .then((result) => console.log(result))
            .catch((error) => console.log(error));
    }

    onSwitchCaptureMode() {
        if (this.state.captureMode === captureModeVideo) {
            this.setState({ captureMode: captureModePhoto });
        } else {
            this.setState({ captureMode: captureModeVideo });
        }
    }

    render() {
        const { captureMode } = this.state;

        return (
            <Camera
                ref={(ref) => this._camera = ref}
                style={{ flex: 1 }}
                captureMode={captureMode}
                captureTarget={CaptureTarget.disk}
            >
                <TouchableOpacity onPress={this.onCapture}>
                    <Icon
                        name='camera-alt'
                        ...
                        ...
                    />
                </TouchableOpacity>
                <TouchableOpacity onPress={this.onSwitchCaptureMode}>
                    <Icon
                        name='...'
                        ...
                        ...
                    />
                </TouchableOpacity>
            </Camera>
        );
    }
}

export default CameraScreen;

当我拍照时,console.log(result)语句记录照片的路径没有问题,但是当captureMode === captureModePhoto时,我的调试器中没有任何日志,是不是我做错了什么?我省略了许多样式以使代码更容易理解。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-25 07:11:27

这是一个愚蠢的错误

我发布的代码工作得非常好,但我必须在真实的设备上测试它。模拟器支持拍照(它会生成一些具有随机背景颜色的图片),但不支持拍照。因此,问题解决了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48637585

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档