react-native-nodemediaclient icon indicating copy to clipboard operation
react-native-nodemediaclient copied to clipboard

Camera preview make app crashes when using react-navigation

Open flavioribeirojr opened this issue 4 years ago • 7 comments

Hi y'all!

I am facing an issue when using the camera preview. The camera works at first, but if I try to navigate back from screen B to screen A(which contains the camera preview) the app crashes.

Could someone provide me guidance on how to fix this?

flavioribeirojr avatar May 28 '21 12:05 flavioribeirojr

Hi @flavioribeirojr, please were you able to fix this? My situation is that i have a HomeScreen from where i launch the StreamScreen. The Stream seems to work ok but after i stop it and navigate back to the HomeScreen the app crashes and there is no logs printed.

Environment details:

  • react-navigation: 5.9.4
  • react-native-nodemediaclient: 0.2.17

moschap avatar Jun 06 '21 05:06 moschap

@moschap I could not found a solution using react-navigation. For now I have switch to react-router(native)

flavioribeirojr avatar Jun 07 '21 11:06 flavioribeirojr

Still a major issue

Vercjames avatar Sep 07 '21 00:09 Vercjames

Here's a work around is to destroy the NodeCameraView with a conditional and remount it when you revisit the page/route/stack.

export const StreamingRoute =  (props: any) => {
  const [renderHack, setRenderHack] = React.useState(false)

  useFocusEffect(
    React.useCallback(() => {
      // This event fires when the component is focused
      setRenderHack(true)

      return () => {
        // This event fires when the component is unfocused
        setRenderHack(false)
      }
    }, [])
  )

  // camera controllers here like stop, start, flip, etc... 
  ...
  

  return (
    <View style={[{ flex: 1, }]}>
      { renderHack ? (
        <NodeCameraView
          outputUrl={""}
          ref={(vb: any) => {setNodeCamera(vb)}}
          camera={{ cameraId: 0, cameraFrontMirror: true }}
          audio={{ bitrate: 32000, profile: 1, samplerate: 44100 }}
          video={{ preset: 1, bitrate: 400000, profile: 1, fps: 15, videoFrontMirror: false }}
          autopreview={renderHack}
        />
      ) : null }
    </View>
  )
}

Vercjames avatar Sep 16 '21 05:09 Vercjames

same problem! Anyone got any solution, please :((

tu-nd avatar Oct 06 '21 17:10 tu-nd

Here's a work around is to destroy the NodeCameraView with a conditional and remount it when you revisit the page/route/stack.

export const StreamingRoute =  (props: any) => {
  const [renderHack, setRenderHack] = React.useState(false)

  useFocusEffect(
    React.useCallback(() => {
      // This event fires when the component is focused
      setRenderHack(true)

      return () => {
        // This event fires when the component is unfocused
        setRenderHack(false)
      }
    }, [])
  )

  // camera controllers here like stop, start, flip, etc... 
  ...
  

  return (
    <View style={[{ flex: 1, }]}>
      { renderHack ? (
        <NodeCameraView
          outputUrl={""}
          ref={(vb: any) => {setNodeCamera(vb)}}
          camera={{ cameraId: 0, cameraFrontMirror: true }}
          audio={{ bitrate: 32000, profile: 1, samplerate: 44100 }}
          video={{ preset: 1, bitrate: 400000, profile: 1, fps: 15, videoFrontMirror: false }}
          autopreview={renderHack}
        />
      ) : null }
    </View>
  )
}

It's work sometimes, When I try it again It's crash

tuannguyen0410 avatar Oct 11 '21 04:10 tuannguyen0410

same issue here

9amcoder avatar Oct 21 '21 04:10 9amcoder