3

有一个名为 IHeartRadio 的应用程序可让您设置睡眠计时器,该计时器将在指定时间间隔后关闭音频。

您首先选择要收听的电台,然后选择广播电台停止播放的睡眠时间。该应用程序不需要在前台发生这种情况。

应用程序如何在后台停止音频?

一种理论是设置带有静音音频的 UILocalNotification。然后 UILocalNotification 将接管设备的音频,实际上使正在播放的任何音频静音。那没有用。

计时器不在后台工作,这在后台基于时间的行为方面并没有留下太多。

4

2 回答 2

1

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.

来自iOS 应用程序编程指南

于 2013-04-10T21:37:39.270 回答
0

您可以applicationDidEnterBackground在您的事件中使用事件AppDelegate来处理应用程序进入后台并在此方法中停止音频。

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

    // add your audio stopping code ..
}
于 2013-04-10T21:05:15.023 回答