feat: custom buffer size (#2370)

* feat: custom buffer size

* cache buffer params

---------

Co-authored-by: dom <githubaccount56556@proton.me>
This commit is contained in:
My-Responsitories
2026-06-10 01:54:32 +00:00
committed by GitHub
parent 90d79b236f
commit 22f37074b1
13 changed files with 152 additions and 64 deletions

View File

@@ -789,9 +789,6 @@ class PlPlayerController with BlockConfigMixin {
final player = await Player.create(
configuration: PlayerConfiguration(
bufferSize: Pref.expandBuffer
? (isLive ? 64 * 1024 * 1024 : 32 * 1024 * 1024)
: (isLive ? 16 * 1024 * 1024 : 4 * 1024 * 1024),
logLevel: kDebugMode ? .warn : .error,
options: opt,
),
@@ -808,17 +805,38 @@ class PlPlayerController with BlockConfigMixin {
),
);
player.setMediaHeader(
userAgent: BrowserUa.pc,
referer: HttpString.baseUrl,
);
// await player.setAudioTrack(.auto());
player.setMediaHeader(userAgent: BrowserUa.pc, referer: HttpString.baseUrl);
_startListeners(player);
return player;
}
Map<String, String>? _buffer;
Map<String, String> get buffer => _buffer ??= _initBuffer();
Map<String, String>? _liveBuffer;
Map<String, String> get liveBuffer => _liveBuffer ??= _initLiveBuffer();
Map<String, String> _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<String, String> _initLiveBuffer() {
return {
'cache': 'yes',
'demuxer-max-bytes': (Pref.bufferSize * 0x200000).toStringAsFixed(0),
'demuxer-max-back-bytes': '0',
};
}
// 配置播放器
Future<void> _createVideoController(
DataSource dataSource,
@@ -851,6 +869,16 @@ class PlPlayerController with BlockConfigMixin {
final Map<String, String> extras = {};
if (dataSource is FileSource) {
extras['cache'] = 'no';
} else {
if (isLive) {
extras.addAll(liveBuffer);
} else {
extras.addAll(buffer);
}
}
String video = dataSource.videoSource;
if (dataSource.audioSource case final audio? when (audio.isNotEmpty)) {
if (onlyPlayAudio.value) {
@@ -900,11 +928,8 @@ class PlPlayerController with BlockConfigMixin {
if (dataSource is FileSource) {
return null;
}
if (_videoPlayerController?.current.isNotEmpty ?? false) {
return _videoPlayerController!.open(
_videoPlayerController!.current.last.copyWith(start: position),
play: true,
);
if (_videoPlayerController case final ctr? when (ctr.current.isNotEmpty)) {
return ctr.open(ctr.current.last.copyWith(start: position), play: true);
}
return null;
}