0 Replies
      Latest reply on Jul 19, 2019 10:55 PM by Nimesh Chandramaniya
      Nimesh Chandramaniya Level 1 Level 1 (0 points)

        Issue:

        My application's audio is not resuming after an interruption (such as phone call or when I use other applications). This issue happens when my application is already in the background state before the interrupt occurs.

         

        Code to handle interrupts:

         

        - (void)handleInterruption:(NSNotification *) notification{
          if (notification.name != AVAudioSessionInterruptionNotification || notification.userInfo == nil) {
          return;
          }
        
          NSDictionary *info = notification.userInfo;
        
          if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) {
        
          if ([[info valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) {
        
        
          NSLog(@"InterruptionTypeBegan");
        
          } else {
          NSLog(@"InterruptionTypeEnded");
          dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
          NSLog(@"playing audio");
        
          self->_audioPlayer.numberOfLoops = -1;
          [self->_audioPlayer play];
        
          });
          }
          }
        }

         

        In Xcode console, I see logs in the following sequence but no audio is played:

        1. InterruptionTypeBegan
        2. InterruptionTypeEnded
        3. playing audio

        I would appreciate any suggestions and thoughts on this topic. Thank you.

         

        Additional information:

        I have noticed same issue with many online music streaming apps such as Saavn and Spotify.