feat: 播放器亮度记忆
This commit is contained in:
@ -72,6 +72,12 @@ class _PlaySettingState extends State<PlaySetting> {
|
|||||||
setKey: SettingBoxKey.enableOnlineTotal,
|
setKey: SettingBoxKey.enableOnlineTotal,
|
||||||
defaultVal: false,
|
defaultVal: false,
|
||||||
),
|
),
|
||||||
|
const SetSwitchItem(
|
||||||
|
title: '亮度记忆',
|
||||||
|
subTitle: '返回时自动调整视频亮度',
|
||||||
|
setKey: SettingBoxKey.enableAutoBrightness,
|
||||||
|
defaultVal: false,
|
||||||
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
dense: false,
|
dense: false,
|
||||||
title: Text('默认画质', style: titleStyle),
|
title: Text('默认画质', style: titleStyle),
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import 'package:pilipala/pages/video/detail/replyReply/index.dart';
|
|||||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
import 'package:pilipala/utils/utils.dart';
|
import 'package:pilipala/utils/utils.dart';
|
||||||
|
import 'package:screen_brightness/screen_brightness.dart';
|
||||||
|
|
||||||
class VideoDetailController extends GetxController
|
class VideoDetailController extends GetxController
|
||||||
with GetSingleTickerProviderStateMixin {
|
with GetSingleTickerProviderStateMixin {
|
||||||
@ -68,6 +69,8 @@ class VideoDetailController extends GetxController
|
|||||||
late String videoUrl;
|
late String videoUrl;
|
||||||
late String audioUrl;
|
late String audioUrl;
|
||||||
late Duration defaultST;
|
late Duration defaultST;
|
||||||
|
// 亮度
|
||||||
|
double? brightness;
|
||||||
// 默认记录历史记录
|
// 默认记录历史记录
|
||||||
bool enableHeart = true;
|
bool enableHeart = true;
|
||||||
var userInfo;
|
var userInfo;
|
||||||
@ -152,6 +155,12 @@ class VideoDetailController extends GetxController
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future playerInit({video, audio, seekToTime, duration}) async {
|
Future playerInit({video, audio, seekToTime, duration}) async {
|
||||||
|
/// 设置/恢复 屏幕亮度
|
||||||
|
if (brightness != null) {
|
||||||
|
ScreenBrightness().setScreenBrightness(brightness!);
|
||||||
|
} else {
|
||||||
|
ScreenBrightness().resetScreenBrightness();
|
||||||
|
}
|
||||||
await plPlayerController.setDataSource(
|
await plPlayerController.setDataSource(
|
||||||
DataSource(
|
DataSource(
|
||||||
videoSource: video ?? videoUrl,
|
videoSource: video ?? videoUrl,
|
||||||
|
|||||||
@ -45,6 +45,7 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
double doubleOffset = 0;
|
double doubleOffset = 0;
|
||||||
|
|
||||||
Box localCache = GStrorage.localCache;
|
Box localCache = GStrorage.localCache;
|
||||||
|
Box setting = GStrorage.setting;
|
||||||
late double statusBarHeight;
|
late double statusBarHeight;
|
||||||
final videoHeight = Get.size.width * 9 / 16;
|
final videoHeight = Get.size.width * 9 / 16;
|
||||||
late Future _futureBuilderFuture;
|
late Future _futureBuilderFuture;
|
||||||
@ -104,6 +105,10 @@ class _VideoDetailPageState extends State<VideoDetailPage>
|
|||||||
@override
|
@override
|
||||||
// 离开当前页面时
|
// 离开当前页面时
|
||||||
void didPushNext() async {
|
void didPushNext() async {
|
||||||
|
/// 开启
|
||||||
|
if (setting.get(SettingBoxKey.enableAutoBrightness, defaultValue: false)) {
|
||||||
|
videoDetailController.brightness = plPlayerController!.brightness.value;
|
||||||
|
}
|
||||||
videoDetailController.defaultST = plPlayerController!.position.value;
|
videoDetailController.defaultST = plPlayerController!.position.value;
|
||||||
videoIntroController.isPaused = true;
|
videoIntroController.isPaused = true;
|
||||||
plPlayerController!.pause();
|
plPlayerController!.pause();
|
||||||
|
|||||||
@ -619,7 +619,7 @@ class PlPlayerController {
|
|||||||
try {
|
try {
|
||||||
brightness.value = brightnes;
|
brightness.value = brightnes;
|
||||||
ScreenBrightness().setScreenBrightness(brightnes);
|
ScreenBrightness().setScreenBrightness(brightnes);
|
||||||
setVideoBrightness();
|
// setVideoBrightness();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw 'Failed to set brightness';
|
throw 'Failed to set brightness';
|
||||||
}
|
}
|
||||||
@ -662,27 +662,24 @@ class PlPlayerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 缓存fit
|
/// 缓存fit
|
||||||
Future<void> setVideoFit() async {
|
// Future<void> setVideoFit() async {
|
||||||
videoStorage.put(VideoBoxKey.videoBrightness, _videoFit.value.name);
|
// videoStorage.put(VideoBoxKey.videoBrightness, _videoFit.value.name);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// 读取fit
|
/// 读取fit
|
||||||
Future<void> getVideoFit() async {
|
// Future<void> getVideoFit() async {
|
||||||
String fitValue =
|
// String fitValue =
|
||||||
videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 'contain');
|
// videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 'contain');
|
||||||
_videoFit.value = videoFitType
|
// _videoFit.value = videoFitType
|
||||||
.firstWhere((element) => element['attr'] == fitValue)['attr'];
|
// .firstWhere((element) => element['attr'] == fitValue)['attr'];
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// 缓存亮度
|
|
||||||
Future<void> setVideoBrightness() async {}
|
|
||||||
|
|
||||||
/// 读取亮度
|
/// 读取亮度
|
||||||
Future<void> getVideoBrightness() async {
|
// Future<void> getVideoBrightness() async {
|
||||||
double brightnessValue =
|
// double brightnessValue =
|
||||||
videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 0.5);
|
// videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 0.5);
|
||||||
setBrightness(brightnessValue);
|
// setBrightness(brightnessValue);
|
||||||
}
|
// }
|
||||||
|
|
||||||
set controls(bool visible) {
|
set controls(bool visible) {
|
||||||
_showControls.value = visible;
|
_showControls.value = visible;
|
||||||
@ -791,6 +788,8 @@ class PlPlayerController {
|
|||||||
await _videoPlayerController?.dispose();
|
await _videoPlayerController?.dispose();
|
||||||
_videoPlayerController = null;
|
_videoPlayerController = null;
|
||||||
_instance = null;
|
_instance = null;
|
||||||
|
// 关闭所有视频页面恢复亮度
|
||||||
|
resetBrightness();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
print(err);
|
print(err);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -156,6 +156,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
widget.controller.brightness.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> triggerFullScreen() async {
|
Future<void> triggerFullScreen() async {
|
||||||
|
|||||||
@ -96,6 +96,7 @@ class SettingBoxKey {
|
|||||||
static const String defaultPicQa = 'defaultPicQa';
|
static const String defaultPicQa = 'defaultPicQa';
|
||||||
static const String enableHA = 'enableHA';
|
static const String enableHA = 'enableHA';
|
||||||
static const String enableOnlineTotal = 'enableOnlineTotal';
|
static const String enableOnlineTotal = 'enableOnlineTotal';
|
||||||
|
static const String enableAutoBrightness = 'enableAutoBrightness';
|
||||||
|
|
||||||
/// 隐私
|
/// 隐私
|
||||||
static const String blackMidsList = 'blackMidsList';
|
static const String blackMidsList = 'blackMidsList';
|
||||||
|
|||||||
Reference in New Issue
Block a user