fix(playback): 位置回退保护 + 恢复用最后已知位置 + 缓冲感知重试
对应 10/24 日志里的"播到一半中断后从头重播": 23:05:26 ffurl_read -> 从 77s 重连成功 23:05:33 再断 -> position 归 0 -> 看门狗"从 0s 继续",听感就是重新开始 - 新增 _lastKnownPosition:位置流累积,切歌归零; 所有恢复路径(看门狗 / 网络切换 / 打开失败)都用它续播 - 位置回退保护(抽成 utils/position_guard.dart): 已播 >10s 且新位置 <5s 时忽略回退,除非用户 seek / 切歌 / 正在恢复 - _scheduleOpenRetry 改为缓冲感知: 缓冲余量 >=12s 时延迟 4s 重试(不打断),否则 1.2s; 重试前若位置已推进超过 1s,判定 mpv 自愈,取消重连 - 收藏列表点击改为整队入队(setQueue,从点击项开始) 测试:新增 position_guard 6 个用例,累计 25 个全绿。 真机验证:收藏整队日志 "17 首,从第 16 首开始",播放正常。
This commit is contained in:
@@ -336,6 +336,44 @@ class _HomePageState extends BaseState<HomePage> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 收藏列表整队入队:点哪首就从哪首开始,队列是整个收藏列表
|
||||
Future<void> _playFavorites(int index) async {
|
||||
if (_favorites.isEmpty) return;
|
||||
try {
|
||||
final headers = await WebDAVService.instance.getAuthHeaders();
|
||||
if (headers.isEmpty) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('请先登录 WebDAV'),
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final songs = _favorites
|
||||
.map((item) => Song(
|
||||
id: item.path,
|
||||
title: item.displayTitle,
|
||||
artist: item.displaySubtitle,
|
||||
url: WebDAVService.instance.getFileUrl(item.path),
|
||||
))
|
||||
.toList();
|
||||
|
||||
if (!mounted) return;
|
||||
debugPrint('⭐ [Home] 收藏整队入队:${songs.length} 首,从第 $index 首开始');
|
||||
await context.read<AudioService>().setQueue(songs, startIndex: index);
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('播放失败: $e'), backgroundColor: Colors.red),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ⭐ 退出/重新登录对话框
|
||||
void _showReauthDialog() {
|
||||
showDialog(
|
||||
@@ -773,7 +811,7 @@ class _HomePageState extends BaseState<HomePage> {
|
||||
if (mounted) safeSetState(() {});
|
||||
},
|
||||
),
|
||||
onTap: () => _playSong(song),
|
||||
onTap: () => _playFavorites(index),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user