Ios 在后台停止音频

Ios 在后台停止音频,ios,audio,background-process,uilocalnotification,Ios,Audio,Background Process,Uilocalnotification,有一个叫做IHeartRadio的应用程序,可以让你设置一个睡眠计时器,在指定的时间间隔后关闭音频 您首先选择要收听的电台,然后选择睡眠时间,之后电台将停止播放。应用程序不需要在前台就可以实现这一点 应用程序在后台时如何停止音频 一种理论是使用无声音频设置UILocalNotification。然后UILocalNotification将接管设备的音频,实际上使正在播放的音频静音。那没用 计时器不在后台工作,这就不会在后台留下太多基于时间的行为。您可以在AppDelegate中使用Applica

有一个叫做IHeartRadio的应用程序,可以让你设置一个睡眠计时器,在指定的时间间隔后关闭音频

您首先选择要收听的电台,然后选择睡眠时间,之后电台将停止播放。应用程序不需要在前台就可以实现这一点

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

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


计时器不在后台工作,这就不会在后台留下太多基于时间的行为。

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

- (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 ..
}

当UIBackgroundModes键包含音频值时,系统的媒体框架会自动防止相应的应用程序在移动到后台时暂停。只要它正在播放音频或视频内容,应用程序就会继续在后台运行。但是,如果应用程序停止播放音频或视频,系统将暂停播放。


From.

可能我不清楚:我想在应用程序已经进入后台后停止音频,而不是在它进入后台的过程中。嗯。根据我的经验,即使我在我的应用程序的plist中的“必需背景模式”下声明了“应用程序播放音频”,NSTimer也不起作用。如果不是UILocalNotification或NSTimer,我还可以采取什么其他基于时间的操作?我想可能是因为我的应用程序没有播放任何音频。我将尝试将沉默与播放分类相结合,看看这是否有效。