@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:os_media_controls/os_media_controls.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
|
||||
import '../mpv/mpv.dart';
|
||||
|
||||
@@ -180,13 +181,18 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen>
|
||||
// Clear media controls when app truly goes to background
|
||||
// (we don't support background playback)
|
||||
OsMediaControls.clear();
|
||||
// Disable wakelock when app goes to background
|
||||
WakelockPlus.disable();
|
||||
appLogger.d(
|
||||
'Media controls cleared due to app being paused/backgrounded',
|
||||
'Media controls cleared and wakelock disabled due to app being paused/backgrounded',
|
||||
);
|
||||
break;
|
||||
case AppLifecycleState.resumed:
|
||||
// Restore media controls when app is resumed
|
||||
// Restore media controls and wakelock when app is resumed
|
||||
if (_isPlayerInitialized && mounted) {
|
||||
// Re-enable wakelock since we're back in the video player
|
||||
WakelockPlus.enable();
|
||||
|
||||
// Restore media metadata
|
||||
final client = _getClientForMetadata(context);
|
||||
if (_mediaControlsManager != null) {
|
||||
@@ -207,7 +213,7 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen>
|
||||
}
|
||||
|
||||
_updateMediaControlsPlaybackState();
|
||||
appLogger.d('Media controls restored on app resume');
|
||||
appLogger.d('Media controls restored and wakelock re-enabled on app resume');
|
||||
}
|
||||
break;
|
||||
case AppLifecycleState.detached:
|
||||
@@ -330,6 +336,10 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen>
|
||||
setState(() {
|
||||
_isPlayerInitialized = true;
|
||||
});
|
||||
|
||||
// Enable wakelock to prevent screen from turning off during playback
|
||||
WakelockPlus.enable();
|
||||
appLogger.d('Wakelock enabled for video playback');
|
||||
}
|
||||
|
||||
// Get the video URL and start playback
|
||||
@@ -751,6 +761,10 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen>
|
||||
_mediaControlsManager?.clear();
|
||||
_mediaControlsManager?.dispose();
|
||||
|
||||
// Disable wakelock when leaving the video player
|
||||
WakelockPlus.disable();
|
||||
appLogger.d('Wakelock disabled');
|
||||
|
||||
// Restore system UI and orientation preferences (skip if navigating to another video)
|
||||
if (!_isReplacingWithVideo) {
|
||||
OrientationHelper.restoreSystemUI();
|
||||
|
||||
@@ -1302,6 +1302,22 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "15.0.2"
|
||||
wakelock_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: wakelock_plus
|
||||
sha256: "9296d40c9adbedaba95d1e704f4e0b434be446e2792948d0e4aa977048104228"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.4.0"
|
||||
wakelock_plus_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: wakelock_plus_platform_interface
|
||||
sha256: "036deb14cd62f558ca3b73006d52ce049fabcdcb2eddfe0bf0fe4e8a943b5cf2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
watcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -33,6 +33,7 @@ dependencies:
|
||||
url: https://github.com/edde746/os-media-controls
|
||||
ref: 75dc5642cd148c54c03fe96976702b8d31c48599
|
||||
rate_limiter: ^1.0.0
|
||||
wakelock_plus: ^1.2.10
|
||||
path_provider: ^2.1.0
|
||||
path: ^1.9.0
|
||||
gamepads: ^0.1.9
|
||||
|
||||
Reference in New Issue
Block a user