Tag: 中断

如何正确处理audio中断?

我已经创build了一个OpenGL 3D游戏,利用OpenAL进行audio播放,如果在audio设备初始化之前按下“Home”button,则会遇到audio丢失的问题。 我试图挂接到audio会话中断处理程序,但我的callback永远不会被调用。 无论我是否最小化或最大化我的申请。 我的“OpenALInterruptionListener”永远不会被调用。 我究竟做错了什么? AudioSessionInitialize(NULL, NULL, OpenALInterriptionListener, this); void OpenALInterriptionListener(void * inClientData, UInt32 inInterruptionState) { OpenALDevice * device = (OpenALDevice *) inClientData; if (inInterruptionState == kAudioSessionBeginInterruption) { alcSuspendContext(_context); alcMakeContextCurrent(_context); AudioSessionSetActive(false); } else if (inInterruptionState == kAudioSessionEndInterruption) { UInt32 sessionCategory = kAudioSessionCategory_AmbientSound; AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory); AudioSessionSetActive(true); alcMakeContextCurrent(_context); alcProcessContext(_context); } }

应用程序与AVPlayer播放mp4中断iPod音乐启动后

我的应用程序使用AVPlayer播放mp4,当我的应用程序完成启动时,它会中断iPod音乐,尽pipe我已经设置了audio会话以允许与其他人混音 – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { AudioSessionInitialize(NULL, NULL, NULL, NULL); AudioSessionSetActive(true); UInt32 sessionCategory = kAudioSessionCategory_AmbientSound; AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory); UInt32 allowMixWithOthers = true; AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixWithOthers), &allowMixWithOthers); 视图控制器确实出现后,我重新启动iPod音乐,它可以正常工作与我的应用程序没有中断,我的应用程序不会中断音乐了。 有谁知道问题是否可以解决? 我也检查了myapp-info.plist ,发现没有属性来防止打断iPod。 所有AudioSession方法都不返回错误。 这里是iPhoneConfigureUtility中的日志: Aug 20 10:55:54 nova-teki-iPhone audiotest[3510] <Warning>: AudioSessionInitialize status = 0 Aug 20 10:55:55 nova-teki-iPhone kernel[0] <Debug>: ALS: kIOHIDDisplayBrightnessSliderPositionKey=69% (0xb226) Aug 20 10:55:55 nova-teki-iPhone […]

AVAudioSession中断

所以在我的应用程序,在iOS 6上运行,似乎一切正常与audio。 我使用旧的C API格式来使用callback来捕获中断。 通过设置: AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, (__bridge void *)self) ,这是伟大的。 尽pipe使用iOS 7 SDK,似乎我的中断callback从来没有被调用,当设备接到电话或闹钟closures。 听了一些后,我听说旧的C API已被弃用,你应该转移到新的AVAudioSessionfunction。 更多的阅读表明,AVAudioSession委托已被弃用,你应该使用AVAudioSessionInterruptionNotification的NSNotification捕捉中断,做任何需要做的事情。 对我来说,似乎这个通知从来没有真正被解雇,所以我从来没有得到正确的打断,这就打破了通话结束后的所有audio内容。 我注册了这样的通知: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AudioInterruption:) name:AVAudioSessionInterruptionNotification object:nil]; 现在, AudioInterruption:函数简单地logging它被触发。 日志和任何断点都不会被触发。 要清楚,最初的audio播放和录音工作正常。 发生中断时(例如来电或警报),不会触发中断通知。 如果需要更多的周边代码,请告诉我。

iOS应用程序在后台录制时audio中断

我的iPad声音应用程序(iOS 7.1)能够在后台录制。 只要在后台录制不中断,一切都可以。 例如,如果有人(愚蠢?)的想法,开始听音乐,而录音的东西。 我试图以不同的方式pipe理这种中断,但没有成功。 问题是, – (void)audioRecorderEndInterruption:(AVAudioPlayer *)p withOptions:(NSUInteger)flags 当应用程序在后台发生中断时,永远不会被触发。 然后,我尝试在另一个解决scheme中实现AVAudioSessionInterruptionNotification和handleInterruption:方法 – (void) viewDidAppear:(BOOL)animated { …… AVAudioSession *session=[AVAudioSession sharedInstance]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:AVAudioSessionInterruptionNotification object:session]; ……. } // interruption handling – (void)handleInterruption:(NSNotification *)notification { try { UInt8 theInterruptionType = [[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] intValue]; NSLog(@"Session interrupted > — %s —\n", theInterruptionType == AVAudioSessionInterruptionTypeBegan ? "Begin Interruption" […]

iOS AVAudioSession中断通知不按预期工作

我想知道什么时候我的AVAudioRecorder无法访问(例如,当音乐开始播放)。 由于audioRecorderEndInterruption将被弃用与iOS 9我专注于AVAudioSession的中断通知(但都没有按预期工作)。 问题是,如果应用程序在中断发生时仍处于前台,中断通知从不会被调用。 例如:用户启动和停止播放音乐,而不将应用程序移动到后台。 要检测我正在使用的任何中断: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionWasInterrupted:) name:AVAudioSessionInterruptionNotification object:nil]; … – (void)audioSessionWasInterrupted:(NSNotification *)notification { if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) { NSLog(@"Interruption notification"); if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) { NSLog(@"InterruptionTypeBegan"); } else { NSLog(@"InterruptionTypeEnded"); } } } 如预期的那样,我得到InterruptionTypeBegan ,但是如果应用程序仍处于前台(即在应用程序放置在后台并返回前台之前不会调用),则不会调用InterruptionTypeEnded 。 在应用程序处于前台时发生中断时,如何接收InterruptionTypeEnded通知?