fix: serialize async state transitions

This commit is contained in:
edde746
2026-07-12 18:59:14 +02:00
parent d1c4ae83eb
commit cd88f73f05
16 changed files with 294 additions and 82 deletions
+10 -3
View File
@@ -174,6 +174,7 @@ class PlayerNative extends PlayerBase {
// Two concurrent invokes on Android caused MpvPlayerPlugin.handleInitialize
// to dispose-and-recreate the in-flight core, hanging playback (#930).
Future<void>? _initFuture;
Future<void> _rateChangeTail = Future<void>.value();
Future<void> _ensureInitialized() async {
if (initialized) return;
@@ -554,10 +555,16 @@ class PlayerNative extends PlayerBase {
}
@override
Future<void> setRate(double rate) async {
// mpv cannot scaletempo compressed (spdif) audio and silently keeps
// playing at 1x, so suspend passthrough while the rate is not 1.0.
Future<void> setRate(double rate) {
_currentRate = rate;
final operation = _rateChangeTail.then((_) => _applyRateChange(rate));
_rateChangeTail = operation.catchError((Object _, StackTrace _) {});
return operation;
}
Future<void> _applyRateChange(double rate) async {
// mpv cannot scaletempo compressed (spdif) audio and silently keeps
// playing at 1x, so serialize passthrough and speed transitions.
if (_passthroughActive && rate != 1.0) {
await _applyPassthrough(false);
}