A cross platform Audiobookshelf client for Android and iOS
Dart
Add audio diagnostic logs for the no-sound symptom
Barnabas01c4bcec9c69
diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swiftindex e0d52a64..2d9255ce 100644--- a/ios/Runner/AppDelegate.swift+++ b/ios/Runner/AppDelegate.swift@@ -209,6 +209,40 @@ let flutterEngine = FlutterEngine(name: "SharedEngine", project: nil, allowHeadlcase "isBluetoothAudioConnected":result(self?.isBluetoothAudioConnected() ?? false)+ case "getAudioDiagnostics":+ // Snapshot of AVAudioSession state for the "tap play, no sound"+ // diagnosis. Returns category, mode, options, output volume,+ // current route ports, and the session-active hint that iOS+ // exposes. Dart side logs all of it via [AudioDiag] markers.+ let session = AVAudioSession.sharedInstance()+ let route = session.currentRoute+ let outputs = route.outputs.map { port -> [String: String] in+ [+ "name": port.portName,+ "type": port.portType.rawValue,+ "uid": port.uid,+ ]+ }+ let inputs = route.inputs.map { port -> [String: String] in+ [+ "name": port.portName,+ "type": port.portType.rawValue,+ ]+ }+ let info: [String: Any] = [+ "category": session.category.rawValue,+ "mode": session.mode.rawValue,+ "categoryOptions": session.categoryOptions.rawValue,+ "outputVolume": session.outputVolume,+ "isOtherAudioPlaying": session.isOtherAudioPlaying,+ "secondaryAudioShouldBeSilencedHint": session.secondaryAudioShouldBeSilencedHint,+ "outputs": outputs,+ "inputs": inputs,+ "sampleRate": session.sampleRate,+ "ioBufferDuration": session.ioBufferDuration,+ ]+ result(info)+case "init":// iOS has no system EQ, so we advertise a fixed 5-band layout that// matches what AudioEQProcessor's biquad filters handle.diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dartindex b580e661..1bec1e5c 100644--- a/lib/services/audio_player_service.dart+++ b/lib/services/audio_player_service.dart@@ -937,6 +937,73 @@ class AudioPlayerService extends ChangeNotifier {double get volume => _player?.volume ?? 1.0;Future<void> setVolume(double v) async => _player?.setVolume(v);+ static const _eqChannelForDiag = MethodChannel('com.absorb.equalizer');++ /// Diagnostic snapshot for the "tap play, no sound" issue. Logs both+ /// just_audio player state AND iOS AVAudioSession route/volume info so+ /// we can tell apart "player thinks it's playing but no audio reaches+ /// speakers" from "player is buffering forever" from "wrong output+ /// route" etc.+ Future<void> _logAudioDiagnostics(String stage) async {+ try {+ final p = _player;+ final pos = p?.position;+ final dur = p?.duration;+ final buffered = p?.bufferedPosition;+ final pieces = <String>[+ 'stage=$stage',+ 'playing=${p?.playing}',+ 'state=${p?.processingState.name}',+ 'volume=${p?.volume?.toStringAsFixed(2)}',+ 'speed=${p?.speed?.toStringAsFixed(2)}',+ 'pos=${pos != null ? "${(pos.inMilliseconds / 1000.0).toStringAsFixed(1)}s" : "null"}',+ 'dur=${dur != null ? "${(dur.inMilliseconds / 1000.0).toStringAsFixed(1)}s" : "null"}',+ 'buf=${buffered != null ? "${(buffered.inMilliseconds / 1000.0).toStringAsFixed(1)}s" : "null"}',+ 'item=$_currentItemId',+ 'ep=$_currentEpisodeId',+ ];++ if (Platform.isIOS) {+ try {+ final info = await _eqChannelForDiag+ .invokeMethod<Map<dynamic, dynamic>>('getAudioDiagnostics');+ if (info != null) {+ final outputs = (info['outputs'] as List?)+ ?.map((o) =>+ '${(o as Map)["type"]}:${o["name"]}')+ .join(',') ??+ '?';+ pieces.addAll([+ 'ios.cat=${info["category"]}',+ 'ios.mode=${info["mode"]}',+ 'ios.outVol=${info["outputVolume"]}',+ 'ios.otherAudio=${info["isOtherAudioPlaying"]}',+ 'ios.silenceHint=${info["secondaryAudioShouldBeSilencedHint"]}',+ 'ios.route=[$outputs]',+ 'ios.sampleRate=${info["sampleRate"]}',+ ]);+ }+ } catch (e) {+ pieces.add('ios.err=$e');+ }+ }++ debugPrint('[AudioDiag] ${pieces.join(' ')}');+ } catch (e) {+ debugPrint('[AudioDiag] log failed: $e');+ }+ }++ /// Schedule a sequence of diagnostic snapshots after starting playback so+ /// we can see whether state advanced as expected ("playing then+ /// position-stuck-at-0" is a classic no-sound fingerprint).+ void _scheduleAudioDiagnostics(String startStage) {+ _logAudioDiagnostics('$startStage:t0');+ Future.delayed(const Duration(seconds: 1), () => _logAudioDiagnostics('$startStage:t1s'));+ Future.delayed(const Duration(seconds: 3), () => _logAudioDiagnostics('$startStage:t3s'));+ Future.delayed(const Duration(seconds: 10), () => _logAudioDiagnostics('$startStage:t10s'));+ }+Stream<Duration> get positionStream =>_player?.positionStream ?? const Stream.empty();Stream<Duration?> get durationStream =>@@ -1764,6 +1831,7 @@ class AudioPlayerService extends ChangeNotifier {// lock screen / Control Center / AirPod controls never appear.try { (await AudioSession.instance).setActive(true); } catch (_) {}_player!.play();+ _scheduleAudioDiagnostics('local');notifyListeners();_setupSync();// Ensure iOS lock screen / Control Center controls appear by pushing@@ -1870,6 +1938,7 @@ class AudioPlayerService extends ChangeNotifier {debugPrint('[Player] Starting cached session playback at ${speed}x');try { (await AudioSession.instance).setActive(true); } catch (_) {}_player!.play();+ _scheduleAudioDiagnostics('cached-session');notifyListeners();_setupSync();Future.delayed(const Duration(milliseconds: 500), () {@@ -2108,6 +2177,7 @@ class AudioPlayerService extends ChangeNotifier {// Re-activate audio session before play (see local playback comment above)try { (await AudioSession.instance).setActive(true); } catch (_) {}_player!.play();+ _scheduleAudioDiagnostics('stream');notifyListeners();_setupSync();// Ensure iOS lock screen / Control Center controls appear (see local playback comment)@@ -2204,6 +2274,7 @@ class AudioPlayerService extends ChangeNotifier {debugPrint('[Player] Transcoded playback starting at ${speed}x');try { (await AudioSession.instance).setActive(true); } catch (_) {}_player!.play();+ _scheduleAudioDiagnostics('transcoded-retry');notifyListeners();_setupSync();Future.delayed(const Duration(milliseconds: 500), () {@@ -2302,6 +2373,7 @@ class AudioPlayerService extends ChangeNotifier {debugPrint('[Player] Transcoded playback starting at ${speed}x');try { (await AudioSession.instance).setActive(true); } catch (_) {}_player!.play();+ _scheduleAudioDiagnostics('transcoded');notifyListeners();_setupSync();Future.delayed(const Duration(milliseconds: 500), () {@@ -3168,6 +3240,7 @@ class AudioPlayerService extends ChangeNotifier {}// Start playback immediately — don't wait for server calls_player?.play();+ _scheduleAudioDiagnostics('resume');_logEvent(PlaybackEventType.play);_onPlaybackStateChangedCallback?.call(true);// Re-create server session and check progress in the background