有一个名为IHeartRadio的应用程序可让你设置一个睡眠定时器,它会在指定的间隔后关闭音频。
首先选择要收听的电台,然后选择一段时间进入睡眠状态,之后电台将停止播放。该应用程序不需要在前台进行此操作。
应用程序如何在后台停止音频时停止播放?
一种理论是用无声音频设置UILocalNotification。然后UILocalNotification将接管设备的音频,实际上使正在播放的音频静音。那没用。
计时器在后台不起作用,后台在基于时间的行为方面没有太大作用。
答案 0 :(得分: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.
答案 1 :(得分: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 ..
}