flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.18k stars 26.64k forks source link

VideoPlayerController's isInitialized state is turning to false, when network is gone for a while. #147463

Open Blacktaler opened 2 weeks ago

Blacktaler commented 2 weeks ago

I'm using VideoPlayer plugin and there are issues with network. For example, I initialize the video in initState, video starts to play, VideoPlayerController buffers 1-3 minutes of the video. I turn off the network(wifi or mobile data). Video plays until the buffered position(3 minutes). If I do not turn on the network while that time, VideoPlayerController's isInitialized state turns false. After that, video will not continue even if the network is back.

Steps to reproduce:

1) Declare VideoPlayerController as variable, initialize in initState method. 2) Use VideoPlayer widget inside the body, give the videoPlayerController to the widget. 3) Turn off the network for a while,(until the videoPlayerController gets reset). 4) Turn on the network, video will not continue to play.

Blacktaler commented 2 weeks ago

it's happening with all videos, just play the video when wifi is turned on, then play the video until the buffered position, then it will stop showing the video and controller's isInitialized value becomes false, then even if your network is returned it will not continue playing.

Anyways, I was trying to check and re initialize when the controller becomes uninitialized, but after once it does not even message that controller has become unInitialized.

Please fix at least one of these errors above, thanks in advance.

KRTirtho commented 2 weeks ago

@Blacktaler please make sure your issue title is a summary of the problem you're facing so maintainers can understand it at a glance. And it shouldn't be that long

huycozy commented 2 weeks ago

@Blacktaler Please help to elaborate on the issue by providing step-by-step to reproduce, actual/expected results, and a minimal sample code that presents the issue.

maheshmnj commented 2 weeks ago

Please update the title as needed thats the best I could comprehend from https://github.com/flutter/flutter/issues/147463#issuecomment-2080635894

Blacktaler commented 2 weeks ago

@Blacktaler please make sure your issue title is a summary of the problem you're facing so maintainers can understand it at a glance. And it shouldn't be that long

Sorry I wanted to reply in an issue, but instead an issue has been opened

danagbemava-nc commented 2 weeks ago

Hi @Blacktaler, what version of video_player are you using? What device(s) are you seeing this on? And what issue did you want to reply to?

Blacktaler commented 2 weeks ago

Hi @Blacktaler, what version of video_player are you using? What device(s) are you seeing this on? And what issue did you want to reply to?

In any android device it's happening. I'm using 2.7.2-version of video_player plugin. I wanted to reply in this #107802 issue issue

huycozy commented 1 week ago

I checked this using the sample code below (which has VideoProgressIndicator to see the cached video part more easily).

Reproduced the issue with the latest package version video_player_android: ^2.4.14.

Flutter sample code ```dart 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 createState() => _VideoPlayerScreenState(); } class _VideoPlayerScreenState extends State { late VideoPlayerController _controller; late Future _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.networkUrl( Uri.parse('http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4'), ); // 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 Stack( alignment: Alignment.bottomCenter, children: [ AspectRatio( aspectRatio: _controller.value.aspectRatio, // Use the VideoPlayer widget to display the video. child: VideoPlayer(_controller), ), VideoProgressIndicator( _controller, allowScrubbing: true, colors: VideoProgressColors(playedColor: Theme.of(context).primaryColor), ), ], ); } 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, ), ), ); } } ```
Demo issue (Android) https://github.com/flutter/flutter/assets/104349824/9ec3ba09-b464-46c1-b155-f8c19cfe2c93
flutter doctor -v (stable and master) ```bash [✓] Flutter (Channel stable, 3.19.6, on macOS 14.1 23B74 darwin-x64, locale en-VN) • Flutter version 3.19.6 on channel stable at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 54e66469a9 (31 hours ago), 2024-04-17 13:08:03 -0700 • Engine revision c4cd48e186 • Dart version 3.3.4 • DevTools version 2.31.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode15.3.app/Contents/Developer • Build 15E204a • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.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 • android-studio-dir = /Applications/Android Studio.app/ • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) [✓] VS Code (version 1.88.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (3 available) • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 11 (API 30) • macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.124 [✓] Network resources • All expected network resources are available. • No issues found! ``` ```bash [!] Flutter (Channel master, 3.22.0-21.0.pre.20, on macOS 14.1 23B74 darwin-x64, locale en-VN) • Flutter version 3.22.0-21.0.pre.20 on channel master at /Users/huynq/Documents/GitHub/flutter_master ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 706f39b0a0 (45 minutes ago), 2024-05-02 02:26:28 +0000 • Engine revision 3087ec1add • Dart version 3.5.0 (build 3.5.0-121.0.dev) • DevTools version 2.35.0 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode15.3.app/Contents/Developer • Build 15E204a • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.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 • android-studio-dir = /Applications/Android Studio.app/ • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874) [✓] VS Code (version 1.88.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.93 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```