首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >相机还没准备好!等待onInitialized()

相机还没准备好!等待onInitialized()
EN

Stack Overflow用户
提问于 2022-11-15 16:52:22
回答 1查看 37关注 0票数 0

我正试图在我的React中实现react-native-vision-camera,它在iOS上运行得非常完美,但在Android上却拒绝正常工作。在Android上,我会遇到以下错误.

[session/camera-not-ready] The Camera is not ready yet! Wait for the onInitialized() callback!

据我所见,在验证权限之前调用is时会发生此错误,而在我的应用程序中并非如此。考虑以下几点..。

代码语言:javascript
复制
// Camera Permission State
const [cameraPerm, setCameraPerm] = useState(false)

// Checks Mic and Video Permissions as soon as page loads
useEffect(() => {
  checkPermissions();
}, []);


// Called in a useEffect to gain permissions
const checkPermissions = async () => {
    // Request Permissions on component load
    await Camera.requestCameraPermission();
    await Camera.requestMicrophonePermission();
    await requestPermission()

    const cameraPermission = await Camera.getCameraPermissionStatus();
    setCameraPerm(cameraPermission)
    const microphonePermission = await Camera.getMicrophonePermissionStatus();
};


  // Renders The Camera, if permissed and not done recording
  function renderCameraScreen(){
    // No permissions
    if (device == null) return <View style={{backgroundColor: 'black'}}/>;

    // Video Recorded
    if (recorded){
      return(
        <View>
          <Text style={{...FONTS.Title, textAlign: 'center', marginTop: 100}}>
            Video Recorded
          </Text>
        </View>
      )
    }

    if (!cameraPerm){
      return(
        <View>
          <Text style={{...FONTS.Title, textAlign: 'center', marginTop: 100}}>
            Please enable video permissions from your settings to access the camera
          </Text>
        </View>
      )
    }


    return (
      <View style={{backgroundColor: 'black', height: maxHeight * 0.70,}}>
        <Camera
          style={StyleSheet.absoluteFill}
          device={device}
          isActive={true}
          video={true}
          audio={true}
          ref={camera}
        />
        <View style={{alignSelf: 'center', marginTop: maxHeight * 0.65}}>
          {renderRecordButton()}
        </View>
      </View>
    );
  };

考虑到这一点,我不知道为什么会有这个错误。老实说,我在任何文档中都没有提到onInitialized(),所以我不确定如何使用该函数,以及在哪里使用该函数。

EN

回答 1

Stack Overflow用户

发布于 2022-11-15 16:56:16

https://github.com/mrousavy/react-native-vision-camera/issues/789说,也许你需要隐藏相机,直到你的应用程序被授权使用相机。

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

https://stackoverflow.com/questions/74449379

复制
相关文章

相似问题

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