Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Restart proxy in case of -1004 error (updated) #1218

Open
wants to merge 1 commit into
base: minor
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions just_audio/lib/just_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic, dynamic>?)?.cast<String, dynamic>());
} on FormatException catch (_) {
Expand Down Expand Up @@ -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
Expand Down