fix(player): 收紧图片与快速切集资源占用

This commit is contained in:
Zhou Weidong committed 2026-10-26 15:10:02 +08:00
1 parent 2fef7470e0
commit 80c962a95c
10 files changed
+281 -30

No files matched your search

@@ -81,6 +81,8 @@ class PlaybackSession extends ChangeNotifier {
// Includes initialization and asynchronous disposal, until native release ends.
int get livePlayerCount => _live.length;
int? get preloadedIndex => _next?.prepared == true ? _next?.index : null;
int? get previousPreloadedIndex =>
_previous?.prepared == true ? _previous?.index : null;
Future<void> get playbackSettled => _operations;
Future<void> get preloadSettled => _preloadTask;
@@ -9,7 +9,7 @@ import '../../config/app_config.dart';
import 'sprite_thumbnail_asset_loader.dart';
const Duration spriteVttCacheTtl = Duration(minutes: 10);
const int spriteImageCacheCapacity = 2;
const int spriteImageCacheCapacity = 1;
/// 单个 VTT cue 对应的 sprite 裁剪区域。
class SpriteThumbnailCue {
@@ -148,7 +148,6 @@ class SpriteThumbnailAxisService extends ChangeNotifier
final Set<String> _failedSprites = {};
bool _disposed = false;
@visibleForTesting
int get spriteCacheSize => _spriteCache.length;
@visibleForTesting
@@ -156,7 +155,7 @@ class SpriteThumbnailAxisService extends ChangeNotifier
.map((url) => Uri.tryParse(url)?.pathSegments.lastOrNull ?? url)
.toList();
/// 播放器就绪时预取当前 cue 与相邻 sprite,拖动帧不触发网络或解码。
/// 播放器就绪时预取当前 cue;容量大于 1 时顺带预取相邻 sprite。
@override
Future<void> prepareAt(String? thumbnailsUrl, Duration position) async {
final url = _normalizeUrl(thumbnailsUrl);
@@ -269,6 +268,7 @@ class SpriteThumbnailAxisService extends ChangeNotifier
if (current == null) return const [];
final index = axis.cues.indexOf(current);
final candidates = <SpriteThumbnailCue>[current];
if (spriteCacheCapacity <= 1) return candidates;
for (final direction in const [1, -1]) {
for (var step = 1; step < axis.cues.length; step++) {
final neighborIndex = index + direction * step;