From a56ef0e3ca6f4e60c413eda53534bf214d68fefc Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Thu, 26 Feb 2026 12:28:30 +0100 Subject: [PATCH] fix: throttle cache state parsing --- lib/mpv/player/player_base.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/mpv/player/player_base.dart b/lib/mpv/player/player_base.dart index 82a06537..a3270125 100644 --- a/lib/mpv/player/player_base.dart +++ b/lib/mpv/player/player_base.dart @@ -40,6 +40,7 @@ abstract class PlayerBase with PlayerStreamControllersMixin implements Player { bool _disposed = false; final _throttleSw = Stopwatch()..start(); int _lastEmitMs = 0; + int _lastCacheStateMs = 0; int _positionMs = 0; int _nextPropId = 0; final Map _propIdToName = {}; @@ -274,6 +275,10 @@ abstract class PlayerBase with PlayerStreamControllersMixin implements Player { if (value is Map) { cacheState = value; } else if (value is String && value.isNotEmpty) { + // Throttle JSON parsing to avoid ANR on low-end devices + final nowMs = _throttleSw.elapsedMilliseconds; + if (nowMs - _lastCacheStateMs < 250) return; + _lastCacheStateMs = nowMs; try { final parsed = jsonDecode(value); if (parsed is Map) cacheState = parsed;