viromedia / viro

ViroReact: AR and VR using React Native
MIT License
2.31k stars 483 forks source link

Video doesn't stop on most of iPhone/iOS versions when AR scene is unmounted causing memory leaks #1005

Open Buthrakaur opened 10 months ago

Buthrakaur commented 10 months ago

Environment

Please provide the following information about your environment:

  1. Development OS: Mac
  2. Device OS & Version: iOS 15, 16
  3. Version: ViroReact version 2.23.1 and React Native version 0.71.3
  4. Device(s): iPhone SE iOS 15.x, iPhone 8, iOS 16.5.1

Description

Video playback doesn't stop when AR scene is unmounted and the audio keeps playing after the scene is unmounted causing memory leak of AVPlayer instance. We tried to resolve this by pausing the playback when on AR scene unmount but it doesn't prevent memory leak of the AVPlayer instance. We tried this on multiple iPhones with mixed results:

Reproducible Demo

Just use a simple AR scene with ViroVideo component opened from a screen in the app.

    <ViroARScene onCameraTransformUpdate={onCameraTransformUpdate} onTrackingUpdated={onInitialized}>
       <ViroVideo
            position={offsetPosition}
            loop={feature.loop}
            rotation={objectRotation}
            width={feature.size.width}
            height={feature.size.height}
            source={feature.source}
            onBufferEnd={onLoadEnded}
            onError={onLoadFailed}
          />
    </ViroARScene>