A cross platform Audiobookshelf client for Android and iOS
Dart
Customizable playback speed presets
Nathan Poulson400e5f17d897
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arbindex 36dcd641..e436d141 100644--- a/lib/l10n/app_en.arb+++ b/lib/l10n/app_en.arb@@ -1624,5 +1624,8 @@"androidAutoCatAuthors": "Authors","showTipsAgain": "Show tips again","showTipsAgainSubtitle": "Bring back feature tips you've dismissed",- "tipsRestored": "Tips restored"+ "tipsRestored": "Tips restored",+ "resetSpeedPresets": "Reset speed presets",+ "resetSpeedPresetsSubtitle": "Restore the default playback speed chips",+ "speedPresetsReset": "Speed presets reset"}diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dartindex e8e5da97..0ce7ae7b 100644--- a/lib/l10n/app_localizations.dart+++ b/lib/l10n/app_localizations.dart@@ -8061,6 +8061,24 @@ abstract class AppLocalizations {/// In en, this message translates to:/// **'Tips restored'**String get tipsRestored;++ /// No description provided for @resetSpeedPresets.+ ///+ /// In en, this message translates to:+ /// **'Reset speed presets'**+ String get resetSpeedPresets;++ /// No description provided for @resetSpeedPresetsSubtitle.+ ///+ /// In en, this message translates to:+ /// **'Restore the default playback speed chips'**+ String get resetSpeedPresetsSubtitle;++ /// No description provided for @speedPresetsReset.+ ///+ /// In en, this message translates to:+ /// **'Speed presets reset'**+ String get speedPresetsReset;}class _AppLocalizationsDelegatediff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dartindex 5f2ef354..860c72c2 100644--- a/lib/l10n/app_localizations_en.dart+++ b/lib/l10n/app_localizations_en.dart@@ -4668,4 +4668,14 @@ class AppLocalizationsEn extends AppLocalizations {@overrideString get tipsRestored => 'Tips restored';++ @override+ String get resetSpeedPresets => 'Reset speed presets';++ @override+ String get resetSpeedPresetsSubtitle =>+ 'Restore the default playback speed chips';++ @override+ String get speedPresetsReset => 'Speed presets reset';}diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dartindex 97d56ff1..27e6720a 100644--- a/lib/l10n/app_localizations_zh.dart+++ b/lib/l10n/app_localizations_zh.dart@@ -4592,4 +4592,13 @@ class AppLocalizationsZh extends AppLocalizations {@overrideString get tipsRestored => '已恢复提示';++ @override+ String get resetSpeedPresets => '重置速度预设';++ @override+ String get resetSpeedPresetsSubtitle => '恢复默认的播放速度选项';++ @override+ String get speedPresetsReset => '速度预设已重置';}diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arbindex a5502240..42001cd3 100644--- a/lib/l10n/app_zh.arb+++ b/lib/l10n/app_zh.arb@@ -802,5 +802,8 @@"openLibrary": "打开媒体库","showTipsAgain": "再次显示提示","showTipsAgainSubtitle": "恢复你已关闭的功能提示",- "tipsRestored": "已恢复提示"+ "tipsRestored": "已恢复提示",+ "resetSpeedPresets": "重置速度预设",+ "resetSpeedPresetsSubtitle": "恢复默认的播放速度选项",+ "speedPresetsReset": "速度预设已重置"}diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dartindex 157d369d..7bf09e36 100644--- a/lib/screens/settings_screen.dart+++ b/lib/screens/settings_screen.dart@@ -915,6 +915,19 @@ class _SettingsScreenState extends State<SettingsScreen> {),),const Divider(height: 1, indent: 16, endIndent: 16),+ ListTile(+ leading: Icon(Icons.refresh_rounded, color: cs.onSurfaceVariant),+ title: Text(l.resetSpeedPresets),+ subtitle: Text(l.resetSpeedPresetsSubtitle,+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),+ onTap: () async {+ await PlayerSettings.resetSpeedPresets();+ if (!mounted) return;+ showOverlayToast(context, l.speedPresetsReset,+ icon: Icons.refresh_rounded);+ },+ ),+ const Divider(height: 1, indent: 16, endIndent: 16),// Skip amountsPadding(padding: const EdgeInsets.fromLTRB(16, 12, 16, 4),diff --git a/lib/services/player_settings.dart b/lib/services/player_settings.dartindex a04ec7f4..9aea9b73 100644--- a/lib/services/player_settings.dart+++ b/lib/services/player_settings.dart@@ -90,6 +90,30 @@ class PlayerSettings {static Future<double> getDefaultSpeed() => _get('defaultSpeed', 1.0);static Future<void> setDefaultSpeed(double speed) => _set('defaultSpeed', speed);+ static const List<double> defaultSpeedPresets = [0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5];++ static Future<List<double>> getSpeedPresets() async {+ final raw = await _get('speedPresets', '');+ if (raw.isEmpty) return List<double>.from(defaultSpeedPresets);+ final parsed = <double>[];+ for (final part in raw.split(',')) {+ final v = double.tryParse(part);+ if (v != null) parsed.add(v);+ }+ if (parsed.isEmpty) return List<double>.from(defaultSpeedPresets);+ parsed.sort();+ return parsed;+ }++ static Future<void> setSpeedPresets(List<double> presets) async {+ final sorted = [...presets]..sort();+ await _set('speedPresets', sorted.map((s) => s.toStringAsFixed(2)).join(','), notify: true);+ }++ static Future<void> resetSpeedPresets() async {+ await _set('speedPresets', '', notify: true);+ }+/// Audible region override for Find Missing Books (e.g. "us", "uk", "de")./// Empty string means use device locale.static Future<String> getAudibleRegion() => _get('audibleRegion', '');diff --git a/lib/widgets/card_buttons.dart b/lib/widgets/card_buttons.dartindex b4e8a65c..d990119a 100644--- a/lib/widgets/card_buttons.dart+++ b/lib/widgets/card_buttons.dart@@ -23,6 +23,7 @@ import 'chromecast_button.dart';import 'episode_detail_sheet.dart';import 'episode_list_sheet.dart';import 'equalizer_sheet.dart';+import 'feature_hint.dart';import 'notes_sheet.dart';import 'overlay_toast.dart';import 'sleep_timer_sheet.dart';@@ -605,7 +606,7 @@ class CardSpeedSheet extends StatefulWidget {class _CardSpeedSheetState extends State<CardSpeedSheet> {late double _speed;- static const _presets = [0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.5];+ List<double> _presets = List<double>.from(PlayerSettings.defaultSpeedPresets);bool get _isCasting {final cast = ChromecastService();@@ -617,6 +618,30 @@ class _CardSpeedSheetState extends State<CardSpeedSheet> {final initialSpeed = _isCasting ? ChromecastService().castSpeed : widget.player.speed;_speed = (initialSpeed * 20).round() / 20.0;if (!widget.player.hasBook && !_isCasting) _loadSavedSpeed();+ _loadPresets();+ PlayerSettings.settingsChanged.addListener(_loadPresets);+ }++ @override void dispose() {+ PlayerSettings.settingsChanged.removeListener(_loadPresets);+ super.dispose();+ }++ Future<void> _loadPresets() async {+ final presets = await PlayerSettings.getSpeedPresets();+ if (mounted) setState(() => _presets = presets);+ }++ Future<void> _addCurrentAsPreset() async {+ if (_presets.any((p) => (p - _speed).abs() < 0.01)) return;+ final next = [..._presets, _speed];+ await PlayerSettings.setSpeedPresets(next);+ }++ Future<void> _removePreset(double value) async {+ if (_presets.length <= 1) return;+ final next = _presets.where((p) => (p - value).abs() >= 0.01).toList();+ await PlayerSettings.setSpeedPresets(next);}Future<void> _loadSavedSpeed() async {@@ -654,17 +679,41 @@ class _CardSpeedSheetState extends State<CardSpeedSheet> {Text(l.playbackSpeed, style: tt.titleMedium?.copyWith(fontWeight: FontWeight.w600)),const SizedBox(height: 4),Text('${_speed.toStringAsFixed(2)}x', style: tt.headlineMedium?.copyWith(fontWeight: FontWeight.w700, color: widget.accent)),- const SizedBox(height: 16),- Wrap(spacing: 8, runSpacing: 8, alignment: WrapAlignment.center, children: _presets.map((s) {- final a = (_speed - s).abs() < 0.01;- return GestureDetector(onTap: () => _setSpeed(s), child: AnimatedContainer(- duration: const Duration(milliseconds: 150),- padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),- decoration: BoxDecoration(color: a ? widget.accent : Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.08), borderRadius: BorderRadius.circular(20),- border: Border.all(color: a ? widget.accent : Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.12))),- child: Text('${s}x', style: TextStyle(color: a ? Theme.of(context).colorScheme.surface : Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.7), fontSize: 13, fontWeight: a ? FontWeight.w700 : FontWeight.w500)),- ));- }).toList()),+ const SizedBox(height: 12),+ const FeatureHint(+ prefKey: 'hint_speed_presets',+ message: 'Tap + to save the current speed as a preset. Long-press a chip to remove it.',+ padding: EdgeInsets.fromLTRB(0, 0, 0, 12),+ ),+ Wrap(spacing: 8, runSpacing: 8, alignment: WrapAlignment.center, children: [+ ..._presets.map((s) {+ final a = (_speed - s).abs() < 0.01;+ final canRemove = _presets.length > 1;+ return GestureDetector(+ onTap: () => _setSpeed(s),+ onLongPress: canRemove ? () => _removePreset(s) : null,+ child: AnimatedContainer(+ duration: const Duration(milliseconds: 150),+ padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),+ decoration: BoxDecoration(color: a ? widget.accent : Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.08), borderRadius: BorderRadius.circular(20),+ border: Border.all(color: a ? widget.accent : Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.12))),+ child: Text('${s}x', style: TextStyle(color: a ? Theme.of(context).colorScheme.surface : Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.7), fontSize: 13, fontWeight: a ? FontWeight.w700 : FontWeight.w500)),+ ),+ );+ }),+ GestureDetector(+ onTap: _addCurrentAsPreset,+ child: Container(+ padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),+ decoration: BoxDecoration(+ color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.04),+ borderRadius: BorderRadius.circular(20),+ border: Border.all(color: widget.accent.withValues(alpha: 0.4), style: BorderStyle.solid),+ ),+ child: Icon(Icons.add_rounded, size: 16, color: widget.accent),+ ),+ ),+ ]),const SizedBox(height: 16),Row(children: [GestureDetector(