Search code examples
ioscallbackcallavplayer

IOS Detect call interruption while streaming video


I'm streaming video using AVPlayer and i want to pause the video when GSM call comes and resume when the call will end and control is back to my app. How can i achieve this?


Solution

  • I figured it out, i did it by using AVAudioSessionInterruptionNotification. Below is code snippet

    [[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;
            }
        } }