Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix(video-player): Video auto plays in bg when app is put in bg after downloading starts

ashilkn0f70196e1c47
diff --git a/lib/ui/viewer/file/video_widget_new.dart b/lib/ui/viewer/file/video_widget_new.dart
index be6d617298..35ef62f5fc 100644
--- a/lib/ui/viewer/file/video_widget_new.dart
+++ b/lib/ui/viewer/file/video_widget_new.dart
@@ -32,16 +32,19 @@ class VideoWidgetNew extends StatefulWidget {
State<VideoWidgetNew> createState() => _VideoWidgetNewState();
}
-class _VideoWidgetNewState extends State<VideoWidgetNew> {
+class _VideoWidgetNewState extends State<VideoWidgetNew>
+ with WidgetsBindingObserver {
static const verticalMargin = 72.0;
late final player = Player();
VideoController? controller;
final _progressNotifier = ValueNotifier<double?>(null);
late StreamSubscription<bool> playingStreamSubscription;
+ bool _isAppInFG = true;
@override
void initState() {
super.initState();
+ WidgetsBinding.instance.addObserver(this);
if (widget.file.isRemoteFile) {
_loadNetworkVideo();
_setFileSizeIfNull();
@@ -75,8 +78,18 @@ class _VideoWidgetNewState extends State<VideoWidgetNew> {
});
}
+ @override
+ void didChangeAppLifecycleState(AppLifecycleState state) {
+ if (state == AppLifecycleState.resumed) {
+ _isAppInFG = true;
+ } else {
+ _isAppInFG = false;
+ }
+ }
+
@override
void dispose() {
+ WidgetsBinding.instance.removeObserver(this);
playingStreamSubscription.cancel();
player.dispose();
_progressNotifier.dispose();
@@ -215,7 +228,7 @@ class _VideoWidgetNewState extends State<VideoWidgetNew> {
if (mounted) {
setState(() {
controller = VideoController(player);
- player.open(Media(url));
+ player.open(Media(url), play: _isAppInFG);
});
}
}