From 64a7d3adb688f02efec9f95a09c7273c6c89c34c Mon Sep 17 00:00:00 2001 From: dom Date: Fri, 12 Jun 2026 10:04:51 +0800 Subject: [PATCH] configure audio buffer Signed-off-by: dom --- lib/pages/audio/controller.dart | 1 + lib/pages/audio/view.dart | 3 +-- lib/plugin/pl_player/controller.dart | 25 +++---------------------- lib/utils/storage_pref.dart | 20 ++++++++++++++++++++ 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/pages/audio/controller.dart b/lib/pages/audio/controller.dart index bbe7126f1..8544b4082 100644 --- a/lib/pages/audio/controller.dart +++ b/lib/pages/audio/controller.dart @@ -336,6 +336,7 @@ class AudioController extends GetxController ? (desktopVolume.value * 100).toString() : Pref.playerVolume.toString(), 'volume-max': kMaxVolume.toString(), + ...Pref.initBuffer(), }, ), ); diff --git a/lib/pages/audio/view.dart b/lib/pages/audio/view.dart index 80c4fbcf3..20119a600 100644 --- a/lib/pages/audio/view.dart +++ b/lib/pages/audio/view.dart @@ -773,7 +773,6 @@ class _AudioPageState extends State { Widget _buildProgressBar(ColorScheme colorScheme) { final primary = colorScheme.primary; final thumbGlowColor = primary.withAlpha(80); - final bufferedBarColor = primary.withValues(alpha: 0.4); final baseBarColor = colorScheme.isDark ? const Color(0x33FFFFFF) : const Color(0x33999999); @@ -783,7 +782,7 @@ class _AudioPageState extends State { total: _controller.duration.value, baseBarColor: baseBarColor, progressBarColor: primary, - bufferedBarColor: bufferedBarColor, + bufferedBarColor: Colors.transparent, thumbColor: primary, thumbGlowColor: thumbGlowColor, thumbGlowRadius: 0, diff --git a/lib/plugin/pl_player/controller.dart b/lib/plugin/pl_player/controller.dart index 45625a48b..678636ce4 100644 --- a/lib/plugin/pl_player/controller.dart +++ b/lib/plugin/pl_player/controller.dart @@ -813,29 +813,10 @@ class PlPlayerController with BlockConfigMixin { } Map? _buffer; - Map get buffer => _buffer ??= _initBuffer(); + Map get buffer => + _buffer ??= Pref.initBuffer(_playbackSpeed.value); Map? _liveBuffer; - Map get liveBuffer => _liveBuffer ??= _initLiveBuffer(); - - Map _initBuffer() { - final bufSec = Pref.bufferSec * _playbackSpeed.value; - final bufSiz = (Pref.bufferSize * 0x100000).toStringAsFixed(0); - return { - 'cache': 'yes', - 'cache-secs': bufSec.toStringAsFixed(3), - 'demuxer-hysteresis-secs': (bufSec / 1.5).toStringAsFixed(3), - 'demuxer-max-bytes': bufSiz, - 'demuxer-max-back-bytes': bufSiz, - }; - } - - Map _initLiveBuffer() { - return { - 'cache': 'yes', - 'demuxer-max-bytes': (Pref.bufferSize * 0x200000).toStringAsFixed(0), - 'demuxer-max-back-bytes': '0', - }; - } + Map get liveBuffer => _liveBuffer ??= Pref.initLiveBuffer(); // 配置播放器 Future _createVideoController( diff --git a/lib/utils/storage_pref.dart b/lib/utils/storage_pref.dart index 60549e2cc..bba1e4698 100644 --- a/lib/utils/storage_pref.dart +++ b/lib/utils/storage_pref.dart @@ -803,6 +803,26 @@ abstract final class Pref { static double get bufferSec => _setting.get(SettingBoxKey.bufferSec, defaultValue: 16.0); + static Map initBuffer([double playbackSpeed = 1.0]) { + final bufSec = Pref.bufferSec * playbackSpeed; + final bufSiz = (Pref.bufferSize * 0x100000).toStringAsFixed(0); + return { + 'cache': 'yes', + 'cache-secs': bufSec.toStringAsFixed(3), + 'demuxer-hysteresis-secs': (bufSec / 1.5).toStringAsFixed(3), + 'demuxer-max-bytes': bufSiz, + 'demuxer-max-back-bytes': bufSiz, + }; + } + + static Map initLiveBuffer() { + return { + 'cache': 'yes', + 'demuxer-max-bytes': (Pref.bufferSize * 0x200000).toStringAsFixed(0), + 'demuxer-max-back-bytes': '0', + }; + } + static String get audioOutput => _setting.get( SettingBoxKey.audioOutput, defaultValue: AudioOutput.defaultValue,