Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add Skip Silence toggle to EQ

Barnabasc468eac240cd
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dart
index 42ebc4f9..3c405c30 100644
--- a/lib/services/audio_player_service.dart
+++ b/lib/services/audio_player_service.dart
@@ -1216,6 +1216,17 @@ class AudioPlayerService extends ChangeNotifier {
);
// Bind service so handler routes play/pause through service (for auto-rewind)
_handler!.bindService(_instance);
+ // Wire the EQ service's skip-silence toggle through to just_audio.
+ // Android-only: just_audio's setSkipSilenceEnabled is a no-op on iOS.
+ if (Platform.isAndroid) {
+ EqualizerService().setSkipSilenceApplier((enabled) {
+ try {
+ _handler?.player.setSkipSilenceEnabled(enabled);
+ } catch (e) {
+ debugPrint('[Player] setSkipSilenceEnabled failed: $e');
+ }
+ });
+ }
// Initialize cached skip amounts so notification icons show the correct values
_handler!._cachedForwardSkip = fwdSkip;
_handler!._cachedBackSkip = backSkip;
diff --git a/lib/services/equalizer_service.dart b/lib/services/equalizer_service.dart
index fa1caa6c..5771d6a0 100644
--- a/lib/services/equalizer_service.dart
+++ b/lib/services/equalizer_service.dart
@@ -24,9 +24,16 @@ class EqualizerService extends ChangeNotifier {
double _virtualizer = 0.0; // 0.0–1.0
double _loudnessGain = 0.0; // 0.0–1.0
bool _mono = false;
+ bool _skipSilence = false;
bool _perItem = false;
String? _currentItemId;
+ /// Applied to the just_audio AudioPlayer whenever skipSilence changes
+ /// (toggle, per-book switch, account reload). Registered by
+ /// AudioPlayerService.init so the EQ service stays decoupled from
+ /// just_audio.
+ void Function(bool enabled)? _skipSilenceApplier;
+
// Built-in presets (EQ curve shapes)
static const Map<String, List<double>> presets = {
'flat': [0, 0, 0, 0, 0],
@@ -51,6 +58,7 @@ class EqualizerService extends ChangeNotifier {
double get virtualizer => _virtualizer;
double get loudnessGain => _loudnessGain;
bool get mono => _mono;
+ bool get skipSilence => _skipSilence;
bool get perItem => _perItem;
String? get currentItemId => _currentItemId;
@@ -82,6 +90,7 @@ class EqualizerService extends ChangeNotifier {
debugPrint('[EQ] Unexpected error: $e — using software presets');
_setupSoftwareFallback();
}
+ _skipSilenceApplier?.call(_skipSilence);
notifyListeners();
}
@@ -170,6 +179,23 @@ class EqualizerService extends ChangeNotifier {
notifyListeners();
}
+ /// Toggle skip-silence on the just_audio player. Android-only;
+ /// the applier no-ops on iOS.
+ Future<void> setSkipSilence(bool value) async {
+ _skipSilence = value;
+ _skipSilenceApplier?.call(_skipSilence);
+ await _saveSettings();
+ notifyListeners();
+ }
+
+ /// Register a callback that the service invokes whenever skipSilence
+ /// changes. Called once immediately with the current value so the player
+ /// picks up persisted state on app start.
+ void setSkipSilenceApplier(void Function(bool enabled) fn) {
+ _skipSilenceApplier = fn;
+ fn(_skipSilence);
+ }
+
/// Set loudness enhancer gain (0.0–1.0).
Future<void> setLoudnessGain(double value) async {
_loudnessGain = value.clamp(0.0, 1.0);
@@ -190,6 +216,8 @@ class EqualizerService extends ChangeNotifier {
_virtualizer = 0.0;
_loudnessGain = 0.0;
_mono = false;
+ _skipSilence = false;
+ _skipSilenceApplier?.call(_skipSilence);
if (_enabled) {
_applyCurrentSettings();
}
@@ -265,6 +293,7 @@ class EqualizerService extends ChangeNotifier {
}
_currentItemId = itemId;
await _loadItemSettings(itemId);
+ _skipSilenceApplier?.call(_skipSilence);
if (_enabled) {
_applyCurrentSettings();
} else {
@@ -290,6 +319,7 @@ class EqualizerService extends ChangeNotifier {
'virtualizer': 0.0,
'loudnessGain': 0.0,
'mono': false,
+ 'skipSilence': false,
'bands': List<double>.filled(bandCount, 0.0),
};
}
@@ -304,6 +334,7 @@ class EqualizerService extends ChangeNotifier {
'virtualizer': await ScopedPrefs.getDouble(_itemKey('virtualizer', itemId)) ?? 0.0,
'loudnessGain': await ScopedPrefs.getDouble(_itemKey('loudnessGain', itemId)) ?? 0.0,
'mono': await ScopedPrefs.getBool(_itemKey('mono', itemId)) ?? false,
+ 'skipSilence': await ScopedPrefs.getBool(_itemKey('skipSilence', itemId)) ?? false,
'bands': bands,
};
}
@@ -316,6 +347,7 @@ class EqualizerService extends ChangeNotifier {
await ScopedPrefs.setDouble(_itemKey('virtualizer', itemId), s['virtualizer'] as double);
await ScopedPrefs.setDouble(_itemKey('loudnessGain', itemId), s['loudnessGain'] as double);
await ScopedPrefs.setBool(_itemKey('mono', itemId), s['mono'] as bool);
+ await ScopedPrefs.setBool(_itemKey('skipSilence', itemId), s['skipSilence'] as bool? ?? false);
final bands = (s['bands'] as List).cast<double>();
await ScopedPrefs.setString(_itemKey('bands', itemId), bands.map((l) => l.toStringAsFixed(1)).join(','));
}
@@ -329,6 +361,7 @@ class EqualizerService extends ChangeNotifier {
_virtualizer = 0.0;
_loudnessGain = 0.0;
_mono = false;
+ _skipSilence = false;
_bandLevels = List.filled(_bandLevels.length, 0.0);
return;
}
@@ -338,6 +371,7 @@ class EqualizerService extends ChangeNotifier {
_virtualizer = await ScopedPrefs.getDouble(_itemKey('virtualizer', itemId)) ?? 0.0;
_loudnessGain = await ScopedPrefs.getDouble(_itemKey('loudnessGain', itemId)) ?? 0.0;
_mono = await ScopedPrefs.getBool(_itemKey('mono', itemId)) ?? false;
+ _skipSilence = await ScopedPrefs.getBool(_itemKey('skipSilence', itemId)) ?? false;
final bandStr = await ScopedPrefs.getString(_itemKey('bands', itemId));
if (bandStr != null) {
_bandLevels = bandStr.split(',').map((s) => double.tryParse(s) ?? 0.0).toList();
@@ -353,6 +387,7 @@ class EqualizerService extends ChangeNotifier {
await ScopedPrefs.setDouble(_itemKey('virtualizer', itemId), _virtualizer);
await ScopedPrefs.setDouble(_itemKey('loudnessGain', itemId), _loudnessGain);
await ScopedPrefs.setBool(_itemKey('mono', itemId), _mono);
+ await ScopedPrefs.setBool(_itemKey('skipSilence', itemId), _skipSilence);
await ScopedPrefs.setString(_itemKey('bands', itemId), _bandLevels.map((l) => l.toStringAsFixed(1)).join(','));
}
@@ -364,6 +399,7 @@ class EqualizerService extends ChangeNotifier {
_virtualizer = await ScopedPrefs.getDouble('eq_virtualizer') ?? 0.0;
_loudnessGain = await ScopedPrefs.getDouble('eq_loudnessGain') ?? 0.0;
_mono = await ScopedPrefs.getBool('eq_mono') ?? false;
+ _skipSilence = await ScopedPrefs.getBool('eq_skipSilence') ?? false;
final bandStr = await ScopedPrefs.getString('eq_bands');
if (bandStr != null) {
@@ -381,6 +417,7 @@ class EqualizerService extends ChangeNotifier {
Future<void> reloadForActiveAccount() async {
await _loadSettings();
_currentItemId = null;
+ _skipSilenceApplier?.call(_skipSilence);
if (_enabled) {
await _applyCurrentSettings();
} else {
@@ -396,6 +433,7 @@ class EqualizerService extends ChangeNotifier {
await ScopedPrefs.setDouble('eq_virtualizer', _virtualizer);
await ScopedPrefs.setDouble('eq_loudnessGain', _loudnessGain);
await ScopedPrefs.setBool('eq_mono', _mono);
+ await ScopedPrefs.setBool('eq_skipSilence', _skipSilence);
await ScopedPrefs.setString('eq_bands', _bandLevels.map((l) => l.toStringAsFixed(1)).join(','));
if (_perItem && _currentItemId != null) {
await _saveItemSettings(_currentItemId!);
diff --git a/lib/widgets/equalizer_sheet.dart b/lib/widgets/equalizer_sheet.dart
index 3dd7fef9..aa099226 100644
--- a/lib/widgets/equalizer_sheet.dart
+++ b/lib/widgets/equalizer_sheet.dart
@@ -59,6 +59,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {
List<double> _pBands = [];
double _pBass = 0.0, _pVirt = 0.0, _pLoud = 0.0;
bool _pMono = false;
+ bool _pSkipSilence = false;
@override
void initState() {
@@ -97,6 +98,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {
_pVirt = 0.0;
_pLoud = 0.0;
_pMono = false;
+ _pSkipSilence = false;
_loadPreview();
} else if (!shouldPreview && _previewMode) {
_previewMode = false;
@@ -116,6 +118,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {
_pVirt = snap['virtualizer'] as double;
_pLoud = snap['loudnessGain'] as double;
_pMono = snap['mono'] as bool;
+ _pSkipSilence = snap['skipSilence'] as bool? ?? false;
_pBands = List<double>.from((snap['bands'] as List).cast<double>());
_previewLoaded = true;
});
@@ -131,6 +134,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {
'virtualizer': _pVirt,
'loudnessGain': _pLoud,
'mono': _pMono,
+ 'skipSilence': _pSkipSilence,
'bands': _pBands,
});
}
@@ -143,6 +147,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {
double get _vVirt => _previewMode ? _pVirt : _eq.virtualizer;
double get _vLoud => _previewMode ? _pLoud : _eq.loudnessGain;
bool get _vMono => _previewMode ? _pMono : _eq.mono;
+ bool get _vSkipSilence => _previewMode ? _pSkipSilence : _eq.skipSilence;
void _setEnabled(bool v) {
if (_previewMode) {
@@ -219,6 +224,15 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {
}
}
+ void _setSkipSilence(bool v) {
+ if (_previewMode) {
+ setState(() => _pSkipSilence = v);
+ _savePreview();
+ } else {
+ _eq.setSkipSilence(v);
+ }
+ }
+
void _resetAll() {
if (_previewMode) {
setState(() {
@@ -228,6 +242,7 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {
_pVirt = 0.0;
_pLoud = 0.0;
_pMono = false;
+ _pSkipSilence = false;
});
_savePreview();
} else {
@@ -515,6 +530,39 @@ class _EqualizerSheetContentState extends State<_EqualizerSheetContent> {
),
),
+ // Skip silence (Android only - just_audio's setSkipSilenceEnabled
+ // is a no-op on iOS).
+ if (Platform.isAndroid) ...[
+ const SizedBox(height: 8),
+ Container(
+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
+ decoration: BoxDecoration(
+ color: cs.onSurface.withValues(alpha: 0.04),
+ borderRadius: BorderRadius.circular(14),
+ ),
+ child: Row(
+ children: [
+ Icon(Icons.fast_forward_rounded, size: 18,
+ color: _vSkipSilence ? accent.withValues(alpha: 0.7) : cs.onSurface.withValues(alpha: 0.2)),
+ const SizedBox(width: 10),
+ Expanded(
+ child: Text(l.skipSilence, style: TextStyle(
+ color: _vSkipSilence ? cs.onSurface.withValues(alpha: 0.7) : cs.onSurface.withValues(alpha: 0.24),
+ fontSize: 12, fontWeight: FontWeight.w500)),
+ ),
+ Transform.scale(
+ scale: 0.8,
+ child: Switch(
+ value: _vSkipSilence,
+ activeTrackColor: accent,
+ onChanged: (v) => _setSkipSilence(v),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ],
+
const SizedBox(height: 20),
// Reset button