【问题标题】:run music in background running application in xcode在后台运行音乐在xcode中运行应用程序
【发布时间】:2010-10-23 20:33:48
【问题描述】:

请向我发送一个代码示例,说明如何在应用程序进入后台时运行音乐文件。 [iphone 4.1]。

我不希望音乐在我的应用程序进入后台时停止,就像 itunes 音乐一样。

最好的问候,
小屁屁

【问题讨论】:

  • '这就是我想要的,为我创造。'

标签: iphone


【解决方案1】:

在您的 PLIST 中将“音频”添加到 UIBackgroundModes。

在手机锁定时继续播放;

#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>

AVAudioSession *audioSession = [AVAudioSession sharedInstance];

NSError *setCategoryError = nil;
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (setCategoryError) { /* handle the error condition */ }

NSError *activationError = nil;
[audioSession setActive:YES error:&activationError];
if (activationError) { /* handle the error condition */ }

【讨论】:

【解决方案2】:

您可以在 Erica Sadun 的书中看到示例 - 如何播放音频文件...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    • 2012-01-28
    • 2014-01-10
    • 2011-09-11
    相关资源
    最近更新 更多