Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Blacktaler opened this issue Apr 27, 2024 · 8 comments
Labels
found in release: 3.19 Found to occur in 3.19 found in release: 3.22 Found to occur in 3.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: video_player The Video Player plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team

Comments

@Blacktaler
Copy link

Blacktaler commented Apr 27, 2024

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
Copy link
Author

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
Copy link

KRTirtho commented Apr 29, 2024

@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 huycozy added the in triage Presently being triaged by the triage team label Apr 29, 2024
@huycozy
Copy link
Member

huycozy commented Apr 29, 2024

@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.

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 29, 2024
@maheshmnj maheshmnj changed the title Hi @rohaitas, Thanks for filing the issue. Is it happening with any specific video or all videos, I tried turning off the network, But I didn't see any issue, it continues playing the buffer. [video_player] Video stops playing buffer when wifi is turned off Apr 29, 2024
@maheshmnj
Copy link
Member

Please update the title as needed thats the best I could comprehend from #147463 (comment)

@Blacktaler Blacktaler changed the title [video_player] Video stops playing buffer when wifi is turned off VideoPlayerController's isInitialized state is turning to false, when the internet turns off and the video plays until the buffered position. Apr 29, 2024
@Blacktaler
Copy link
Author

@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

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 29, 2024
@Blacktaler Blacktaler changed the title VideoPlayerController's isInitialized state is turning to false, when the internet turns off and the video plays until the buffered position. VideoPlayerController's isInitialized state is turning to false, when network is gone for a while. Apr 29, 2024
@danagbemava-nc
Copy link
Member

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?

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 30, 2024
@Blacktaler
Copy link
Author

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

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 30, 2024
@huycozy
Copy link
Member

huycozy commented May 2, 2024

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

  • On Flutter iOS which uses AVPlayer underlying, the issue is not reproduced.
  • On Flutter Android, the issue is reproduced. Once the network is resumed, the video does not continue playing.
    I also checked this using ExoPlayer Android native sample code here, and the issue is not there. The playback button will turn into "pause" state automatically when turning off network. Once I turn network on again, press Play button, the video continue playing as desired.

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

Flutter sample code
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.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)
Screen.Recording.2024-05-02.at.11.37.25.mov
flutter doctor -v (stable and master)
[✓] 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!
[!] 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.

@huycozy huycozy added platform-android Android applications specifically p: video_player The Video Player plugin package flutter/packages repository. See also p: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on team-android Owned by Android platform team fyi-ecosystem For the attention of Ecosystem team found in release: 3.19 Found to occur in 3.19 found in release: 3.22 Found to occur in 3.22 and removed in triage Presently being triaged by the triage team labels May 2, 2024
@yaakovschectman yaakovschectman added P2 Important issues not at the top of the work list triaged-android Triaged by Android platform team labels May 2, 2024
@stuartmorgan stuartmorgan added the triaged-ecosystem Triaged by Ecosystem team label May 8, 2024
@flutter-triage-bot flutter-triage-bot bot removed fyi-ecosystem For the attention of Ecosystem team triaged-ecosystem Triaged by Ecosystem team labels May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
found in release: 3.19 Found to occur in 3.19 found in release: 3.22 Found to occur in 3.22 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: video_player The Video Player plugin P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. platform-android Android applications specifically team-android Owned by Android platform team triaged-android Triaged by Android platform team
Projects
None yet
Development

No branches or pull requests

7 participants