Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add a seek bar lock and a Media Controls settings section

Barnabas3e8e89c780bd
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index 8de0602c..e11571c6 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -67,6 +67,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
bool _showBookSlider = false;
bool _notifChapterProgress = false;
bool _notifSpeedBookmark = false;
+ bool _lockSeekBar = false;
bool _speedAdjustedTime = true;
int _forwardSkip = 30;
int _backSkip = 10;
@@ -339,7 +340,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
PlayerSettings.getClassicWording(), // 50
PlayerSettings.getQueuePlaylistId(), // 51
PlayerSettings.getMediaControlsSpeedBookmark(), // 52
- PlayerSettings.getProgressTextScale(), // 53
+ PlayerSettings.getLockSeekBar(), // 53
+ PlayerSettings.getProgressTextScale(), // 54
]);
final s = results[0] as AutoRewindSettings;
final progressScale = results.last as double;
@@ -392,6 +394,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
final classicWording = results[47] as bool;
final qpId = results[48] as String?;
final notifSpeedBookmark = results[49] as bool;
+ final lockSeek = results[50] as bool;
final rmabBaseUrl = await ScopedPrefs.getString(kRmabBaseUrlKey);
final rmabApiToken = await ScopedPrefs.getString(kRmabApiTokenKey);
final sleepRewind = await PlayerSettings.getSleepRewindSeconds();
@@ -408,6 +411,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
_showBookSlider = bookSlider;
_notifChapterProgress = notifChapter;
_notifSpeedBookmark = notifSpeedBookmark;
+ _lockSeekBar = lockSeek;
_speedAdjustedTime = speedAdj;
_forwardSkip = fwd;
_backSkip = bk;
@@ -1343,42 +1347,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
} : null,
),
const Divider(height: 1, indent: 16, endIndent: 16),
- SwitchListTile(
- title: Text(Platform.isIOS
- ? l.chapterProgressInNotificationIos
- : l.chapterProgressInNotification),
- subtitle: Text(
- _notifChapterProgress
- ? (Platform.isIOS
- ? l.chapterProgressOnSubtitleIos
- : l.chapterProgressOnSubtitle)
- : l.chapterProgressOffSubtitle,
- style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
- value: _notifChapterProgress,
- onChanged: _loaded ? (v) {
- setState(() => _notifChapterProgress = v);
- PlayerSettings.setNotificationChapterProgress(v);
- } : null,
- ),
- // Android only: chooses which pair fills the phone media
- // player's two extra slots. iOS uses CarPlay's own buttons.
- if (Platform.isAndroid) ...[
- const Divider(height: 1, indent: 16, endIndent: 16),
- SwitchListTile(
- title: Text(l.speedBookmarkInControls),
- subtitle: Text(
- _notifSpeedBookmark
- ? l.speedBookmarkOnSubtitle
- : l.speedBookmarkOffSubtitle,
- style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
- value: _notifSpeedBookmark,
- onChanged: _loaded ? (v) {
- setState(() => _notifSpeedBookmark = v);
- PlayerSettings.setMediaControlsSpeedBookmark(v);
- } : null,
- ),
- ],
- const Divider(height: 1, indent: 16, endIndent: 16),
// ── Auto-Rewind ──
SwitchListTile(
title: Text(l.autoRewindOnResume),
@@ -1529,6 +1497,68 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
const SizedBox(height: 16),
+ // ── Media Controls ──
+ CollapsibleSection(
+ key: _keyFor('Media Controls'),
+ icon: Icons.dvr_rounded,
+ title: l.sectionMediaControls,
+ cs: cs,
+ isExpanded: _expandedSection == 'Media Controls',
+ onExpansionChanged: (v) => _onSectionExpanded('Media Controls', v),
+ children: [
+ SwitchListTile(
+ title: Text(Platform.isIOS
+ ? l.chapterProgressInNotificationIos
+ : l.chapterProgressInNotification),
+ subtitle: Text(
+ _notifChapterProgress
+ ? (Platform.isIOS
+ ? l.chapterProgressOnSubtitleIos
+ : l.chapterProgressOnSubtitle)
+ : l.chapterProgressOffSubtitle,
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ value: _notifChapterProgress,
+ onChanged: _loaded ? (v) {
+ setState(() => _notifChapterProgress = v);
+ PlayerSettings.setNotificationChapterProgress(v);
+ } : null,
+ ),
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ // Cross-platform: drops the seek action so the scrubber in the
+ // notification / lockscreen / car can't be dragged.
+ SwitchListTile(
+ title: Text(l.lockSeekBar),
+ subtitle: Text(
+ _lockSeekBar ? l.lockSeekBarOnSubtitle : l.lockSeekBarOffSubtitle,
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ value: _lockSeekBar,
+ onChanged: _loaded ? (v) {
+ setState(() => _lockSeekBar = v);
+ PlayerSettings.setLockSeekBar(v);
+ } : null,
+ ),
+ // Android only: chooses which pair fills the phone media
+ // player's two extra slots. iOS uses CarPlay's own buttons.
+ if (Platform.isAndroid) ...[
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ SwitchListTile(
+ title: Text(l.speedBookmarkInControls),
+ subtitle: Text(
+ _notifSpeedBookmark
+ ? l.speedBookmarkOnSubtitle
+ : l.speedBookmarkOffSubtitle,
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ value: _notifSpeedBookmark,
+ onChanged: _loaded ? (v) {
+ setState(() => _notifSpeedBookmark = v);
+ PlayerSettings.setMediaControlsSpeedBookmark(v);
+ } : null,
+ ),
+ ],
+ ],
+ ),
+ const SizedBox(height: 16),
+
// ── Sleep Timer ──
CollapsibleSection(
key: _keyFor('Sleep Timer'),
@@ -3073,6 +3103,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
final otherAccounts = accounts.where((a) =>
!(a.serverUrl == auth.serverUrl && a.username == auth.username)
).toList();
+ SavedAccount? activeAccount;
+ for (final a in accounts) {
+ if (a.serverUrl == auth.serverUrl && a.username == auth.username) {
+ activeAccount = a;
+ break;
+ }
+ }
final shortServer = auth.serverUrl?.replaceAll(RegExp(r'^https?://'), '').replaceAll(RegExp(r'/+$'), '') ?? '';
final userType = auth.isRoot ? l.rootAdmin : auth.isAdmin ? l.admin : l.userFallback;
@@ -3103,6 +3140,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
const SizedBox(width: 6),
Expanded(child: Text(shortServer, style: tt.labelSmall?.copyWith(
color: cs.onSurfaceVariant.withValues(alpha: 0.5)), maxLines: 1, overflow: TextOverflow.ellipsis)),
+ if (activeAccount != null)
+ InkResponse(
+ onTap: () { Navigator.pop(ctx); _editServerUrl(context, activeAccount!); },
+ radius: 22,
+ child: Padding(padding: const EdgeInsets.all(6),
+ child: Icon(Icons.edit_rounded, size: 18, color: cs.onSurfaceVariant.withValues(alpha: 0.7))),
+ ),
]),
const SizedBox(height: 3),
Row(children: [
@@ -3143,7 +3187,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
.replaceAll(RegExp(r'/+$'), '');
return InkWell(
onTap: () { Navigator.pop(ctx); _switchAccount(context, account); },
- onLongPress: () { Navigator.pop(ctx); _removeAccount(context, account); },
+ onLongPress: () { Navigator.pop(ctx); _accountOptions(context, account); },
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Row(children: [
@@ -3274,6 +3318,88 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
}
+ /// Long-press menu for a saved (non-active) account: edit its server
+ /// address or remove it.
+ void _accountOptions(BuildContext context, SavedAccount account) {
+ final cs = Theme.of(context).colorScheme;
+ final l = AppLocalizations.of(context)!;
+ showModalBottomSheet(
+ context: context,
+ backgroundColor: cs.surfaceContainerHigh,
+ shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
+ builder: (ctx) => SafeArea(child: Column(mainAxisSize: MainAxisSize.min, children: [
+ const SizedBox(height: 10),
+ Center(child: Container(width: 36, height: 4,
+ decoration: BoxDecoration(color: cs.onSurface.withValues(alpha: 0.12), borderRadius: BorderRadius.circular(2)))),
+ const SizedBox(height: 8),
+ ListTile(
+ leading: Icon(Icons.dns_rounded, color: cs.primary),
+ title: Text(l.editServerAddressAction),
+ onTap: () { Navigator.pop(ctx); _editServerUrl(context, account); }),
+ ListTile(
+ leading: Icon(Icons.delete_outline_rounded, color: cs.error),
+ title: Text(l.removeAccountAction, style: TextStyle(color: cs.error)),
+ onTap: () { Navigator.pop(ctx); _removeAccount(context, account); }),
+ const SizedBox(height: 8),
+ ])),
+ );
+ }
+
+ /// Edit the server URL of a saved account in place (dynamic-DNS hostname
+ /// changed, etc.) without losing the account's data. See
+ /// [AuthProvider.editServerUrl].
+ void _editServerUrl(BuildContext context, SavedAccount account) {
+ final l = AppLocalizations.of(context)!;
+ final ctrl = TextEditingController(text: account.serverUrl);
+ showDialog(
+ context: context,
+ builder: (ctx) {
+ final cs = Theme.of(ctx).colorScheme;
+ return AlertDialog(
+ title: Text(l.editServerAddressTitle),
+ content: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(l.editServerAddressSubtitle(account.username),
+ style: Theme.of(ctx).textTheme.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ const SizedBox(height: 14),
+ TextField(
+ controller: ctrl,
+ autofocus: true,
+ keyboardType: TextInputType.url,
+ autocorrect: false,
+ decoration: InputDecoration(
+ labelText: l.editServerAddressField,
+ hintText: 'https://example.com',
+ border: const OutlineInputBorder()),
+ ),
+ ]),
+ actions: [
+ TextButton(onPressed: () => Navigator.pop(ctx), child: Text(l.cancel)),
+ FilledButton(
+ onPressed: () async {
+ final newUrl = ctrl.text.trim();
+ Navigator.pop(ctx);
+ if (newUrl.isEmpty) return;
+ final auth = context.read<AuthProvider>();
+ final wasActive = account.serverUrl == auth.serverUrl && account.username == auth.username;
+ final ok = await auth.editServerUrl(account, newUrl);
+ if (!context.mounted) return;
+ // Re-pull the active library from the new address.
+ if (ok && wasActive) context.read<LibraryProvider>().refresh();
+ if (context.mounted) setState(() {});
+ ScaffoldMessenger.of(context)
+ ..clearSnackBars()
+ ..showSnackBar(SnackBar(
+ content: Text(ok ? l.editServerAddressUpdated : l.editServerAddressFailed),
+ behavior: SnackBarBehavior.floating,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12))));
+ },
+ child: Text(l.save)),
+ ],
+ );
+ },
+ );
+ }
+
void _removeAccount(BuildContext context, SavedAccount account) async {
final l = AppLocalizations.of(context)!;
final confirmed = await showDialog<bool>(
diff --git a/lib/services/audio_player_service.dart b/lib/services/audio_player_service.dart
index 69ab48ea..591ccd4d 100644
--- a/lib/services/audio_player_service.dart
+++ b/lib/services/audio_player_service.dart
@@ -59,6 +59,9 @@ class AudioPlayerHandler extends BaseAudioHandler with SeekHandler {
// bookmark (true) or chapter skip (false). Android Auto shows all of them
// regardless. See PlayerSettings.getMediaControlsSpeedBookmark.
bool _cachedNotifSpeedBookmark = false;
+ // When true, the system scrubber is non-draggable (seek action dropped from
+ // the playback state). See PlayerSettings.getLockSeekBar.
+ bool _cachedLockSeekBar = false;
AudioPlayer get player => _player;
@@ -262,7 +265,10 @@ class AudioPlayerHandler extends BaseAudioHandler with SeekHandler {
controls: controls,
// iOS-only: declaring on Android adds prev/next buttons to the notification.
systemActions: {
- MediaAction.seek,
+ // Dropping seek locks the scrubber: Android omits ACTION_SEEK_TO and iOS
+ // omits changePlaybackPositionCommand, so it shows progress but can't be
+ // dragged. The skip (rewind/forward) buttons stay functional.
+ if (!_cachedLockSeekBar) MediaAction.seek,
MediaAction.seekForward,
MediaAction.seekBackward,
MediaAction.skipToQueueItem,
@@ -1219,6 +1225,12 @@ class AudioPlayerService extends ChangeNotifier {
_handler!.refreshPlaybackState();
}
});
+ PlayerSettings.getLockSeekBar().then((v) {
+ if (_handler != null && v != _handler!._cachedLockSeekBar) {
+ _handler!._cachedLockSeekBar = v;
+ _handler!.refreshPlaybackState();
+ }
+ });
}
/// The last seek target in seconds (absolute book position).
@@ -1883,6 +1895,7 @@ class AudioPlayerService extends ChangeNotifier {
_handler!._cachedBackSkip = backSkip;
_handler!._cachedNotifSpeedBookmark =
await PlayerSettings.getMediaControlsSpeedBookmark();
+ _handler!._cachedLockSeekBar = await PlayerSettings.getLockSeekBar();
debugPrint('[Player] AudioService initialized');
// Configure streaming cache if enabled
final cacheSizeMb = await PlayerSettings.getStreamingCacheSizeMb();
diff --git a/lib/services/player_settings.dart b/lib/services/player_settings.dart
index bcc68d07..1fcb78f4 100644
--- a/lib/services/player_settings.dart
+++ b/lib/services/player_settings.dart
@@ -278,6 +278,14 @@ class PlayerSettings {
static Future<bool> getMediaControlsSpeedBookmark() => _get('mediaControlsSpeedBookmark', false);
static Future<void> setMediaControlsSpeedBookmark(bool value) => _set('mediaControlsSpeedBookmark', value, notify: true);
+ // When true, the system media scrubber still shows progress but can't be
+ // dragged to seek - stops accidental position jumps from the notification,
+ // lockscreen, Android Auto and CarPlay. Implemented by dropping the seek
+ // action from the playback state (Android ACTION_SEEK_TO / iOS
+ // changePlaybackPositionCommand). Default off.
+ static Future<bool> getLockSeekBar() => _get('lockSeekBar', false);
+ static Future<void> setLockSeekBar(bool value) => _set('lockSeekBar', value, notify: true);
+
// ── Sleep timer settings ──
// 'off', 'addTime', 'resetTimer'