Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop audio while in background

There is an app called IHeartRadio which lets you set a sleep timer which will shut off audio after a specified interval.

You first choose a station to listen to and then select an amount of time to sleep after which the radio station will stop playing. The app does not need to be in the foreground for this to happen.

How is it possible for an app to stop audio while it is in the background?

One theory was to set a UILocalNotification with silent audio. Then the UILocalNotification would take over the audio of the device, in effect silencing whatever audio was playing. That didn't work.

Timers don't work in the background, which doesn't leave much in terms of time-based behavior in the background.

like image 686
ari gold Avatar asked Feb 19 '26 09:02

ari gold


1 Answers

When the UIBackgroundModes key contains the audio value, the system’s media frameworks automatically prevent the corresponding app from being suspended when it moves to the background. As long as it is playing audio or video content, the app continues to run in the background. However, if the app stops playing the audio or video, the system suspends it.

From iOS App Programming Guide.

like image 81
mbuc91 Avatar answered Feb 20 '26 22:02

mbuc91