Camera is not running

Hello
I’m trying to make a prototype application that over and over
1- record a video with the camera for x seconds
2- displays this video

For this I use the components

  • Camera from expo-camera
  • Video from expo-av

For this I have two views :

I use in my code the stateSequence property and the sequencer() function which displays alternately the view with the Camera component which films for x seconds , and the video view which allows me to display the video.

Sequencer() is triggered with setInterval( this.sequencer , 10000) found in the componentWillMount()

I can switch alternately from a View with the Camera component to a View with the Video component.

To record a video with the Camera component I use recordAsync(), but I get the following error:

Unhandled promise rejection: Error: Camera is not running

I’m using an android phone for my tests.

Can’t you help me

this is my code

import React, { Component } from 'react';
import { StyleSheet, Text, View ,TouchableOpacity} from 'react-native';

import * as Permissions from 'expo-permissions';
import { Camera } from 'expo-camera';
import { Video } from 'expo-av';
import { Logs } from 'expo';


export default class SequenceViewer extends Component {
  constructor(props) {
    super(props);
    this.state = {
      stateSequence: "SHOOT ",
      hasCameraPermission: null,
      type: Camera.Constants.Type.front,
    }
    this.recordVideo = this.recordVideo.bind(this)
  }
  
  sequencer = () => {  
  
    if(this.state.stateSequence==="WATCH"){ 
      this.setState({  stateSequence: "SHOOT",})
    
      this.recordVideo();  //  Error message   Camera is not running
    
    } else {
      this.setState({stateSequence: "WATCH"})
    }
      
   
  }

  async componentWillMount() {    
    let  rollStatus  = await Permissions.askAsync(Permissions.CAMERA_ROLL);
    let cameraResponse = await Permissions.askAsync(Permissions.CAMERA)
    if (rollStatus.status=='granted'){
      if (cameraResponse.status == 'granted' ){
        let audioResponse = await Permissions.askAsync(Permissions.AUDIO_RECORDING);
        if (audioResponse.status == 'granted'){
          this.setState({ permissionsGranted: true });
         
          setInterval( this.sequencer , 10000);
      
        }  
      }
    }                  
  }

  recordVideo = async () => {

            if(this.state.cameraIsRecording){
              this.setState({cameraIsRecording:false})
              this.camera.stopRecording();
            }
            else {
              this.setState({cameraIsRecording:true})
              if (this.camera) {
                let record = await  this.camera.recordAsync(quality='480p',maxDuration=5,mute=true).then( data =>{
                 
                  this.setState( {recVideoUri :data.uri})                         
                }) 
             }   
                  
            }
  };  
 

  render() {
   
    const { hasCameraPermission } = this.state
      if(this.state.stateSequence=="WATCH")
      {
        return(
          <View style={styles.container}>
           <Video
              source={{ uri:this.state.recVideoUri }}
              rate={1.0}
              volume={1.0}
              isMuted={false}
              resizeMode="cover"
              shouldPlay
              isLooping
              style={{ width: 300, height: 300 }}
              ref={(ref) => { this.player = ref }}   
            />
        </View>  
        )

      } else
      {
        return(
         
          <View style={{ flex: 1 }}>
          <Camera style={{ flex: 1 }} type={this.state.type}  ref={ref => {this.camera = ref; }}></Camera>
        </View>
          
        )
      }
  }
}

const styles = StyleSheet.create({
    viewerText: {
        fontSize: 20,
        fontWeight: 'bold',
    },
    container: {
      flex: 1,
      backgroundColor: '#fff',
      alignItems: 'center',
      justifyContent: 'center',
    },
  });

Thank you