Repository: flutter
Issue: [camera]Recording video results in a black screen at the end of the video.
Labels: platform-ios,p: camera,package,has reproducible steps,P2,team-ios,triaged-ios,found in release: 3.19,found in release: 3.21

### Steps to reproduce

1.initialize everything
2.start recording
3.stop recording
4.initialize video_player controller
5.seekTo the end of the video
6.now you can see a black frame.

Using the example code, you can long press the "camera" button to film something.
lift up your finger, you will see a player widget with 5 buttons:
play: start to play this video
pause: pause
a right arrow: jump to the beginning of this video (Duration.zero)
a E: jump to the end of this video (videoController.value.duration)
exit: resume the preview.

So, if you press the "E" one, you can get a black screen.

I tested on my iPhone, not sure if this happens on Android devices.

It seems that the iOS gallery has applied some optimization for this issue. When viewing the video in the album, there is no black screen anymore. However, when playing the same video using QuickTime, the black screen can be seen again.


### Expected results

it should be the real last frame, instead of a black one.

### Actual results

a black frame

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'dart:io';

import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

late List<CameraDescription> _cameras;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  _cameras = await availableCameras();
  runApp(const MainApp());
}

class MainApp extends StatefulWidget {
  const MainApp({Key? key}) : super(key: key);

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  late CameraController cameraController;
  late VideoPlayerController videoPlayerController;

  @override
  void initState() {
    cameraController = CameraController(
      _cameras[0],
      ResolutionPreset.medium,
    );

    super.initState();
  }

  @override
  void dispose() {
    cameraController.dispose();
    videoPlayerController.dispose();
    super.dispose();
  }

  bool isPlaying = false;
  String filePath = "";

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Stack(
            children: [
              if (!isPlaying)
                FutureBuilder(
                    future: cameraController.initialize(),
                    builder: (context, snapshot) {
                      if (snapshot.connectionState == ConnectionState.done) {
                        return CameraPreview(cameraController);
                      } else {
                        return const CircularProgressIndicator();
                      }
                    }),
              if (isPlaying)
                VideoFrame(
                  videoPlayerController: videoPlayerController,
                  backCallback: () {
                    videoPlayerController.pause();
                    videoPlayerController.dispose();
                    File(filePath).delete();
                    isPlaying = false;
                    setState(() {});
                  },
                ),
              if (!isPlaying)
                Positioned(
                  bottom: 20,
                  right: 20,
                  child: GestureDetector(
                    onLongPressStart: (LongPressStartDetails details) async {
                      await cameraController.startVideoRecording();
                    },
                    onLongPressEnd: (LongPressEndDetails details) async {
                      var file = await cameraController.stopVideoRecording();
                      filePath = file.path;

                      videoPlayerController =
                          VideoPlayerController.file(File(filePath))
                            ..initialize().then((_) {
                              setState(() {});
                            });
                      isPlaying = true;
                      setState(() {});
                      videoPlayerController.play();
                    },
                    child: Container(
                        height: 90,
                        width: 90,
                        decoration: const BoxDecoration(
                          shape: BoxShape.circle,
                          color: Colors.amber,
                        ),
                        child: const Icon(Icons.camera)),
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }
}

class VideoFrame extends StatelessWidget {
  const VideoFrame(
      {super.key,
      required this.videoPlayerController,
      required this.backCallback});

  final VideoPlayerController videoPlayerController;
  final Function() backCallback;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        AspectRatio(
            aspectRatio: videoPlayerController.value.aspectRatio,
            child: VideoPlayer(videoPlayerController)),
        Positioned(
          bottom: 0,
          child: Row(
            children: [
              GestureDetector(
                onTap: () {
                  videoPlayerController.play();
                },
                child: Container(
                    height: 60,
                    width: 60,
                    decoration: const BoxDecoration(
                      shape: BoxShape.circle,
                      color: Colors.amber,
                    ),
                    child: const Icon(Icons.play_arrow)),
              ),
              GestureDetector(
                onTap: () {
                  videoPlayerController.pause();
                },
                child: Container(
                    height: 60,
                    width: 60,
                    decoration: const BoxDecoration(
                      shape: BoxShape.circle,
                      color: Colors.amber,
                    ),
                    child: const Icon(Icons.pause)),
              ),
              GestureDetector(
                onTap: () {
                  videoPlayerController.seekTo(Duration.zero);
                },
                child: Container(
                    height: 60,
                    width: 60,
                    decoration: const BoxDecoration(
                      shape: BoxShape.circle,
                      color: Colors.amber,
                    ),
                    child: const Icon(Icons.start)),
              ),
              GestureDetector(
                onTap: () {
                  videoPlayerController
                      .seekTo(videoPlayerController.value.duration);
                },
                child: Container(
                    height: 60,
                    width: 60,
                    decoration: const BoxDecoration(
                      shape: BoxShape.circle,
                      color: Colors.amber,
                    ),
                    child: const Icon(Icons.e_mobiledata)),
              ),
              GestureDetector(
                onTap: () {
                  backCallback();
                },
                child: Container(
                    height: 60,
                    width: 60,
                    decoration: const BoxDecoration(
                      shape: BoxShape.circle,
                      color: Colors.amber,
                    ),
                    child: const Icon(Icons.exit_to_app_rounded)),
              )
            ],
          ),
        ),
      ],
    );
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.2.1 23C71 darwin-arm64, locale zh-Hans-US)
    • Flutter version 3.16.9 on channel stable at /Users/Documents/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 41456452f2 (7 weeks ago), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/Library/Android/sdk
    • Platform android-34, build-tools 33.0.0
    • ANDROID_HOME = /Users/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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.13+0-b1751.21-8125866)

[✓] VS Code (version 1.87.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.84.0

[✓] Connected device (3 available)
    • iPhone (mobile) • 00008030-000E31623C81802E • ios            • iOS 17.3.1 21D61
    • macOS (desktop)      • macos                     • darwin-arm64   • macOS 14.2.1 23C71 darwin-arm64
    • Chrome (web)         • chrome                    • web-javascript • Google Chrome 122.0.6261.128
   

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>