Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: pause video playback on screen change using VisibilityDetector #868

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

Open
surelyruchi wants to merge 1 commit into foss42:main
base: main
Choose a base branch
Loading
from surelyruchi:fix/video-player-background-play

Conversation

@surelyruchi
Copy link
Contributor

@surelyruchi surelyruchi commented Jul 25, 2025

PR Description

This PR fixes the issue where the video player continued playing in the background even after navigating away from the screen.

🛠️ How It’s Fixed

  • Integrated VisibilityDetector to monitor the visibility of the video widget.
  • When the widget is no longer visible (i.e. screen changes), the video playback is paused.

🎯 Why This Approach

  • VisibilityDetector is a lightweight and effective way to track widget visibility without relying on screen lifecycle events.
  • It avoids unnecessary resource usage and ensures a cleaner user experience.

Related Issues

Checklist

  • I have gone through the contributing guide
  • I have updated my branch and synced it with project main branch before making this PR
  • I am using the latest Flutter stable branch (run flutter upgrade and verify)
  • I have run the tests (flutter test) and all tests are passing

Added/updated tests?

  • Yes
  • No, and this is why: it's been manually tested, and we can consider writing a test later if needed based on feedback.

OS on which you have developed and tested the feature?

  • Windows
  • macOS
  • Linux

Copy link
Contributor Author

Hey @ashitaprasad @animator
Let me know your reviews on this.
Just a few things I wanted to mention about this PR :

  • I removed _videoController.play() from initState to avoid auto-playing if the user navigates away while the request is still in process, and the play will be handled by the Visibility Detector.
  • Handled manual pause case using the existing _isPlaying variable to ensure the video doesn't auto-play again if the user paused it intentionally.
  • Auto-play resumes only when visibility ≥ 50% and the user hasn’t manually paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@sudhar08 sudhar08 sudhar08 approved these changes

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Switching to a different screen does not stop the background tasks from the previous screen

AltStyle によって変換されたページ (->オリジナル) /