#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAudioSessionRouteChangeNoti:) name:AVAudioSessionRouteChangeNotification object:[AVAudioSession sharedInstance]];
}
//音频播放中断的通知
-(void)handleAudioSessionRouteChangeNoti:(NSNotification*)noti
{
    NSDictionary *userInfo = noti.userInfo;
    AVAudioSessionRouteChangeReason reason = [userInfo[AVAudioSessionRouteChangeReasonKey] unsignedIntegerValue];
    if (reason == AVAudioSessionRouteChangeReasonOldDeviceUnavailable)
    {
        AVAudioSessionRouteDescription *previousRoute = userInfo[AVAudioSessionRouteChangePreviousRouteKey];
        AVAudioSessionPortDescription *previousOutput = previousRoute.outputs[0];
        NSString *portType = previousOutput.portType;
        if ([portType isEqualToString:AVAudioSessionPortHeadphones])
        {
            //原来使用的设备是耳机,现在不再使用耳机需要进行的操作
        }
    }
    
}

 

相关文章:

  • 2021-12-04
  • 2021-08-19
  • 2021-11-18
  • 2022-12-23
  • 2021-04-11
  • 2021-12-04
猜你喜欢
  • 2021-09-01
  • 2021-10-26
  • 2022-02-22
  • 2021-12-04
  • 2021-09-20
  • 2021-08-26
相关资源
相似解决方案