mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-08 12:04:50 +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;
|
bool _pauseDueToPauseUponEnteringBackgroundMode = false;
|
||||||
|
|
||||||
StreamSubscription? _brightnessListener;
|
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;
|
int? tmpSubtitlePaddingB;
|
||||||
StreamSubscription? _controlsListener;
|
StreamSubscription? _controlsListener;
|
||||||
@@ -198,43 +238,22 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
videoController = plPlayerController.videoController!;
|
videoController = plPlayerController.videoController!;
|
||||||
|
|
||||||
if (PlatformUtils.isMobile) {
|
if (PlatformUtils.isMobile) {
|
||||||
Future.microtask(() async {
|
Future.microtask(() {
|
||||||
try {
|
try {
|
||||||
FlutterVolumeController.updateShowSystemUI(true);
|
FlutterVolumeController.updateShowSystemUI(true);
|
||||||
plPlayerController.volume.value =
|
_getCurrVolume();
|
||||||
(await FlutterVolumeController.getVolume())!;
|
FlutterVolumeController.addListener(
|
||||||
FlutterVolumeController.addListener((double value) {
|
_onVolumeChanged,
|
||||||
if (mounted && !plPlayerController.volumeInterceptEventStream) {
|
emitOnStart: false,
|
||||||
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);
|
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
});
|
|
||||||
|
|
||||||
Future.microtask(() async {
|
|
||||||
try {
|
try {
|
||||||
void listener(double value) {
|
_getCurrBrightness();
|
||||||
if (mounted) {
|
|
||||||
_brightnessValue.value = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_brightnessValue.value =
|
|
||||||
await ScreenBrightnessPlatform.instance.system;
|
|
||||||
_brightnessListener = ScreenBrightnessPlatform
|
_brightnessListener = ScreenBrightnessPlatform
|
||||||
.instance
|
.instance
|
||||||
.onSystemScreenBrightnessChanged
|
.onSystemScreenBrightnessChanged
|
||||||
.listen(listener);
|
.listen(_onBrightnessChanged);
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -274,6 +293,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setBrightness(double value) async {
|
Future<void> setBrightness(double value) async {
|
||||||
|
_brightnessValue.value = value;
|
||||||
try {
|
try {
|
||||||
await ScreenBrightnessPlatform.instance.setSystemScreenBrightness(
|
await ScreenBrightnessPlatform.instance.setSystemScreenBrightness(
|
||||||
value,
|
value,
|
||||||
|
|||||||
Reference in New Issue
Block a user