diff --git a/just_audio/lib/just_audio.dart b/just_audio/lib/just_audio.dart index 759835e82..8e8fbcd2d 100644 --- a/just_audio/lib/just_audio.dart +++ b/just_audio/lib/just_audio.dart @@ -866,6 +866,16 @@ class AudioPlayer { return duration; } on PlatformException catch (e) { try { + // cant connect to servers + if (e.code == "-1004" && source is LockCachingAudioSource) { + // proxy is offline + try { + await _proxy._server.close(force: true); + } catch (_) { + // ignore err + } + await _proxy.start(); + } throw PlayerException(int.parse(e.code), e.message, (e.details as Map?)?.cast()); } on FormatException catch (_) { @@ -2093,9 +2103,14 @@ class _ProxyHttpServer { } }, onDone: () { _running = false; - }, onError: (Object e, StackTrace st) { + }, onError: (Object e, StackTrace st) async { _running = false; - }); + try { + await _server.close(force: true); + } catch (_) { + // ignore + } + }, cancelOnError: true); } /// Stops the server