apidash icon indicating copy to clipboard operation
apidash copied to clipboard

fix: pause video playback on screen change using VisibilityDetector

Open surelyruchi opened this issue 5 months ago • 1 comments

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

  • Closes #848

Checklist

  • [x] I have gone through the contributing guide
  • [x] I have updated my branch and synced it with project main branch before making this PR
  • [x] 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
  • [x] 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?

  • [x] Windows
  • [ ] macOS
  • [ ] Linux

surelyruchi avatar Jul 25 '25 08:07 surelyruchi

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

  • [x] 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.
  • [x] Handled manual pause case using the existing _isPlaying variable to ensure the video doesn't auto-play again if the user paused it intentionally.
  • [x] Auto-play resumes only when visibility ≥ 50% and the user hasn’t manually paused.

surelyruchi avatar Jul 25 '25 18:07 surelyruchi