Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add chapter barrier setting for auto-rewind

Nathan Poulsonf89ac47f8717
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index c3bab9fd..80d66a63 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -68,6 +68,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
bool _fullScreenPlayer = false;
String _cardButtonLayout = 'standard';
bool _snappyTransitions = false;
+ bool _rectangleCovers = false;
String _themeMode = 'dark';
String _colorSource = 'wallpaper';
int _startScreen = 2;
@@ -161,6 +162,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
PlayerSettings.getStartScreen(), // 36
PlayerSettings.getPodcastQueueMode(), // 37
PlayerSettings.getCardButtonLayout(), // 38
+ PlayerSettings.getRectangleCovers(), // 39
]);
final s = results[0] as AutoRewindSettings;
final speed = results[1] as double;
@@ -201,6 +203,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
final startScreen = results[36] as int;
final podcastQueueMode = results[37] as String;
final cardBtnLayout = results[38] as String;
+ final rectCovers = results[39] as bool;
if (mounted) setState(() {
_rewindSettings = s;
_defaultSpeed = speed;
@@ -245,6 +248,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
_disableAudioFocus = audioFocusOff;
_startScreen = startScreen;
_cardButtonLayout = cardBtnLayout;
+ _rectangleCovers = rectCovers;
_loaded = true;
});
}
@@ -689,6 +693,18 @@ class _SettingsScreenState extends State<SettingsScreen> {
snappyTransitionsNotifier.value = v;
} : null,
),
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ SwitchListTile(
+ title: const Text('Rectangle book covers'),
+ subtitle: Text(
+ _rectangleCovers ? 'Covers display in 2:3 book proportion' : 'Covers are square',
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ value: _rectangleCovers,
+ onChanged: _loaded ? (v) {
+ setState(() => _rectangleCovers = v);
+ PlayerSettings.setRectangleCovers(v);
+ } : null,
+ ),
],
),
const SizedBox(height: 16),
@@ -1113,6 +1129,21 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant, fontSize: 11)),
),
const Divider(height: 1, indent: 16, endIndent: 16),
+ SwitchListTile(
+ title: const Text('Chapter barrier'),
+ subtitle: Text(
+ "Don't rewind past the start of the current chapter",
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ value: _rewindSettings.chapterBarrier,
+ onChanged: (v) => _saveRewind(AutoRewindSettings(
+ enabled: true,
+ minRewind: _rewindSettings.minRewind,
+ maxRewind: _rewindSettings.maxRewind,
+ activationDelay: _rewindSettings.activationDelay,
+ chapterBarrier: v,
+ )),
+ ),
+ const Divider(height: 1, indent: 16, endIndent: 16),
Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 16, 12),
child: Container(
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dart
index ecd61eee..b4ea856f 100644
--- a/lib/services/audio_player_service.dart
+++ b/lib/services/audio_player_service.dart
@@ -25,12 +25,14 @@ class AutoRewindSettings {
final double minRewind;
final double maxRewind;
final double activationDelay; // seconds — how long pause must be before rewind kicks in
+ final bool chapterBarrier; // don't rewind past the start of the current chapter
const AutoRewindSettings({
this.enabled = true,
this.minRewind = 1.0,
this.maxRewind = 30.0,
this.activationDelay = 0.0, // 0 = always rewind on resume
+ this.chapterBarrier = false,
});
static Future<AutoRewindSettings> load() async {
@@ -39,6 +41,7 @@ class AutoRewindSettings {
minRewind: await ScopedPrefs.getDouble('autoRewind_min') ?? 1.0,
maxRewind: await ScopedPrefs.getDouble('autoRewind_max') ?? 30.0,
activationDelay: await ScopedPrefs.getDouble('autoRewind_delay') ?? 0.0,
+ chapterBarrier: await ScopedPrefs.getBool('autoRewind_chapterBarrier') ?? false,
);
}
@@ -47,6 +50,7 @@ class AutoRewindSettings {
await ScopedPrefs.setDouble('autoRewind_min', minRewind);
await ScopedPrefs.setDouble('autoRewind_max', maxRewind);
await ScopedPrefs.setDouble('autoRewind_delay', activationDelay);
+ await ScopedPrefs.setBool('autoRewind_chapterBarrier', chapterBarrier);
}
}
@@ -274,6 +278,9 @@ class PlayerSettings {
static Future<bool> getSnappyTransitions() => _get('snappyTransitions', false);
static Future<void> setSnappyTransitions(bool value) => _set('snappyTransitions', value);
+ static Future<bool> getRectangleCovers() => _get('rectangleCovers', false);
+ static Future<void> setRectangleCovers(bool value) => _set('rectangleCovers', value, notify: true);
+
// ── Audio focus ──
static Future<bool> getDisableAudioFocus() => _get('disableAudioFocus', false);
@@ -2332,6 +2339,17 @@ class AudioPlayerService extends ChangeNotifier {
final currentAbsolutePos = position.inMilliseconds / 1000.0;
var newPosSeconds = currentAbsolutePos - rewindSeconds;
if (newPosSeconds < 0) newPosSeconds = 0;
+ // Chapter barrier: don't rewind past the current chapter start
+ if (settings.chapterBarrier && _chapters.isNotEmpty) {
+ for (final ch in _chapters) {
+ final start = (ch['start'] as num?)?.toDouble() ?? 0;
+ final end = (ch['end'] as num?)?.toDouble() ?? 0;
+ if (currentAbsolutePos >= start && currentAbsolutePos < end) {
+ if (newPosSeconds < start) newPosSeconds = start;
+ break;
+ }
+ }
+ }
await _seekAbsolute(newPosSeconds);
_logEvent(PlaybackEventType.autoRewind,
detail: '${rewindSeconds.toStringAsFixed(1)}s rewind');