Skip to main content
Namida’s sleep timer allows you to automatically stop playback after a set duration (minutes) or after a specified number of tracks, perfect for listening before bed or during focused work sessions.

Features

Time-Based Timer

Stop playback after a specified number of minutes

Track-Based Timer

Stop playback after a certain number of tracks

Flexible Controls

Enable one or both timer types simultaneously

Dynamic Adjustment

Modify timer settings while playback is active

Sleep Timer Types

Time-Based Timer

Pause playback after a specified duration in minutes.
// From audio_handler.dart
int get maximumSleepTimerMins => kMaximumSleepTimerMins; // 180 minutes (3 hours)
Configuration:
  • Minimum: 1 minute
  • Maximum: 180 minutes (3 hours)
  • Precision: 1-minute increments
1

Open Sleep Timer

Navigate to More → Sleep Timer from the main menu
2

Enable Time Timer

Toggle “Sleep after minutes”
3

Set Duration

Adjust the slider to your desired duration (1-180 minutes)
4

Start Playback

The timer begins counting down immediately

Track-Based Timer

Pause playback after a specified number of tracks have finished playing.
// From audio_handler.dart  
int get maximumSleepTimerItems => kMaximumSleepTimerTracks; // 40 tracks
Configuration:
  • Minimum: 1 track
  • Maximum: 40 tracks
  • Behavior: Counts tracks from current position forward
1

Open Sleep Timer

Navigate to More → Sleep Timer from the main menu
2

Enable Track Timer

Toggle “Sleep after tracks”
3

Set Track Count

Adjust the slider to your desired number of tracks (1-40)
4

Track Position

The timer shows which track will be the last to play
The track-based timer calculates the final track index from your current position. For example, if you’re on track 5 and set “sleep after 3 tracks”, playback will stop after track 7.

Using Sleep Timer

Opening the Dialog

Access the sleep timer dialog from multiple locations:
  • Main Menu: Tap More → Sleep Timer
  • Player Menu: Tap the menu icon in the player
  • Quick Access: Some queue screens include a sleep timer shortcut
// From main_page_wrapper.dart
static void openSleepTimerDialog(BuildContext context) {
  // Opens the sleep timer configuration dialog
}

Configuration Interface

The sleep timer dialog provides:
Sleep After Minutes
  • Toggle switch to enable/disable
  • Slider for duration (1-180 minutes)
  • Real-time display of remaining time
  • Clear indication when timer is active
Sleep After Tracks
  • Toggle switch to enable/disable
  • Slider for track count (1-40 tracks)
  • Display of final track index in queue
  • Queue position visualization

Sleep Timer State

The sleep timer maintains its configuration:
// From player_controller.dart
RxBaseCore<SleepTimerConfig> get sleepTimerConfig => _audioHandler.sleepTimerConfig;

void updateSleepTimerValues({
  bool? enableSleepAfterItems,
  bool? enableSleepAfterMins,
  int? sleepAfterMin,
  int? sleepAfterItems,
}) {
  _audioHandler.updateSleepTimerValues(
    enableSleepAfterItems: enableSleepAfterItems,
    enableSleepAfterMins: enableSleepAfterMins,
    sleepAfterMin: sleepAfterMin,
    sleepAfterItems: sleepAfterItems,
  );
}

Sleep Timer Behavior

Time-Based Timer Behavior

When the time-based timer expires:
  1. Countdown: Timer counts down in real-time
  2. Pause Trigger: When time reaches zero, playback pauses gracefully
  3. Current Track: The current track continues until the timer expires (doesn’t wait for track end)
  4. Fade Out: Respects pause fade duration settings
The time-based timer will pause immediately when the countdown reaches zero, even if a track is currently playing. This allows for precise timing control.

Track-Based Timer Behavior

When the track-based timer expires:
  1. Track Counting: Counts each completed track
  2. Final Track: Plays the specified final track completely
  3. Auto Pause: Pauses after the final track finishes
  4. Queue Position: Updates as queue changes
If you shuffle, reorder, or modify the queue while the track-based timer is active, the final track index is recalculated from the current position.

Combined Timers

You can enable both timer types simultaneously:
  • Whichever Comes First: Playback stops when either condition is met
  • Independent Tracking: Each timer operates independently
  • Status Display: Both timers show in the interface
1

Enable Both Timers

Toggle both “Sleep after minutes” and “Sleep after tracks”
2

Configure Each

Set different values for time and track counts
3

Monitoring

Watch both counters to see which will trigger first
4

Auto Pause

Playback stops when the first condition is met

Managing the Sleep Timer

Modifying Active Timer

You can adjust the sleep timer while it’s running:

Extend Time

Increase the duration or track count before it expires

Reduce Time

Decrease the duration or track count for earlier pause

Switch Types

Toggle between time-based and track-based modes

Cancel Timer

Disable both timers to continue playing indefinitely

Resetting the Timer

Reset the sleep timer to its initial state:
// From player_controller.dart
void resetSleepAfterTimer() {
  _audioHandler.resetSleepTimer();
}
1

Open Sleep Timer Dialog

Access the sleep timer settings
2

Disable All Timers

Toggle off both timer types
3

Restart if Needed

Re-enable and configure with new values

Quick Actions

Sleep After Current Track

Some contexts offer a quick “Sleep after 1 track” option:
// From yt_utils.dart and general_popup_dialog.dart
Player.inst.updateSleepTimerValues(
  enableSleepAfterItems: true, 
  sleepAfterItems: 1
);
This immediately sets the timer to pause after the current track finishes.
Quick actions are available in:
  • Track context menus
  • Player menu shortcuts
  • Video player controls
  • YouTube playback interface

Use Cases

Bedtime Listening

Set a 30-minute timer to fall asleep to music

Podcast Episodes

Set to pause after 2-3 episodes

Workout Sessions

Use 45-60 minute timer for gym playlists

Study Sessions

Pomodoro technique with 25-minute intervals

Best Practices

Time-Based Timer

  • Estimate Duration: Add a few extra minutes to avoid mid-track cuts
  • Battery Saving: Use shorter durations to save battery overnight
  • Check Remaining: Monitor the timer display before falling asleep

Track-Based Timer

  • Count Tracks: Check your queue length before setting count
  • Album Playback: Set timer to album length for complete albums
  • Dynamic Queues: Be aware that queue changes affect the final track

Combined Timers

  • Safety Net: Use time + tracks for flexible stopping
  • Long Playlists: Time prevents playing all night if you have many tracks
  • Short Tracks: Track count prevents stopping too soon on short songs
Common Mistakes to Avoid:
  • Setting timer after you start falling asleep (set it first!)
  • Forgetting to enable the timer toggle
  • Not accounting for queue shuffle/changes
  • Setting too short duration for album playback

Troubleshooting

Check:
  1. Timer toggle is enabled (blue/active state)
  2. Values are set correctly (not at minimum or maximum unexpectedly)
  3. Playback is active (timer only runs during playback)
  4. No other app is controlling audio focus
Possible Causes:
  • Time-based timer set too short
  • Track-based count doesn’t account for short tracks
  • Queue was modified after setting timer
Solutions:
  • Increase time/track count
  • Verify queue contents before setting
  • Add buffer time/tracks
Possible Causes:
  • Timer was disabled or reset
  • App was force-closed (interrupts timer)
  • System killed background process
Solutions:
  • Re-enable timer
  • Keep app in background (don’t force-close)
  • Disable aggressive battery optimization for Namida

Advanced Features

Sleep Timer Index Calculation

For track-based timers, the final track index is calculated:
// From player_controller.dart
int sleepingItemIndex(int sleepAfterItems, int currentIndex) {
  return sleepAfterItems + currentIndex - 1;
}
Example:
  • Current track: #5
  • Sleep after: 3 tracks
  • Final track: 5 + 3 - 1 = #7

Integration with Queue

The sleep timer integrates with Namida’s queue system:
  • Respects Queue Order: Follows your queue exactly
  • Shuffle Compatible: Works with shuffle mode
  • Repeat Aware: Accounts for repeat settings
  • Dynamic Updates: Adjusts to queue modifications
When using “Repeat One” mode with a track-based timer, the same track counts toward the timer each time it repeats.

Tips & Tricks

Extend Before Expiry

Re-open the dialog to add more time before it expires

Quick Sleep

Use track count of 1 for instant “stop after current”

Battery Saver

Enable timer to prevent all-night playback draining battery

Habit Formation

Use consistent timer durations to build healthy listening habits

Build docs developers (and LLMs) love