opt: 数据初始化

This commit is contained in:
guozhigq
2024-08-26 23:23:43 +08:00
parent f0cd9c5cf2
commit 2e329553d9
13 changed files with 137 additions and 99 deletions

View File

@ -18,6 +18,7 @@ import 'package:pilipala/plugin/pl_player/index.dart';
import 'package:pilipala/plugin/pl_player/models/play_repeat.dart';
import 'package:pilipala/services/service_locator.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/global_data_cache.dart';
import 'package:pilipala/utils/storage.dart';
import 'package:screen_brightness/screen_brightness.dart';
import 'package:status_bar_control/status_bar_control.dart';
@ -277,50 +278,19 @@ class PlPlayerController {
// 添加一个私有构造函数
PlPlayerController._internal(this.videoType) {
isOpenDanmu.value =
setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false);
blockTypes =
localCache.get(LocalCacheKey.danmakuBlockType, defaultValue: []);
showArea = localCache.get(LocalCacheKey.danmakuShowArea, defaultValue: 0.5);
// 不透明度
opacityVal =
localCache.get(LocalCacheKey.danmakuOpacity, defaultValue: 1.0);
// 字体大小
fontSizeVal =
localCache.get(LocalCacheKey.danmakuFontScale, defaultValue: 1.0);
// 弹幕时间
danmakuDurationVal =
localCache.get(LocalCacheKey.danmakuDuration, defaultValue: 4.0);
// 描边粗细
strokeWidth = localCache.get(LocalCacheKey.strokeWidth, defaultValue: 1.5);
playRepeat = PlayRepeat.values.toList().firstWhere(
(e) =>
e.value ==
videoStorage.get(VideoBoxKey.playRepeat,
defaultValue: PlayRepeat.pause.value),
);
_playbackSpeed.value =
videoStorage.get(VideoBoxKey.playSpeedDefault, defaultValue: 1.0);
enableAutoLongPressSpeed = setting
.get(SettingBoxKey.enableAutoLongPressSpeed, defaultValue: false);
if (!enableAutoLongPressSpeed) {
_longPressSpeed.value = videoStorage
.get(VideoBoxKey.longPressSpeedDefault, defaultValue: 2.0);
}
// 自定义倍速集合
speedsList = List<double>.from(videoStorage
.get(VideoBoxKey.customSpeedsList, defaultValue: <double>[]));
// 默认倍速
speedsList = List<double>.from(videoStorage
.get(VideoBoxKey.customSpeedsList, defaultValue: <double>[]));
//playSpeedSystem
final List<double> playSpeedSystem =
videoStorage.get(VideoBoxKey.playSpeedSystem, defaultValue: playSpeed);
// for (final PlaySpeed i in PlaySpeed.values) {
speedsList.addAll(playSpeedSystem);
// }
final cache = GlobalDataCache();
isOpenDanmu.value = cache.isOpenDanmu;
blockTypes = cache.blockTypes;
showArea = cache.showArea;
opacityVal = cache.opacityVal;
fontSizeVal = cache.fontSizeVal;
danmakuDurationVal = cache.danmakuDurationVal;
strokeWidth = cache.strokeWidth;
playRepeat = cache.playRepeat;
_playbackSpeed.value = cache.playbackSpeed;
enableAutoLongPressSpeed = cache.enableAutoLongPressSpeed;
_longPressSpeed.value = cache.longPressSpeed;
speedsList = cache.speedsList;
// _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) {
// if (status == PlayerStatus.playing) {
// WakelockPlus.enable();

View File

@ -19,7 +19,7 @@ import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/storage.dart';
import 'package:screen_brightness/screen_brightness.dart';
import '../../utils/global_data.dart';
import '../../utils/global_data_cache.dart';
import 'models/bottom_control_type.dart';
import 'models/bottom_progress_behavior.dart';
import 'widgets/app_bar_ani.dart';
@ -87,7 +87,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
late bool enableBackgroundPlay;
late double screenWidth;
final FullScreenGestureMode fullScreenGestureMode =
GlobalData().fullScreenGestureMode;
GlobalDataCache().fullScreenGestureMode;
// 用于记录上一次全屏切换手势触发时间,避免误触
DateTime? lastFullScreenToggleTime;
@ -132,7 +132,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
screenWidth = Get.size.width;
animationController = AnimationController(
vsync: this,
duration: GlobalData().enablePlayerControlAnimation
duration: GlobalDataCache().enablePlayerControlAnimation
? const Duration(milliseconds: 150)
: const Duration(milliseconds: 10),
);