开发者

Playing audio file in background (multitasking)

开发者 https://www.devze.com 2023-03-23 13:14 出处:网络
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:

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

精彩评论

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