开发者

Play one instance of AVAudioPlayer in the background

开发者 https://www.devze.com 2023-04-09 07:17 出处:网络
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

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

精彩评论

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