3

IHeartRadio というアプリがあり、指定した間隔でオーディオをオフにするスリープ タイマーを設定できます。

最初に聞くステーションを選択し、次にラジオ ステーションの再生を停止するまでのスリープ時間を選択します。これが発生するために、アプリがフォアグラウンドにある必要はありません。

アプリがバックグラウンドにあるときにオーディオを停止するにはどうすればよいですか?

1 つの理論は、サイレント オーディオで 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 に答える