No buffering rings at the end of short videos; links never guess an AniList show
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9a4b04672b
commit
24fc137e4f
6 files changed
+33
-5
No files matched your search
@@ -559,12 +559,17 @@ class StateBroadcast {
|
||||
/// Buffer an in-set member needs before playback can go on, as the
|
||||
/// server's gate counts it: [RelayConstants.minBufferSecs], less near the
|
||||
/// end (mpv cannot buffer past it), none once finished.
|
||||
double get bufferNeed {
|
||||
double get bufferNeed => bufferNeedAt(DateTime.now().toUtc());
|
||||
|
||||
/// [bufferNeed] at [now]: while playing the position has moved on since
|
||||
/// [serverTime] (the local clock is close enough for this).
|
||||
double bufferNeedAt(DateTime now) {
|
||||
if (transport == 'finished') return 0;
|
||||
final d = (media?['duration'] as num?)?.toDouble() ?? 0;
|
||||
const full = RelayConstants.minBufferSecs;
|
||||
if (d <= 0) return full;
|
||||
return (d - position - RelayConstants.endSlackSecs).clamp(0.0, full).toDouble();
|
||||
final moved = transport == 'playing' ? now.difference(serverTime).inMilliseconds / 1000 : 0;
|
||||
return (d - (position + moved) - RelayConstants.endSlackSecs).clamp(0.0, full).toDouble();
|
||||
}
|
||||
|
||||
final int eventId;
|
||||
|
||||
@@ -193,4 +193,21 @@ void main() {
|
||||
expect((r.duration, r.mediaId), (0.0, 0));
|
||||
});
|
||||
});
|
||||
|
||||
test('bufferNeed counts the time played since the last event', () {
|
||||
final t0 = DateTime.utc(2026, 1, 1);
|
||||
final s = StateBroadcast(
|
||||
eventId: 1,
|
||||
transport: 'playing',
|
||||
position: 0,
|
||||
serverTime: t0,
|
||||
mediaId: 1,
|
||||
media: const {'name': 'clip', 'duration': 6.0},
|
||||
members: const [],
|
||||
);
|
||||
expect(s.bufferNeedAt(t0), 4.0);
|
||||
// 3 s in: 3 s left, minus the 2 s end slack.
|
||||
expect(s.bufferNeedAt(t0.add(const Duration(seconds: 3))), closeTo(1.0, 1e-9));
|
||||
expect(s.bufferNeedAt(t0.add(const Duration(seconds: 5))), 0);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user