Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 相机没有运行_Android_React Native_Expo - Fatal编程技术网

Android 相机没有运行

Android 相机没有运行,android,react-native,expo,Android,React Native,Expo,我正试图制作一个反复使用的原型应用程序 1-用摄像机录制视频x秒 2-显示此视频 为此,我使用expo Camera的组件摄像头和expo av的视频 对此,我有两种看法: 我在代码中使用stateSequence属性和sequencer()函数,该函数交替显示带有摄影机组件的视图,摄影机组件可以拍摄x秒,视频视图允许我显示视频 Sequencer()由componentWillMount()中的setInterval(this.Sequencer,10000)触发 我可以交替地从带有摄像头组件

我正试图制作一个反复使用的原型应用程序

1-用摄像机录制视频x秒

2-显示此视频

为此,我使用expo Camera的组件摄像头和expo av的视频

对此,我有两种看法:

我在代码中使用stateSequence属性和sequencer()函数,该函数交替显示带有摄影机组件的视图,摄影机组件可以拍摄x秒,视频视图允许我显示视频

Sequencer()由componentWillMount()中的setInterval(this.Sequencer,10000)触发

我可以交替地从带有摄像头组件的视图切换到带有视频组件的视图

要使用摄像头组件录制视频,我使用recordAsync(),但出现以下错误:

Unhandled promise rejection: Error: Camera is not running
我在用安卓手机做测试

你能帮帮我吗

这是我的密码

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',
    },
  });
从'react native'导入{样式表、文本、视图、TouchableOpacity};
从“expo Permissions”导入*作为权限;
从“expo Camera”导入{Camera};
从“expo av”导入{Video};
从“expo”导入{Logs};
导出默认类SequenceViewer扩展组件{
建造师(道具){
超级(道具);
此.state={
状态序列:“射击”,
hasCameraPermission:null,
类型:Camera.Constants.type.front,
}
this.recordVideo=this.recordVideo.bind(this)
}
sequencer=()=>{
如果(this.state.stateSequence==“WATCH”){
this.setState({stateSequence:“SHOOT”,})
this.recordVideo();//错误消息Camera未运行
}否则{
this.setState({stateSequence:“WATCH”})
}
}
异步组件willmount(){
let rollStatus=wait Permissions.askAsync(Permissions.CAMERA\u ROLL);
let cameraResponse=wait Permissions.askAsync(Permissions.CAMERA)
如果(rollStatus.status==“已授予”){
如果(cameraResponse.status==“已授予”){
let audioResponse=wait Permissions.askAsync(Permissions.AUDIO_RECORDING);
如果(audioResponse.status==“已授予”){
this.setState({permissionsGranted:true});
setInterval(该序列器,10000);
}  
}
}                  
}
recordVideo=async()=>{
if(this.state.cameraIsRecording){
this.setState({cameraisserving:false})
这个.camera.stopRecording();
}
否则{
this.setState({cameraisserving:true})
如果(这个相机){
让record=wait this.camera.recordAsync(quality='480p',maxDuration=5,mute=true)。然后(data=>{
this.setState({recVideoUri:data.uri})
}) 
}   
}
};  
render(){
const{hasCameraPermission}=this.state
if(this.state.stateSequence==“WATCH”)
{
返回(
{this.player=ref}}
/>
)
}否则
{
返回(
{this.camera=ref;}}>
)
}
}
}
const styles=StyleSheet.create({
查看文字:{
尺寸:20,
fontWeight:'粗体',
},
容器:{
弹性:1,
背景颜色:“#fff”,
对齐项目:“居中”,
为内容辩护:“中心”,
},
});

谢谢

我也遇到了同样的问题,我的解决方案是默认情况下相机类型必须为“后退”,您可以通过以下方式更改为“前进”:


我也有同样的问题,你解决了吗?你有哪个sdk???不,我没有解决,我用的是35 sdk
componentDidMount = () => {
    this.props.navigation.addListener('didFocus', async () => {
      await setTimeout(() => {
        this.setState({ cameraType: Camera.Constants.Type.front })
      }, 100)
    });
  }