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 dom
parent 3b942eeeaf
commit ce09306025
10 changed files with 149 additions and 38 deletions

View File

@@ -597,7 +597,6 @@ class PlPlayerController with BlockConfigMixin {
final player = await Player.create(
configuration: PlayerConfiguration(
bufferSize: isLive ? 16 * 1024 * 1024 : 4 * 1024 * 1024,
logLevel: kDebugMode ? .warn : .error,
options: opt,
),
@@ -614,17 +613,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,
@@ -654,6 +674,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) {
@@ -678,11 +708,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;
}