Repository: flutter
Issue: [camera][android] App throws exception when trying to resume video after returning from background
Labels: c: crash,platform-android,p: camera,package,has reproducible steps,P2,found in release: 3.3,found in release: 3.5,team-android,triaged-android

I'm developing a feature where if the user starts video recording and puts the app in the background then the recording should be paused and when the user comes back to the app it should be resumed.
Now if I came back within 60 secs then it is working fine but after 60 secs I'm getting these logs - 

open | onError
open | onClosed

and when I resume the app I get this exception -

```
E/MethodChannel#plugins.flutter.io/camera_android( 4852): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaRecorder.resume()' on a null object reference
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at io.flutter.plugins.camera.Camera.resumeVideoRecording(Camera.java:820)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at io.flutter.plugins.camera.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:136)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at android.os.Looper.loopOnce(Looper.java:201)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at android.os.Looper.loop(Looper.java:288)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at android.app.ActivityThread.main(ActivityThread.java:7839)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/MethodChannel#plugins.flutter.io/camera_android( 4852): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
```

## Steps to Reproduce

Project repo - https://github.com/gauravkatkar1000/flutter_camera.git

1. Clone this project and run.
2. Start recording.
3. Go to the background.
4. Wait for 60 secs.
5. Resume the app


**Expected results:**  - Video recording should be resumed

**Actual results:**  - Getting an Exception 

<details>
<summary>Code sample</summary>

https://github.com/gauravkatkar1000/flutter_camera.git

</details>

<details>
 <summary>Logs</summary>

flutter run --verbose -

```
[  +32 ms] I/Camera  ( 9292): prepareMediaRecorder
[+1482 ms] I/Camera  ( 9292): CameraCaptureSession onConfigured
[        ] I/Camera  ( 9292): Updating builder settings
[        ] D/Camera  ( 9292): Updating builder with feature: ExposureLockFeature
[        ] D/Camera  ( 9292): Updating builder with feature: ExposurePointFeature
[        ] D/Camera  ( 9292): Updating builder with feature: ZoomLevelFeature
[        ] D/Camera  ( 9292): Updating builder with feature: AutoFocusFeature
[        ] D/Camera  ( 9292): Updating builder with feature: NoiseReductionFeature
[        ] I/Camera  ( 9292): updateNoiseReduction | currentSetting: fast
[        ] D/Camera  ( 9292): Updating builder with feature: FocusPointFeature
[        ] D/Camera  ( 9292): Updating builder with feature: ResolutionFeature
[        ] D/Camera  ( 9292): Updating builder with feature: SensorOrientationFeature
[        ] D/Camera  ( 9292): Updating builder with feature: FlashFeature
[        ] D/Camera  ( 9292): Updating builder with feature: ExposureOffsetFeature
[        ] D/Camera  ( 9292): Updating builder with feature: FpsRangeFeature
[        ] I/Camera  ( 9292): refreshPreviewCaptureSession
[  +36 ms] I/Camera  ( 9292): CameraCaptureSession onClosed
[ +172 ms] D/EGL_emulation( 9292): app_time_stats: avg=194.26ms min=2.76ms max=1131.39ms count=8
[+1020 ms] D/EGL_emulation( 9292): app_time_stats: avg=77.68ms min=3.77ms max=106.04ms count=13
[+1024 ms] D/EGL_emulation( 9292): app_time_stats: avg=85.56ms min=50.29ms max=121.29ms count=12
[+1068 ms] D/EGL_emulation( 9292): app_time_stats: avg=88.95ms min=45.46ms max=120.21ms count=12
[ +944 ms] I/flutter ( 9292): --------------- Recording Paused ---------------
[ +122 ms] D/EGL_emulation( 9292): app_time_stats: avg=105.97ms min=68.19ms max=256.56ms count=10
[+5370 ms] W/System  ( 9292): A resource failed to call release. 
[+55006 ms] I/Camera  ( 9292): open | onError
[        ] I/Camera  ( 9292): close
[ +561 ms] I/flutter ( 9292): After 61 secs ---------------------------
[   +3 ms] I/flutter ( 9292): CameraController#c3814(CameraValue(isRecordingVideo: true, isInitialized: true, errorDescription: null, previewSize: Size(320.0,
240.0), isStreamingImages: false, flashMode: FlashMode.auto, exposureMode: ExposureMode.auto, focusMode: FocusMode.auto, exposurePointSupported: true,
focusPointSupported: true, deviceOrientation: DeviceOrientation.portraitUp, lockedCaptureOrientation: null, recordingOrientation: DeviceOrientation.portraitUp,
isPreviewPaused: true, previewPausedOrientation: DeviceOrientation.portraitUp))
[ +936 ms] I/Camera  ( 9292): open | onClosed
[+4226 ms] I/Camera  ( 9292): refreshPreviewCaptureSession
[        ] I/Camera  ( 9292): refreshPreviewCaptureSession: captureSession not yet initialized, skipping preview capture session refresh.
[ +141 ms] E/MethodChannel#plugins.flutter.io/camera_android( 9292): Failed to handle method call
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292): java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.media.MediaRecorder.resume()' on a null object reference
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at io.flutter.plugins.camera.Camera.resumeVideoRecording(Camera.java:820)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at
io.flutter.plugins.camera.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:136)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at
io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at
io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown
Source:12)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at android.os.Handler.handleCallback(Handler.java:938)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at android.os.Handler.dispatchMessage(Handler.java:99)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at android.os.Looper.loopOnce(Looper.java:201)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at android.os.Looper.loop(Looper.java:288)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at android.app.ActivityThread.main(ActivityThread.java:7839)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at java.lang.reflect.Method.invoke(Native Method)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
[        ] E/MethodChannel#plugins.flutter.io/camera_android( 9292):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
[  +33 ms] I/OpenGLRenderer( 9292): Davey! duration=89367ms; Flags=1, FrameTimelineVsyncId=54610, IntendedVsync=3504378568291, Vsync=3504511901619, InputEventId=0,
HandleInputStart=3504518448118, AnimationStart=3504518460548, PerformTraversalsStart=3504518461567, DrawStart=3504520972635, FrameDeadline=3504411901623,
FrameInterval=3504518405196, FrameStartTime=16666666, SyncQueued=3504522684198, SyncStart=3504539123779, IssueDrawCommandsStart=3504548926324,
SwapBuffers=3504638990006, FrameCompleted=3593762396311, DequeueBufferDuration=97139798, QueueBufferDuration=6075452, GpuCompleted=3593762396311,
SwapBuffersCompleted=3504769350093, DisplayPresentTime=71773198500158, 
[  +27 ms] I/flutter ( 9292): --------------- Recording Resumed ---------------
```

</details>

<details>
<summary>flutter doctor -v </summary>

```
[✓] Flutter (Channel stable, 3.3.2, on Ubuntu 20.04.5 LTS 5.14.0-1052-oem, locale en_IN)
    • Flutter version 3.3.2 on channel stable at /home/jombay-admin/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e3c29ec00c (4 weeks ago), 2022-09-14 08:46:55 -0500
    • Engine revision a4ff2c53d8
    • Dart version 2.18.1
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /home/jombay-admin/Android/Sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /opt/android-studio-2021.1.1/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
    • cmake version 3.10.2
    • ninja version 1.8.2
    • pkg-config version 0.29.1

[✓] Android Studio (version 2021.1)
    • Android Studio at /opt/android-studio-2021.1.1/android-studio
    • Flutter plugin version 70.2.1
    • Dart plugin version 211.7817
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] Android Studio
    • Android Studio at /opt/android-studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7590822)

[✓] Connected device (3 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 12 (API 31) (emulator)
    • Linux (desktop)              • linux         • linux-x64      • Ubuntu 20.04.5 LTS 5.14.0-1052-oem
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 106.0.5249.61

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
```

</details>