Keep Apple TV awake during audio-only playback

Since b08974f4 audio-only playback re-enabled the idle timer on every
platform. On tvOS idle means screensaver and then device sleep, which
suspends the app, stops playback, and turns the TV off over HDMI-CEC.
Always prevent sleep while playing on tvOS; iOS and macOS still let the
screen sleep in audio mode.
This commit is contained in:
Arkadiusz Fal
2026-09-20 23:49:35 +02:00
parent 1ac35f2273
commit ea57378b00

View File

@@ -636,12 +636,20 @@ final class PlayerService {
/// Reconciles sleep prevention with what is actually on screen: display sleep
/// is only prevented when a video track is rendered. Audio-only playback
/// lets the screen sleep normally.
///
/// tvOS is the exception: idle there means screensaver and then device sleep,
/// which suspends the app, stops playback, and powers the TV off over CEC.
/// Audio-only playback must keep the idle timer disabled as well.
private func updateSleepPrevention() {
#if os(tvOS)
sleepPreventionService.preventSleep()
#else
if state.currentStream?.isAudioOnly == true {
sleepPreventionService.allowSleep()
} else {
sleepPreventionService.preventSleep()
}
#endif
}
/// Pauses playback.