Skip to content

Conversation

surelyruchi
Copy link
Contributor

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

@surelyruchi
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
Labels
None yet
Projects
None yet
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
2 participants