开发者

run music in background running application in xcode

Kindly send me a code sample of how to run the music file when the application goes in the background. [iphone 4.1].

I don't want the music to stop when my application goes in the background just like the itunes music.

Best Regards,

Naveed B开发者_如何学Pythonutt


Add "audio" to UIBackgroundModes in your PLIST.

For playback to continue when the phone locks;

#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 */ }


You can see the sample in the book of Erica Sadun - how to play audio file ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜