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.
精彩评论