set system brightness

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-11-09 11:44:04 +08:00
parent 1291dc77c8
commit 13c220338c
9 changed files with 47 additions and 16 deletions

View File

@@ -210,4 +210,5 @@
--> -->
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" /> <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" /> <uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
</manifest> </manifest>

View File

@@ -143,7 +143,7 @@ class _LiveRoomPageState extends State<LiveRoomPage>
void dispose() { void dispose() {
videoPlayerServiceHandler?.onVideoDetailDispose(heroTag); videoPlayerServiceHandler?.onVideoDetailDispose(heroTag);
WidgetsBinding.instance.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
if (Utils.isMobile) { if (Platform.isAndroid && !plPlayerController.setSystemBrightness) {
ScreenBrightnessPlatform.instance.resetApplicationScreenBrightness(); ScreenBrightnessPlatform.instance.resetApplicationScreenBrightness();
} }
PlPlayerController.setPlayCallBack(null); PlPlayerController.setPlayCallBack(null);

View File

@@ -82,6 +82,14 @@ List<SettingsModel> get playSettings => [
setKey: SettingBoxKey.enableSlideVolumeBrightness, setKey: SettingBoxKey.enableSlideVolumeBrightness,
defaultVal: true, defaultVal: true,
), ),
if (Platform.isAndroid)
const SettingsModel(
settingsType: SettingsType.sw1tch,
title: '调节系统亮度',
leading: Icon(Icons.brightness_6_outlined),
setKey: SettingBoxKey.setSystemBrightness,
defaultVal: false,
),
const SettingsModel( const SettingsModel(
settingsType: SettingsType.sw1tch, settingsType: SettingsType.sw1tch,
title: '中间滑动进入/退出全屏', title: '中间滑动进入/退出全屏',

View File

@@ -110,6 +110,7 @@ class VideoDetailController extends GetxController
PlPlayerController plPlayerController = PlPlayerController.getInstance() PlPlayerController plPlayerController = PlPlayerController.getInstance()
..setCurrBrightness(-1.0); ..setCurrBrightness(-1.0);
bool get setSystemBrightness => plPlayerController.setSystemBrightness;
late VideoItem firstVideo; late VideoItem firstVideo;
late AudioItem firstAudio; late AudioItem firstAudio;

View File

@@ -326,7 +326,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
); );
if (!Get.previousRoute.startsWith('/video')) { if (!Get.previousRoute.startsWith('/video')) {
if (Utils.isMobile) { if (Platform.isAndroid && !videoDetailController.setSystemBrightness) {
ScreenBrightnessPlatform.instance.resetApplicationScreenBrightness(); ScreenBrightnessPlatform.instance.resetApplicationScreenBrightness();
} }
PlPlayerController.setPlayCallBack(null); PlPlayerController.setPlayCallBack(null);
@@ -371,7 +371,7 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
WidgetsBinding.instance.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
if (Utils.isMobile) { if (Platform.isAndroid && !videoDetailController.setSystemBrightness) {
ScreenBrightnessPlatform.instance.resetApplicationScreenBrightness(); ScreenBrightnessPlatform.instance.resetApplicationScreenBrightness();
} }
@@ -418,7 +418,9 @@ class _VideoDetailPageVState extends State<VideoDetailPageV>
introController.startTimer(); introController.startTimer();
if (Utils.isMobile && mounted) { if (mounted &&
Platform.isAndroid &&
!videoDetailController.setSystemBrightness) {
if (videoDetailController.brightness != null) { if (videoDetailController.brightness != null) {
plPlayerController?.setCurrBrightness( plPlayerController?.setCurrBrightness(
videoDetailController.brightness!, videoDetailController.brightness!,

View File

@@ -98,6 +98,7 @@ class PlPlayerController {
final RxDouble _currentVolume = RxDouble( final RxDouble _currentVolume = RxDouble(
Utils.isDesktop ? Pref.desktopVolume : 1.0, Utils.isDesktop ? Pref.desktopVolume : 1.0,
); );
final setSystemBrightness = Pref.setSystemBrightness;
final RxDouble _currentBrightness = (-1.0).obs; final RxDouble _currentBrightness = (-1.0).obs;
final RxBool _showControls = false.obs; final RxBool _showControls = false.obs;

View File

@@ -204,14 +204,22 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
try { try {
_brightnessValue.value = _brightnessValue.value =
await ScreenBrightnessPlatform.instance.application; await ScreenBrightnessPlatform.instance.application;
_listener = ScreenBrightnessPlatform
.instance void listener(double value) {
.onApplicationScreenBrightnessChanged if (mounted) {
.listen((double value) { _brightnessValue.value = value;
if (mounted) { }
_brightnessValue.value = value; }
}
}); _listener = Platform.isIOS || plPlayerController.setSystemBrightness
? ScreenBrightnessPlatform
.instance
.onSystemScreenBrightnessChanged
.listen(listener)
: ScreenBrightnessPlatform
.instance
.onApplicationScreenBrightnessChanged
.listen(listener);
} catch (_) {} } catch (_) {}
}); });
} }
@@ -264,9 +272,15 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
Future<void> setBrightness(double value) async { Future<void> setBrightness(double value) async {
try { try {
await ScreenBrightnessPlatform.instance.setApplicationScreenBrightness( if (Platform.isIOS || plPlayerController.setSystemBrightness) {
value, await ScreenBrightnessPlatform.instance.setSystemScreenBrightness(
); value,
);
} else {
await ScreenBrightnessPlatform.instance.setApplicationScreenBrightness(
value,
);
}
} catch (_) {} } catch (_) {}
_brightnessIndicator.value = true; _brightnessIndicator.value = true;
_brightnessTimer?.cancel(); _brightnessTimer?.cancel();

View File

@@ -142,7 +142,8 @@ abstract class SettingBoxKey {
silentDownImg = 'silentDownImg', silentDownImg = 'silentDownImg',
showMemberShop = 'showMemberShop', showMemberShop = 'showMemberShop',
enablePlayAll = 'enablePlayAll', enablePlayAll = 'enablePlayAll',
enableTapDm = 'enableTapDm'; enableTapDm = 'enableTapDm',
setSystemBrightness = 'setSystemBrightness';
static const String minimizeOnExit = 'minimizeOnExit', static const String minimizeOnExit = 'minimizeOnExit',
windowSize = 'windowSize', windowSize = 'windowSize',

View File

@@ -865,4 +865,7 @@ abstract class Pref {
static bool get showTrayIcon => static bool get showTrayIcon =>
_setting.get(SettingBoxKey.showTrayIcon, defaultValue: true); _setting.get(SettingBoxKey.showTrayIcon, defaultValue: true);
static bool get setSystemBrightness =>
_setting.get(SettingBoxKey.setSystemBrightness, defaultValue: false);
} }