mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-08 03:54:49 +08:00
opt handle brightness/volume
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -131,6 +131,46 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
bool _pauseDueToPauseUponEnteringBackgroundMode = false;
|
||||
|
||||
StreamSubscription? _brightnessListener;
|
||||
void _onBrightnessChanged(double value) {
|
||||
if (mounted && _gestureType != .left) {
|
||||
_brightnessValue.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
void _getCurrBrightness() {
|
||||
ScreenBrightnessPlatform.instance.system.then((res) {
|
||||
if (mounted) {
|
||||
_brightnessValue.value = res;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _onVolumeChanged(double value) {
|
||||
if (mounted && !plPlayerController.volumeInterceptEventStream) {
|
||||
plPlayerController.volume.value = value;
|
||||
if (Platform.isIOS && !FlutterVolumeController.showSystemUI) {
|
||||
plPlayerController
|
||||
..volumeIndicator.value = true
|
||||
..volumeTimer?.cancel()
|
||||
..volumeTimer = Timer(
|
||||
const Duration(milliseconds: 800),
|
||||
() {
|
||||
if (mounted) {
|
||||
plPlayerController.volumeIndicator.value = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _getCurrVolume() {
|
||||
FlutterVolumeController.getVolume().then((res) {
|
||||
if (mounted) {
|
||||
plPlayerController.volume.value = res!;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
int? tmpSubtitlePaddingB;
|
||||
StreamSubscription? _controlsListener;
|
||||
@@ -198,43 +238,22 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
videoController = plPlayerController.videoController!;
|
||||
|
||||
if (PlatformUtils.isMobile) {
|
||||
Future.microtask(() async {
|
||||
Future.microtask(() {
|
||||
try {
|
||||
FlutterVolumeController.updateShowSystemUI(true);
|
||||
plPlayerController.volume.value =
|
||||
(await FlutterVolumeController.getVolume())!;
|
||||
FlutterVolumeController.addListener((double value) {
|
||||
if (mounted && !plPlayerController.volumeInterceptEventStream) {
|
||||
plPlayerController.volume.value = value;
|
||||
if (Platform.isIOS && !FlutterVolumeController.showSystemUI) {
|
||||
plPlayerController
|
||||
..volumeIndicator.value = true
|
||||
..volumeTimer?.cancel()
|
||||
..volumeTimer = Timer(const Duration(milliseconds: 800), () {
|
||||
if (mounted) {
|
||||
plPlayerController.volumeIndicator.value = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, emitOnStart: false);
|
||||
_getCurrVolume();
|
||||
FlutterVolumeController.addListener(
|
||||
_onVolumeChanged,
|
||||
emitOnStart: false,
|
||||
);
|
||||
} catch (_) {}
|
||||
});
|
||||
|
||||
Future.microtask(() async {
|
||||
try {
|
||||
void listener(double value) {
|
||||
if (mounted) {
|
||||
_brightnessValue.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
_brightnessValue.value =
|
||||
await ScreenBrightnessPlatform.instance.system;
|
||||
_getCurrBrightness();
|
||||
_brightnessListener = ScreenBrightnessPlatform
|
||||
.instance
|
||||
.onSystemScreenBrightnessChanged
|
||||
.listen(listener);
|
||||
.listen(_onBrightnessChanged);
|
||||
} catch (_) {}
|
||||
});
|
||||
}
|
||||
@@ -274,6 +293,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
}
|
||||
|
||||
Future<void> setBrightness(double value) async {
|
||||
_brightnessValue.value = value;
|
||||
try {
|
||||
await ScreenBrightnessPlatform.instance.setSystemScreenBrightness(
|
||||
value,
|
||||
|
||||
Reference in New Issue
Block a user