Source:  Twitter logo

So I was working on a project that used the react-native video camera from https://github.com/lwansbrough/react-native-camera and had it working. The component would take videos and the data would print in Xcode's console. Unfortunately I lost this file and a couple others on my computer and am starting the app back from scratch. I have been attempting to recreate the camera with video recording capabilities but cannot get it to work. Does anybody know what I am doing wrong because I cannot seem to figure it out. The data will print out when I change the captureMode to camera but nothing will happen for video. Here is my component:

let startVideo = false;

class VideoCamera extends Component {
  constructor() {
    super()
    this.state = {
      captureMode: Camera.constants.CaptureMode.video,
    }
  }
  render() {
    return (
      <Camera
          captureMode={this.state.captureMode}
          ref="camera"
          style={styles.container}
      >
      <TouchableHighlight
          onPressIn={this._startRecord.bind(this)}
          onPressOut={this._endVideo.bind(this)}
      >
      <Icon
          name={'video-camera'}
          size={40}
          style={styles.recordButton}
      />
        </TouchableHighlight>
        </Camera>
      )
  }

  _startRecord() {
    startVideo = setTimeout(this._recordVideo.bind(this), 50)
  }

  _recordVideo() {
    this.refs.camera.capture({})
      .then((data) => console.log(data))
      .catch((err) => console.log(err))
  }

  _endVideo() {
    this.refs.camera.stopCapture()
  }

}

In your _recordVideo method you are passing an empty object to camera.capture, instead you should pass an object specifying the capture mode. Try this version of _recordVideo:

_recordVideo() {
  this.refs.camera.capture({mode: Camera.constants.CaptureMode.video})
    .then((data) => console.log(data))
    .catch((err) => console.log(err))
}
3 users liked answer #0dislike answer #03
Travis Nuttall profile pic
Travis Nuttall

Actually now, it changed, you only have to use the recordAsync() function to start recording.

and stopRecording() to stop the recording.

the recordAsync() return a file uri (.mp4 format) of app cache that you can reuse for your app. Enjoy

2 users liked answer #1dislike answer #12
kevin richard profile pic
kevin richard
recordOptions: {mute: false }

Set this to get the audio and also ask for the audio permission in both android and ios.

0 users liked answer #2dislike answer #20
Bindaas Life profile pic
Bindaas Life

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).