zoukankan      html  css  js  c++  java
  • iOS耳机等音频输出设备切换的通知

    #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])
            {
                //原来使用的设备是耳机,现在不再使用耳机需要进行的操作
            }
        }
        
    }
  • 相关阅读:
    Linux系统root密码修改
    网络通信
    运维平台cmdb开发-day1
    questions information
    Django Rest Framework
    Django-CBV和跨域请求伪造
    Flask学习
    会议室预定终章
    python的可变数据类型和不可变类型
    模拟admin组件自己开发stark组件之搜索和批量操作
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/8482251.html
Copyright © 2011-2022 走看看