Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Cap server session call at 5s so silent network drops don't delay offline play

Barnabas39e0b12ca7a7
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dart
index ffb8c6a9..0fa974a6 100644
--- a/lib/services/audio_player_service.dart
+++ b/lib/services/audio_player_service.dart
@@ -1663,13 +1663,20 @@ class AudioPlayerService extends ChangeNotifier {
final manualOffline = prefs.getBool('manual_offline_mode') ?? false;
debugPrint('[Player] manualOffline=$manualOffline, api=${_api != null}');
- // Try to start a server session for sync (unless manual offline)
+ // Try to start a server session for sync (unless manual offline).
+ // Cap the call at 5s so a silently-dropping reverse proxy doesn't
+ // hold up local playback for the full 20s api-level timeout. On a
+ // healthy server the response comes back in under 1s; on truly dead
+ // networks the kernel returns ECONNREFUSED in milliseconds; only
+ // the "host accepts but never replies" case takes the full window
+ // and that's the case we're shortening.
if (_api != null && !manualOffline) {
try {
debugPrint('[Player] Starting server session for local playback...');
- final sessionData = _currentEpisodeId != null
- ? await _api!.startEpisodePlaybackSession(_currentItemId!, _currentEpisodeId!)
- : await _api!.startPlaybackSession(itemId);
+ final sessionData = await (_currentEpisodeId != null
+ ? _api!.startEpisodePlaybackSession(_currentItemId!, _currentEpisodeId!)
+ : _api!.startPlaybackSession(itemId)
+ ).timeout(const Duration(seconds: 5), onTimeout: () => null);
if (sessionData != null) {
_playbackSessionId = sessionData['id'] as String?;
debugPrint('[Player] Got server session for local playback: $_playbackSessionId');
diff --git a/pubspec.yaml b/pubspec.yaml
index 21f5fc53..f567d165 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,7 +1,7 @@
name: absorb
description: An Audiobookshelf Client
publish_to: 'none'
-version: 1.8.78+112
+version: 1.8.78+113
environment:
sdk: '>=3.1.0 <4.0.0'