mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.47k stars 1.09k forks source link

🐛 App crashes (iOS 18.1) when user stops recording video. AVFCapture: CameraSession.deactivateAudioSession() #3261

Open davidfeldt opened 1 day ago

davidfeldt commented 1 day ago

What's happening?

When user stops recording a video, app crashes. The error log from XCode shows the following (see image)

AVFCapture deactivateAudioSession

This happened when we upgraded to version 4.5.2 of the library. The error seems to be happening in the Swift CameraSession+Audio.swift file

final func deactivateAudioSession() { VisionLogger.log(level: .info, message: "Deactivating Audio Session...")

audioCaptureSession.stopRunning()
VisionLogger.log(level: .info, message: "Audio Session deactivated!")

}

This was working fine before we upgraded to RN 0.75 with react-native-vision-camera v. 4.5.2

Reproduceable Code

import {Camera, getCameraDevice} from 'react-native-vision-camera';
...
const stopRecordingVideo = async () => {
    try {
      setIsRecording(false);
      console.log('stopRecordingVideo');
      timerService.stopTimer();
      await camera?.current?.stopRecording();
      setRemainingSeconds(botbVideoLength);
    } catch (error) {
      console.warn(error);
      Alert.alert('Error', error?.cause?.message);
    }
  };
...

<SafeAreaView style={styles.fullscreen}>
      <Text style={styles.headerText}>{question}</Text>
      <View style={styles.videoRecorder}>
        <Camera
          ref={camera}
          style={StyleSheet.absoluteFill}
          device={device}
          isActive={true}
          video={true}
          audio={true}
          preset="medium"
        />
      </View>
      {remainingSeconds > 0 ? displayCountdownTime() : null}
      <View style={styles.row}>
        <Icon
          type="ionicon"
          name="videocam"
          size={35}
          color={colors.cherry}
          // disabled={isRecording}
          onPress={startRecordingVideo}
        />

        <Icon
          type="ionicon"
          name="stop-circle-outline"
          size={35}
          color={colors.cherry}
          // disabled={!isRecording}
          onPress={stopRecordingVideo}
        />

...

Relevant log output

See attached image above showing the error trace.

Camera Device

{
  "position": "front",
  "minFocusDistance": 20,
  "id": "com.apple.avfoundation.avcapturedevice.built-in_video:1",
  "maxZoom": 128.875,
  "isMultiCam": false,
  "supportsLowLightBoost": false,
  "maxExposure": 8,
  "minExposure": -8,
  "name": "Front Camera",
  "hasFlash": true,
  "hardwareLevel": "full",
  "supportsRawCapture": false,
  "neutralZoom": 1,
  "supportsFocus": true,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "hasTorch": false,
  "minZoom": 1,
  "formats": [],
  "sensorOrientation": "portrait"
}

Device

iPhone 14 Pro Max

VisionCamera Version

4.5.2

Can you reproduce this issue in the VisionCamera Example app?

No, I cannot reproduce the issue in the Example app

Additional information

maintenance-hans[bot] commented 1 day ago

Guten Tag, Hans here! 🥨

Thanks for reporting this issue. It seems like you might be facing a crash when stopping the video recording. However, to better assist you, could you please provide more detailed logs from Xcode? Specifically, look for any runtime errors in ze console window to help us diagnose zhis issue more effectively.

Also, make sure to check if zhese issues can be replicated in a basic example with only ze vision camera functionality, as it might help in pinpointing onde the problem lies.

If you're enjoying ze project, consider supporting mrousavy by sponsoring him: Sponsor mrousavy. Your support helps in maintaining ze project!

Looking forward to your updates! 🍻

Note: If you think I made a mistake, please ping @mrousavy to take a look.