IOS 流式传输视频时检测通话中断
IOS Detect call interruption while streaming video
我正在使用 AVPlayer 流式传输视频,我想在 GSM 呼叫到来时暂停视频,并在呼叫结束且控制权返回我的应用程序时恢复。我怎样才能做到这一点?
我想出来了,我用 AVAudioSessionInterruptionNotification
做到了。下面是代码片段
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(routeInterrypt:) name:AVAudioSessionInterruptionNotification object:nil];
-(void)routeInterrypt:(NSNotification *)notification {
NSDictionary *dic = notification.userInfo;
int changeReason= [dic[AVAudioSessionRouteChangeReasonKey] intValue];
if (changeReason == AVAudioSessionRouteChangeReasonUnknown) {
if (_state == TYVideoPlayerStateContentPlaying || _state == TYVideoPlayerStateBuffering) {
[self pauseContent];
return;
}
} }
我正在使用 AVPlayer 流式传输视频,我想在 GSM 呼叫到来时暂停视频,并在呼叫结束且控制权返回我的应用程序时恢复。我怎样才能做到这一点?
我想出来了,我用 AVAudioSessionInterruptionNotification
做到了。下面是代码片段
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(routeInterrypt:) name:AVAudioSessionInterruptionNotification object:nil];
-(void)routeInterrypt:(NSNotification *)notification {
NSDictionary *dic = notification.userInfo;
int changeReason= [dic[AVAudioSessionRouteChangeReasonKey] intValue];
if (changeReason == AVAudioSessionRouteChangeReasonUnknown) {
if (_state == TYVideoPlayerStateContentPlaying || _state == TYVideoPlayerStateBuffering) {
[self pauseContent];
return;
}
} }