mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-08-05 10:10:14 +08:00
feat: custom buffer size (#2370)
* feat: custom buffer size * cache buffer params --------- Co-authored-by: dom <githubaccount56556@proton.me>
This commit is contained in:
committed by
GitHub
parent
90d79b236f
commit
22f37074b1
@@ -10,6 +10,7 @@ import 'package:PiliPlus/pages/setting/widgets/ordered_multi_select_dialog.dart'
|
||||
import 'package:PiliPlus/pages/setting/widgets/select_dialog.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/audio_output_type.dart';
|
||||
import 'package:PiliPlus/plugin/pl_player/models/hwdec_type.dart';
|
||||
import 'package:PiliPlus/utils/filtering_text.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:PiliPlus/utils/storage_key.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
@@ -144,12 +145,19 @@ List<SettingsModel> get videoSettings => [
|
||||
getSubtitle: () => '当前:${Pref.audioOutput}',
|
||||
onTap: _showAudioOutputDialog,
|
||||
),
|
||||
const SwitchModel(
|
||||
title: '扩大缓冲区',
|
||||
leading: Icon(Icons.storage_outlined),
|
||||
subtitle: '默认缓冲区为视频4MB/直播16MB,开启后为32MB/64MB,加载时间变长',
|
||||
setKey: SettingBoxKey.expandBuffer,
|
||||
defaultVal: false,
|
||||
NormalModel(
|
||||
title: '缓冲大小',
|
||||
leading: const Icon(Icons.storage_outlined),
|
||||
getSubtitle: () =>
|
||||
'当前:${Pref.bufferSize}MB。同时为前向和后向缓冲区大小。对于直播流,无后向缓冲大小,全部转给前向(此选项即mpv的--demuxer-max-bytes,--demuxer-max-back-bytes)',
|
||||
onTap: _showBufferSizeDialog,
|
||||
),
|
||||
NormalModel(
|
||||
title: '缓冲时长',
|
||||
leading: const Icon(Icons.av_timer),
|
||||
getSubtitle: () =>
|
||||
'当前:${Pref.bufferSec}s。实际缓冲为二者最小值。对于直播流,该选项无效(此选项即mpv的--cache-secs)',
|
||||
onTap: _showBufferSecDialog,
|
||||
),
|
||||
NormalModel(
|
||||
title: '自动同步',
|
||||
@@ -494,3 +502,70 @@ void _showAutoSyncDialog(BuildContext context, VoidCallback setState) {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDecimalDialog(
|
||||
BuildContext context,
|
||||
VoidCallback setState, {
|
||||
required String key,
|
||||
required double defVal,
|
||||
required String title,
|
||||
required String? suffix,
|
||||
}) {
|
||||
String value = (GStorage.setting.get(key) ?? defVal).toString();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(title),
|
||||
content: TextFormField(
|
||||
autofocus: true,
|
||||
initialValue: value,
|
||||
keyboardType: const .numberWithOptions(decimal: true),
|
||||
onChanged: (val) => value = val,
|
||||
inputFormatters: FilteringText.decimal,
|
||||
decoration: suffix == null ? null : InputDecoration(suffixText: suffix),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Get.back,
|
||||
child: Text(
|
||||
'取消',
|
||||
style: TextStyle(color: ColorScheme.of(context).outline),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
try {
|
||||
final val = double.parse(value);
|
||||
Get.back();
|
||||
await GStorage.setting.put(key, val);
|
||||
setState();
|
||||
} catch (e) {
|
||||
SmartDialog.showToast(e.toString());
|
||||
}
|
||||
},
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showBufferSizeDialog(BuildContext context, VoidCallback setState) =>
|
||||
_showDecimalDialog(
|
||||
context,
|
||||
setState,
|
||||
key: SettingBoxKey.bufferSize,
|
||||
defVal: Pref.bufferSize,
|
||||
title: '缓冲大小',
|
||||
suffix: 'MB',
|
||||
);
|
||||
|
||||
void _showBufferSecDialog(BuildContext context, VoidCallback setState) =>
|
||||
_showDecimalDialog(
|
||||
context,
|
||||
setState,
|
||||
key: SettingBoxKey.bufferSec,
|
||||
defVal: Pref.bufferSec,
|
||||
title: '缓冲时长',
|
||||
suffix: 's',
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user