Repository: flutter
Issue: [video_player] iOS seems to downloads entire file before playing
Labels: platform-ios,p: video_player,package,has reproducible steps,P2,found in release: 3.10,found in release: 3.11,team-ios,triaged-ios

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

1. Start with the code found in the complete example here: https://docs.flutter.dev/cookbook/plugins/play-video.

2. Change the network-loaded video URL to that of a much, much longer video in MP4 format:  https://player.vimeo.com/progressive_redirect/playback/824940727/rendition/1080p/file.mp4?loc=external&signature=70433d8bf85f37e1ecca01ac0beed15a995bc12b1771d967b55c7101a509a480

3. Run this in the iOS simulator - or on a physical iOS device. 

4. Note that this is extremely slow - in my case over 2 minutes before the circular spinner goes away. On the other hand, the Android and Web platforms both popped the player up very quickly, within a second or two.

5. Watch the Activity Monitor and see the Bytes Received climb up to over 3GB for the Runner process before the circular spinner goes away.

I'm on MacOS Ventura 13.2.1 on an M2 Pro Macbook Pro 16" 2023. However, the same exact behavior is seen on a physical iPhone 12 Mini running iOS 15. 



### Expected results

I expect this to behave like the Android and Web platforms:  pop the player up quickly and allow me to begin playing it while it continues to buffer. Also, rather than downloading the entire video the other platforms seem to stop buffering while not playing. 

### Actual results

I have to wait between a minute and a half and about three minutes before I can play it. 

Working through the debugger shows that the underlying call to the AVFoundationPlayer is snappy but the events are not firing for quite some time afterward.

Walking through the differences between the behavior, on Android the _initializeVideoPlayerFuture has it's then() method called quickly. On iOS this takes a very long time. However, all of the underlying native calls found in the respective messages.g.dart files (within both the video_player_android and video_player_avfoundation libraries) return quickly. No differences there. The initialize() returns quickly with no errors and the create() returns a texture ID rapidly. 

Then, on iOS, nothing at all happens for a long time in the code until eventually the _initializeVideoPlayerFuture calls then() and we can finally get on with things.

When I look at the Mac Activity Monitor while running in the simulator, the network is extremely busy for the 1.5 - 3+ minutes it takes to load the video. Then it is completely flat while playing the video. This seems to imply that the network() call downloads the entire video before proceeding. 



### Code sample

<details>
<summary>Code Example</summary>

```

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

void main() => runApp(const VideoPlayerApp());

class VideoPlayerApp extends StatelessWidget {
  const VideoPlayerApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Video Player Demo',
      home: VideoPlayerScreen(),
    );
  }
}

class VideoPlayerScreen extends StatefulWidget {
  const VideoPlayerScreen({super.key});

  @override
  State<VideoPlayerScreen> createState() => _VideoPlayerScreenState();
}

class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
  late VideoPlayerController _controller;
  late Future<void> _initializeVideoPlayerFuture;

  @override
  void initState() {
    super.initState();

    // Create and store the VideoPlayerController. The VideoPlayerController
    // offers several different constructors to play videos from assets, files,
    // or the internet.
    _controller = VideoPlayerController.network(
      'https://player.vimeo.com/progressive_redirect/playback/824940727/rendition/1080p/file.mp4?loc=external&signature=70433d8bf85f37e1ecca01ac0beed15a995bc12b1771d967b55c7101a509a480',
    );

    // Initialize the controller and store the Future for later use.
    _initializeVideoPlayerFuture = _controller.initialize();

    // Use the controller to loop the video.
    _controller.setLooping(true);
  }

  @override
  void dispose() {
    // Ensure disposing of the VideoPlayerController to free up resources.
    _controller.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Butterfly Video'),
      ),
      // Use a FutureBuilder to display a loading spinner while waiting for the
      // VideoPlayerController to finish initializing.
      body: FutureBuilder(
        future: _initializeVideoPlayerFuture,
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            // If the VideoPlayerController has finished initialization, use
            // the data it provides to limit the aspect ratio of the video.
            return AspectRatio(
              aspectRatio: _controller.value.aspectRatio,
              // Use the VideoPlayer widget to display the video.
              child: VideoPlayer(_controller),
            );
          } else {
            // If the VideoPlayerController is still initializing, show a
            // loading spinner.
            return const Center(
              child: CircularProgressIndicator(),
            );
          }
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          // Wrap the play or pause in a call to `setState`. This ensures the
          // correct icon is shown.
          setState(() {
            // If the video is playing, pause it.
            if (_controller.value.isPlaying) {
              _controller.pause();
            } else {
              // If the video is paused, play it.
              _controller.play();
            }
          });
        },
        // Display the correct icon depending on the state of the player.
        child: Icon(
          _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
        ),
      ),
    );
  }
}

```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

```

My QuickTime screen recording was too big to upload here so I popped it up on Google Drive:

https://drive.google.com/file/d/1-xFNBLf0lkPkharwiGZTmlyRlI3XolpQ/view?usp=sharing

```

</details>


### Logs

<details><summary>Logs</summary>

Generated with `flutter run -d iPhone --verbose`

[slow-ios-video-logfile.txt](https://github.com/flutter/flutter/files/11471262/slow-ios-video-logfile.txt)

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.10.0, on macOS 13.2.1 22D68 darwin-arm64, locale
    en-US)
    • Flutter version 3.10.0 on channel stable at /Users/bjc/fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 84a1e904f4 (5 days ago), 2023-05-09 07:41:44 -0700
    • Engine revision d44b5a94c9
    • Dart version 3.0.0
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/bjc/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • 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
      17.0.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 73.0.4
    • Dart plugin version 231.8109.91

[✓] Connected device (4 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554                        •
      android-arm64  • Android 13 (API 33) (emulator)
    • iPhone 14 Pro Max (mobile)  • DA632553-F1D7-4EDD-8DD9-62F7E16CB756 • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)             • macos                                •
      darwin-arm64   • macOS 13.2.1 22D68 darwin-arm64
    • Chrome (web)                • chrome                               •
      web-javascript • Google Chrome 113.0.5672.92

[✓] Network resources
    • All expected network resources are available.

• No issues found!

```

</details>