fix(player): retain duration probing after queue edits during loading

This commit is contained in:
zarzet
2026-09-27 00:42:53 +07:00
parent da5a0522ca
commit fa4a03c754
2 changed files with 27 additions and 8 deletions
+22 -1
View File
@@ -41,6 +41,7 @@ class _AudioNative {
final sources = <String, String>{};
final sourceGates = <String, Completer<void>>{};
final resumedSources = <String>[];
bool emitsDuration = true;
void install() {
for (final name in [
@@ -71,7 +72,7 @@ class _AudioNative {
await sourceGates[source]?.future;
sources[id] = source;
unawaited(event(id, 'audio.onPrepared', true));
unawaited(event(id, 'audio.onDuration', 60000));
if (emitsDuration) unawaited(event(id, 'audio.onDuration', 60000));
case 'seek':
positions[id] = args['position']! as int;
unawaited(event(id, 'audio.onSeekComplete'));
@@ -406,6 +407,26 @@ void main() {
},
);
test(
'removing an earlier row during preparation preserves duration probing',
() async {
native.emitsDuration = false;
final gate = Completer<void>();
native.sourceGates['/three.flac'] = gate;
final loading = handler.setQueueAndPlay(_tracks, initialIndex: 2);
await _until(() => native.calls.any((call) => call.$2 == 'setSourceUrl'));
handler.removeQueuedItem(handler.queue.value.first);
gate.complete();
await loading;
await _until(
() => handler.mediaItem.value?.duration == const Duration(seconds: 60),
);
expect(handler.playbackState.value.queueIndex, 1);
expect(handler.mediaItem.value?.id, 'three');
expect(native.resumedSources, ['/three.flac']);
},
);
test('restored shuffle can return to the saved original order', () async {
await handler.restoreSession(
items: [_tracks[1], _tracks[2], _tracks[0]],