在后台运行音乐在xcode中运行应用程序
问题描述:
请向我发送如何在应用程序在后台运行时运行音乐文件的代码示例。 [iphone 4.1]。在后台运行音乐在xcode中运行应用程序
当我的应用程序像itunes音乐一样在后台播放时,我不希望音乐停止。
最好的问候,
纳维德·巴特
答
添加“音频”,以UIBackgroundModes在PLIST。
用于在手机锁定时继续播放;
#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 */ }
+0
不要在模拟器上测试,这在设备上正常工作。 http://stackoverflow.com/questions/3421128/how-do-you-use-avaudioplayer-to-play-music-while-in-the-background?rq=1 – justinkoh 2012-08-14 04:10:34
答
你可以看到埃里卡丧盾书样本 - 如何播放音频文件...
'这就是我想要的,为我创造。' – Emil 2010-10-23 21:05:32