作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想通过扬声器播放歌曲,同时能够使用 Quickblox 接听视频通话。
我的音频速率越来越乱了。还有一个更大的问题是,当通话结束时,quickblox 框架将 Audio Session 设置为停用状态。 IE [Avaudiosession sharedInstance]setActive:NO....
如何阻止这种情况发生?
或者有没有办法处理上述情况。??
我已经通过谷歌阅读了一个月,但仍然没有找到任何合适的答案或任何指南。谁能帮我解决这个问题/??
最佳答案
首先,要允许 AVAudioSession
与其他 AVAudioSession
一起工作,您需要在初始化时设置选项 AVAudioSessionCategoryOptionMixWithOthers
:
NSError *sessionError = NULL;
BOOL success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:&sessionError];
if(!success) {
NSLog(@"Error setting category Audio Session: %@", [sessionError localizedDescription]);
}
要处理中断(电话、闹钟等),您应该为 NSNotificationCenter
的中断设置一个观察者,您将能够处理 的激活/停用code>AVAudioSession
如有必要:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleAudioSessionInterruption:)
name:AVAudioSessionInterruptionNotification
object:[AVAudioSession sharedInstance]];
NSNotification 会携带 Type of Interruption 和 Key:
- (void)handleAudioSessionInterruption:(NSNotification*)notification {
NSNumber *interruptionType = [[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey];
NSNumber *interruptionOption = [[notification userInfo] objectForKey:AVAudioSessionInterruptionOptionKey];
switch (interruptionType.unsignedIntegerValue) {
case AVAudioSessionInterruptionTypeBegan:{
// • Audio has stopped, already inactive
// • Change state of UI, etc., to reflect non-playing state
NSLog(@"AVAudioSessionInterruptionTypeBegan");
} break;
case AVAudioSessionInterruptionTypeEnded:{
// • Make session active
// • Update user interface
// • AVAudioSessionInterruptionOptionShouldResume option
NSLog(@"AVAudioSessionInterruptionTypeEnded");
if (interruptionOption.unsignedIntegerValue == AVAudioSessionInterruptionOptionShouldResume) {
// Here you should continue playback.
}
} break;
default:
break;
}
}
关于ios - 如何阻止 Avaudiosesion 停用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37123598/
我想通过扬声器播放歌曲,同时能够使用 Quickblox 接听视频通话。 我的音频速率越来越乱了。还有一个更大的问题是,当通话结束时,quickblox 框架将 Audio Session 设置为停用
我是一名优秀的程序员,十分优秀!