Ben*_*ley 5 iphone interrupt core-audio ipad ios
我正在使用AUGraph和AUSampler将MIDI信号转换为音频。该应用程序可以正常运行,但是如果该应用程序被中断(例如电话或计时器)会出现问题。中断后,AUGraph停止运行,没有任何声音。再次获得声音的唯一方法是重新启动应用程序。我正在使用标准方法来处理中断:
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(handleInterruption:)
name: AVAudioSessionInterruptionNotification
object: [AVAudioSession sharedInstance]];
Run Code Online (Sandbox Code Playgroud)
发生中断时,将调用handleInterruption方法:
// If the system interrupts the audio session - kill the volume
-(void) handleInterruption: (NSNotification *) notification {
NSDictionary *interuptionDict = notification.userInfo;
NSInteger interuptionType = [[interuptionDict valueForKey:AVAudioSessionInterruptionTypeKey] intValue];
if (interuptionType == AVAudioSessionInterruptionTypeBegan) {
[self setAudioSessionActive: NO];
[self stopAUGraph];
}
else if (interuptionType == AVAudioSessionInterruptionTypeEnded) {
[self setAudioSessionActive: YES];
[self startAUGraph];
}
}
Run Code Online (Sandbox Code Playgroud)
这是启动和停止AUGraph的方法
-(void) startAUGraph {
CheckError(AUGraphStart(_audioGraph), "Failed to start Audio Graph");
}
-(void) stopAUGraph {
Boolean isRunning = false;
// Check to see if the graph is running.
CheckError(AUGraphIsRunning(_audioGraph, &isRunning), "Error trying querying whether graph is running");
// If the graph is running, stop it.
if (isRunning) {
CheckError(AUGraphStop(_audioGraph), "Failed to stop Audio Graph");
}
}
Run Code Online (Sandbox Code Playgroud)
这是setAudioSessionActive方法:
-(void) setAudioSessionActive: (BOOL) active {
NSError *audioSessionError = nil;
BOOL success = [_audioSession setActive:active error:&audioSessionError];
if (!success) {
NSLog (@"Error activating audio session!");
}
}
Run Code Online (Sandbox Code Playgroud)
我在渲染回调中设置了一个断点,以便可以确认AUGraph没有运行。有人遇到过这个问题吗?我还需要做其他事情才能使AUGraph重新运行吗?提前致谢!
小智 1
我不确定当前的 iOS6 版本能否实现这一目标。请参阅此错误报告 - http://openradar.appspot.com/12412685
您可能想要收听UIApplicationWillResignActiveNotification和UIApplicationDidBecomeActiveNotification通知,这些通知在通知处理程序中的电话呼叫和停止/启动音频会话等中断期间触发。
| 归档时间: |
|
| 查看次数: |
1863 次 |
| 最近记录: |