Ver Fonte

keep screen alive when video is playing

ashilkn há 2 anos atrás
pai
commit
b8594d20d5
2 ficheiros alterados com 20 adições e 1 exclusões
  1. 19 0
      lib/ui/viewer/file/detail_page.dart
  2. 1 1
      pubspec.lock

+ 19 - 0
lib/ui/viewer/file/detail_page.dart

@@ -16,6 +16,7 @@ import 'package:photos/ui/viewer/gallery/gallery.dart';
 import 'package:photos/utils/dialog_util.dart';
 import 'package:photos/utils/file_util.dart';
 import 'package:photos/utils/navigation_util.dart';
+import 'package:wakelock/wakelock.dart';
 
 enum DetailPageMode {
   minimalistic,
@@ -154,6 +155,7 @@ class _DetailPageState extends State<DetailPage> {
           },
           playbackCallback: (isPlaying) {
             _shouldHideAppBar = isPlaying;
+            _keepScreenAliveOnPlaying(isPlaying);
             Future.delayed(Duration.zero, () {
               _toggleFullScreen();
             });
@@ -251,6 +253,23 @@ class _DetailPageState extends State<DetailPage> {
     }
   }
 
+  void _keepScreenAliveOnPlaying(bool isPlaying) {
+    bool wakeLockEnabledHere = false;
+    if (isPlaying) {
+      Wakelock.enabled.then((value) {
+        if (value == false) {
+          Wakelock.enable();
+          wakeLockEnabledHere = true;
+          //wakeLockEnabledHere will not be set to true if wakeLock is already enabled from settings on iOS.
+          //We shouldn't disable when video is not playing if it was enabled manually by the user from ente settings by user.
+        }
+      });
+    }
+    if (wakeLockEnabledHere && !isPlaying) {
+      Wakelock.disable();
+    }
+  }
+
   Future<void> _onFileDeleted(File file) async {
     final totalFiles = _files.length;
     if (totalFiles == 1) {

+ 1 - 1
pubspec.lock

@@ -911,7 +911,7 @@ packages:
       name: photo_manager
       url: "https://pub.dartlang.org"
     source: hosted
-    version: "2.1.1"
+    version: "2.3.0"
   photo_view:
     dependency: "direct main"
     description: