features/sleepTimer
clearSleepTimer()
function clearSleepTimer(): boolean;Clears the active sleep timer.
Returns
boolean
true if a timer was cleared, false if no timer was active
useSleepTimer()
function useSleepTimer(params?): SleepTimerState | undefined;Hook that returns the current sleep timer state and time left.
Note that time left is not updated when the app is in the background.
Parameters
| Parameter | Type | Description |
|---|---|---|
params? | { updateInterval?: number; inactive?: boolean; } | Optional configuration object |
params.updateInterval? | number | ms interval at which the time left is updated. Defaults to 1000 (1 second). |
params.inactive? | boolean | Whether the app is in the background. If true, time left updates are paused. |
Returns
SleepTimerState | undefined
The current sleep timer state with secondsLeft calculated
getSleepTimer()
function getSleepTimer(): SleepTimer;Gets the current sleep timer state.
Returns
setSleepTimer()
function setSleepTimer(seconds): void;Sets a sleep timer to stop playback after the specified duration.
Parameters
| Parameter | Type | Description |
|---|---|---|
seconds | number | Number of seconds until playback stops |
Returns
void
onSleepTimerChanged
const onSleepTimerChanged: NativeUpdatedValue<SleepTimer>;Subscribes to sleep timer changes.
Param
Called when the sleep timer state changes
Returns
Cleanup function to unsubscribe
SleepTimer
type SleepTimer =
| SleepTimerTime
| SleepTimerEndOfTrack
| null;Sleep timer configuration:
SleepTimerTime: Stop playback after a specific timeSleepTimerEndOfTrack: Stop playback after current track finishesnull: No sleep timer active
useSleepTimerActive()
function useSleepTimerActive(): boolean;Hook that returns whether a sleep timer is currently active. This is a lightweight alternative to useSleepTimer when you only need to know if a timer is set.
Returns
boolean
true if any sleep timer is active, false otherwise
SleepTimerEndOfTrack
type SleepTimerEndOfTrack = object;End-of-track sleep timer that stops playback when current track finishes.
Properties
sleepWhenPlayedToEnd
sleepWhenPlayedToEnd: boolean;Whether to sleep when current track finishes playing
SleepTimerState
type SleepTimerState =
| {
time: number;
secondsLeft: number;
}
| {
sleepWhenPlayedToEnd: boolean;
};State returned by useSleepTimer hook.
- Time-based timer includes
secondsLeftcountdown - End-of-track timer includes
sleepWhenPlayedToEndflag
SleepTimerTime
type SleepTimerTime = object;Time-based sleep timer that stops playback after a specific time.
Properties
time
time: number;Time when playback should stop (milliseconds since epoch)
setSleepTimerToEndOfTrack()
function setSleepTimerToEndOfTrack(): void;Sets a sleep timer to stop playback when the current track finishes playing.
Returns
void
SleepTimerChangedEvent
type SleepTimerChangedEvent = SleepTimer;