Skip to content

Add workaround for invalid buffering info on android #912

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

Merged

Conversation

timoxd7
Copy link
Contributor

@timoxd7 timoxd7 commented Apr 2, 2025

Info

As already described in multiple issues, there is currently a problem with android reporting "isBuffering" with true even if the video is already playing, preventing the video controls to be displayed. This is a workaround, checking (on android only) if the video is actually buffering. Tested with a network- and file-based video.

NOTE: This is only a workaround until video_player and flutter is fixed. See flutter/flutter#165149 for more information. Also thanks to @wenwangwill who added a workaround as comment i got inspired from.

Additional Issues not solved

If pausing the video and seeking to some point (using seekTo, so clicking on the progress bar) still leads to the infinit loading bar, as no callback is called by the video controller and thus the buffering not updated.

As workaround, just start playing on seekTo like this:

  // Your init code can be above
  videoController.addListener(yourListeningMethod);

  // ...

  bool wasPlayingBefore = false;
  void yourListeningMethod() {
    if (!videoController.value.isPlaying && !wasPlayingBefore) {
      // -> Workaround if seekTo another position while it was paused before
      //    on Android this might lead to infinite loading, so just play the
      //    video again.
      videoController.play();
    }

    wasPlayingBefore = videoController.value.isPlaying;

  // ...
  }

Related to

#909
#907
#906
#903

@timoxd7 timoxd7 force-pushed the android-buffering-workaround branch from bd70415 to ecea260 Compare April 2, 2025 10:35
Copy link

codecov bot commented Apr 2, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 5 lines in your changes missing coverage. Please review.

Project coverage is 44.74%. Comparing base (b0ccd83) to head (85cddc5).
Report is 14 commits behind head on master.

Files with missing lines Patch % Lines
lib/src/helpers/utils.dart 44.44% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #912      +/-   ##
==========================================
- Coverage   44.95%   44.74%   -0.22%     
==========================================
  Files          22       22              
  Lines        1546     1569      +23     
==========================================
+ Hits          695      702       +7     
- Misses        851      867      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@diegotori
Copy link
Collaborator

@timoxd7 can you add that additional workaround in the README so that it doesn't get lost after this version is eventually released? Thanks in advance.

@yann-elpyoo
Copy link

For information until the bug is fixed, and for chewie users only : it is possible to use a simple and complete workaround.

The thing is to add a long duration for the loader to appear. Then nothing is blocked anymore even at the end of the video! No need for looping too. It just shows the video paused and played each time seek to is called...

 _chewieController = ChewieController(
          videoPlayerController: _videoPlayerController,
          progressIndicatorDelay:
              PlatformProvider.isAndroid() ? const Duration(days: 1) : null,
        );

For non chewie users suffering from it, maybe wrapping with chewie could be a temporary solution...

@naghinezhad
Copy link

@timoxd7 @diegotori
Please review and merge this pull request so the related bug can be resolved. We are waiting for it.

@timoxd7
Copy link
Contributor Author

timoxd7 commented Apr 7, 2025

@naghinezhad i am a bit in two minds about this pr. I will incorporate the requested changes, but it still is not a complete fix.

I don't know if it works good with live streams. As @yann-elpyoo wrote, you could fix it by disabling indirectly the loading spinner for android, but this also removes the feedback to the user that something is buffering.

@diegotori i updated according to your review. I also tested @yann-elpyoo solution and added it to the readme, both work together too (as my workaround will just be hidden by disabling the loader anyway).

As maintainer you can decide wether to merge this, as the root problem is not relying in chewie itself. However, we now have it documented here at least and if someone needs a fix, can use it util it is fixed in flutter itself.

@timoxd7 timoxd7 requested a review from diegotori April 7, 2025 13:23
Copy link
Collaborator

@diegotori diegotori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the new utility method, add comments related to the issue your changes are trying to address.

Thanks.

@diegotori
Copy link
Collaborator

@timoxd7 other than the final nit that I called out, the rest LGTM.

@timoxd7 timoxd7 requested a review from diegotori April 8, 2025 08:23
Copy link
Collaborator

@diegotori diegotori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@diegotori diegotori merged commit 25a0d9d into fluttercommunity:master Apr 9, 2025
3 of 4 checks passed
diegotori added a commit that referenced this pull request Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants