From 555e945d219be8c91dcdda198c0a2a495f6e9f1a Mon Sep 17 00:00:00 2001 From: Grzegorz Leoniec Date: Mon, 1 Apr 2024 11:21:43 +0200 Subject: [PATCH] applied https://github.com/ryanheise/just_audio/pull/812 --- just_audio/lib/just_audio.dart | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) 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