up
This commit is contained in:
@@ -65,9 +65,9 @@ class FeedPlayerPool {
|
||||
bool get isCurrentPlaying => currentSlot.player.state.playing;
|
||||
|
||||
/// 绑定窗口:index 为当前页;items 为已解析好播放地址的窗口数据源
|
||||
void bindWindow(int index, List<({int videoId, String url})> items) {
|
||||
Future<void> bindWindow(int index, List<({int videoId, String url})> items) async {
|
||||
_currentIndex = index;
|
||||
// 1. 窗口内槽位按需加载
|
||||
// 1. 窗口内槽位按需加载(open 完才 play,libmpv 不接受未 open 的 play)
|
||||
for (var offset = -1; offset <= 1; offset++) {
|
||||
final i = index + offset;
|
||||
if (i < 0 || i >= items.length) continue;
|
||||
@@ -77,7 +77,7 @@ class FeedPlayerPool {
|
||||
slot.videoId = item.videoId;
|
||||
slot.completeNotified = false;
|
||||
if (item.url.isNotEmpty) {
|
||||
slot.player.open(Media(item.url), play: false);
|
||||
await slot.player.open(Media(item.url), play: false);
|
||||
}
|
||||
}
|
||||
// 2. 槽位状态:当前播、相邻预缓冲(保持 pause)、出窗复位
|
||||
@@ -120,10 +120,18 @@ class FeedPlayerPool {
|
||||
}));
|
||||
_subs.add(slot.player.stream.completed.listen((done) {
|
||||
if (!done) return;
|
||||
if (slot.videoId < 0 || slot.completeNotified) return;
|
||||
if (slot != currentSlot) return;
|
||||
slot.completeNotified = true;
|
||||
onWatchComplete?.call(slot.videoId, lastPosition.inSeconds);
|
||||
// 每视频每次绑定只触发一次 complete 上报(≥95% 或播完都算)
|
||||
if (slot.videoId >= 0 && !slot.completeNotified) {
|
||||
slot.completeNotified = true;
|
||||
if (slot == currentSlot) {
|
||||
onWatchComplete?.call(slot.videoId, lastPosition.inSeconds);
|
||||
}
|
||||
}
|
||||
// 自动循环(抖音/TikTok 式体验:当前槽播完从头再来)
|
||||
if (slot == currentSlot) {
|
||||
slot.player.seek(Duration.zero);
|
||||
slot.player.play();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user