在UILocalNotification声音比AVAudioPlayer在最大音量

为了这个问题的目的,想象我的应用程序每10秒播放一个audio剪辑。 此audio使用AVAudioPlayer播放/与设备上的iPod音乐播放器(使用低频)混合。 当应用程序被发送到后台,我安排UILocalNotification对象与audio文件引用(和没有文字),所以声音继续播放以10秒为间隔。

令我困扰的是,在iOS 6上作为通知的一部分播放的audio剪辑的音量似乎是我在应用程序中播放audio时的两倍(我将音量设置为1.0f,文档说是最大)。 所以,每隔10秒钟,应用程序就会播放声音,当您发送到背景时,与应用程序中的内容相比,现在声音非常响亮。

相关片段…应用程序启动,这里是我如何设置AVAudioSession,以启用ducking:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; UInt32 doChangeDefaultRoute = 1; AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute); OSStatus propertySetError = 0; UInt32 allowMixing = true; propertySetError = AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers,sizeof (allowMixing),&allowMixing); 

…我如何创build我的球员:

 - (AVAudioPlayer *)playerWithCAFFileNamed:(NSString *)fname { NSURL *u = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:fname ofType:@"caf"]]; NSData *d = [NSData dataWithContentsOfURL:u]; AVAudioPlayer *p = [[AVAudioPlayer alloc] initWithData:d error:nil]; p.delegate = self; p.volume = 1.0; [p prepareToPlay]; return p; } 

…然后播放:

 - (void)playAudio:(AVAudioPlayer *)player { [self setSessionActiveWithMixing:YES]; [player setVolume:1.0]; // should already be set, but just to be sure [player play]; } 

…以下是我如何创build超大声通知:

 - (UILocalNotification *)notificationWithSoundNamed:(NSString *)sound atTimeInterval:(NSTimeInterval)ti { UILocalNotification *n = [[UILocalNotification alloc] init]; n.soundName = sound; n.fireDate = [NSDate dateWithTimeIntervalSinceReferenceDate:ti]; return n; } 

我用苹果打开的错误被closures为“functiondevise”。 他们的简短解释:

通知声音跟随铃声音量; AVAudioPlayer遵循媒体音量。

…我想你可以假设铃声音量比最响的媒体音量大,以确保你听到铃声。 我猜。

我遇到类似的AVAudioPlayer音量问题。 所以我把我想分配的价值按我想得到的一个因素来划分。 值得find原因。