开发者

Playing audio file in background (multitasking)

I have searched for many web sites in order to play my audio file even the home button on iPhone is pressed. And I have come up with the following:

path = [[NSB开发者_开发百科undle mainBundle] pathForResource:@"forest" ofType:@"mp3"];
NSData *sampleData = [[NSData alloc] initWithContentsOfFile:path];
NSError *audioError = nil;

av = [[AVAudioPlayer alloc] initWithData:sampleData error:&audioError];
[sampleData release];

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
[av play];

Then an error msg comes up:

'AVAudioSession' undeclared (first use in this function)

Can anyone explain why this error is shown??

Edit: I have the followings as well:

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


Hope you have included AVFoundation framework and using the correct includes on your code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜