react-video-recorder icon indicating copy to clipboard operation
react-video-recorder copied to clipboard

Call onStartRecording callback after the countdown

Open alexeymetelkinpro opened this issue 3 years ago • 0 comments

Hey there!

I noticed that onStartRecording callback fires right after the record button is clicked, although if countdownTime is non-zero, then actual recording won't start at that moment (cause it's going to timeout on the amount of countdownTime)

Here is the code:

...
handleStartRecording = () => {
    if (this.props.onStartRecording) { 
      this.props.onStartRecording()             // <--- Calling the callback 
    }

    this.setState({
      isRunningCountdown: true,
      isReplayingVideo: false
    })

    setTimeout(() => this.startRecording(), this.props.countdownTime)   // <--- setting the timeout on recording
  }

  startRecording = () => {
    captureThumb(this.cameraVideo).then((thumbnail) => {
      this.thumbnail = thumbnail

      this.recordedBlobs = []
      const options = {
        mimeType: this.getMimeType()
      }

      try {
        this.setState({
          isRunningCountdown: false,
          isRecording: true                           // <--- setting up the recording flag
        })
...

Basically, onStartRecording happens at the same moment as the countdown starts to count down, at the same time isRecording is flagged only when it is actually starts recording.

Wouldn't it be more consistent if we move onStartRecording call after the countdown?

alexeymetelkinpro avatar Oct 19 '21 10:10 alexeymetelkinpro