iPod的 - 让本土音乐应用程序在后台播放声音 [英] iPod - Let the native music app to play sound in background
问题描述
我建立的iPod的应用程序。
当运行它,本机的iPod音乐应用程序应继续在后台播放,但这没有发生。
I am building an application for iPod. When running it, the native iPod music app should continue play in background, but this is not happening.
我想可能有一些做的,它是由我的应用程序播放的声音。对于在某一个点打一短声,我使用AVAudioPlayer。在code是这样的:
I think it might have something to do with the sound that it is played by my app. For playing a short sound at a certain point, I am using AVAudioPlayer. The code looks like this:
NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"];
NSLog(@"%@", path);
player = [[AVAudioPlayer alloc] initWithData:[NSData dataWithContentsOfFile:path] error:nil];
[player prepareToPlay];
[player play];
难道这干扰了iPod中的原生音乐播放器?
而另一件事。在我的应用程序,我已经集成的AdWhirl,它似乎使用AudioToolbox。
Could this interfere with the native music player on iPod? And another thing. In my app, I have integrated AdWhirl and it appears to use AudioToolbox.
非常感谢,
乔治
Thanks a lot, George
推荐答案
您必须设置AVAudioSession使用环境类别。这告诉你的声音应该与任何已经播放的声音混合系统。在iOS 4的做到这一点的最好办法是在应用程序的委托,像这样的:
You must set up your AVAudioSession to use the Ambient category. This tells the system that your sound should blend with any already playing sound. The best way to do this in iOS 4 is in the app delegate, like this:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:nil];
// ...
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// reactivate audio session
[[AVAudioSession sharedInstance] setActive: YES error: nil];
}
在音频片段阅读起来。如果您的应用程序产生的声音,你的总是的希望是有意识的,并在音频会话的控制权。
Read up on Audio Sessions. If your app produces sound, you always want be conscious of and in control of your audio session.
这篇关于iPod的 - 让本土音乐应用程序在后台播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!