开发者

Play one instance of AVAudioPlayer in the background

I have several instances 开发者_开发百科of AVAudioPlayer in my app (in separate classes). I have added multi-tasking capabilities to one instance but all audio now plays in the background. I added the 'App plays audio' key to my plist and:

    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];

to my class. How can I target this code to only 1 instance of AVAudioPlayer?


The only way around this I could find was the pause the specific AVAudioPlayer instance in:

applicationWillResignActive

I moved the creation of the instance to the appdelegate and then accessed it via:

appDelegate = [[UIApplication sharedApplication] delegate]

in my class. There is probably a better way to do this but this was the quickest and simplest I could find.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜