From 48c7dc0eedf51b43676ba0e06e4ecac81268396f Mon Sep 17 00:00:00 2001 From: dom Date: Thu, 29 Jan 2026 17:42:25 +0800 Subject: [PATCH] custom autosync Signed-off-by: dom --- lib/pages/setting/models/video_settings.dart | 49 +++++++++++++++++++- lib/plugin/pl_player/controller.dart | 2 +- lib/utils/storage_key.dart | 1 + lib/utils/storage_pref.dart | 3 ++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/pages/setting/models/video_settings.dart b/lib/pages/setting/models/video_settings.dart index 7e761e65f..138dadcd1 100644 --- a/lib/pages/setting/models/video_settings.dart +++ b/lib/pages/setting/models/video_settings.dart @@ -16,6 +16,8 @@ import 'package:PiliPlus/utils/storage_pref.dart'; import 'package:PiliPlus/utils/video_utils.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart' show FilteringTextInputFormatter; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; @@ -149,7 +151,12 @@ List get videoSettings => [ setKey: SettingBoxKey.expandBuffer, defaultVal: false, ), - //video-sync + NormalModel( + title: '自动同步', + leading: const Icon(Icons.sync_rounded), + getSubtitle: () => '当前:${Pref.autosync}(此项即mpv的--autosync)', + onTap: _showAutoSyncDialog, + ), NormalModel( title: '视频同步', leading: const Icon(Icons.view_timeline_outlined), @@ -447,3 +454,43 @@ Future _showHwDecDialog( setState(); } } + +void _showAutoSyncDialog(BuildContext context, VoidCallback setState) { + String autosync = Pref.autosync.toString(); + showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('自动同步'), + content: TextFormField( + autofocus: true, + initialValue: autosync, + keyboardType: TextInputType.number, + onChanged: (value) => autosync = value, + inputFormatters: [FilteringTextInputFormatter.digitsOnly], + ), + actions: [ + TextButton( + onPressed: Get.back, + child: Text( + '取消', + style: TextStyle(color: ColorScheme.of(context).outline), + ), + ), + TextButton( + onPressed: () async { + try { + // validate + int.parse(autosync); + Get.back(); + await GStorage.setting.put(SettingBoxKey.autosync, autosync); + setState(); + } catch (e) { + SmartDialog.showToast(e.toString()); + } + }, + child: const Text('确定'), + ), + ], + ), + ); +} diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 6c99fa3c5..ac8417aa0 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -800,7 +800,7 @@ class PlPlayerController { } // video-sync=display-resample await pp.setProperty("video-sync", Pref.videoSync); - await pp.setProperty("autosync", "30"); + await pp.setProperty("autosync", Pref.autosync); // vo=gpu-next & gpu-context=android & gpu-api=opengl // await pp.setProperty("vo", "gpu-next"); // await pp.setProperty("gpu-context", "android"); diff --git a/lib/utils/storage_key.dart b/lib/utils/storage_key.dart index ccf2fafc7..fa3d77c03 100644 --- a/lib/utils/storage_key.dart +++ b/lib/utils/storage_key.dart @@ -17,6 +17,7 @@ abstract final class SettingBoxKey { expandBuffer = 'expandBuffer', hardwareDecoding = 'hardwareDecoding', videoSync = 'videoSync', + autosync = 'autosync', p1080 = 'p1080', enableAutoEnter = 'enableAutoEnter', enableAutoExit = 'enableAutoExit', diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index fa8d90868..e3bf08422 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -252,6 +252,9 @@ abstract final class Pref { static String get videoSync => _setting.get(SettingBoxKey.videoSync, defaultValue: 'display-resample'); + static String get autosync => + _setting.get(SettingBoxKey.autosync, defaultValue: '30'); + static CDNService get defaultCDNService { if (_setting.get(SettingBoxKey.CDNService) case final String cdnName) { return CDNService.values.byName(cdnName);