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(handleAudioSessionInterruptNoti:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]];
    
    }
    
    //音频播放中断的通知
    
    -(void)handleAudioSessionInterruptNoti:(NSNotification*)noti
    
    {
    
        NSDictionary *userInfo = noti.userInfo;
    
        AVAudioSessionInterruptionType type = [userInfo[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
    
        switch (type)
    
        {
    
            case AVAudioSessionInterruptionTypeBegan:
    
            {
    
                //需要停止播放操作
    
            }
    
                break;
    
            case AVAudioSessionInterruptionTypeEnded:
    
            {
    
                AVAudioSessionInterruptionOptions options = [userInfo[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue];
    
                if (options == AVAudioSessionInterruptionOptionShouldResume)
    
                {
    
                    //需要执行播放操作
    
                }
    
            }
    
                break;
    
            default:
    
                break;
    
        }
    
    }
    
     
  • 相关阅读:
    MongoDb
    js暴露内部方法属性等
    JS闭包
    k8s设计模式
    scrum
    死锁
    Linux下安装php 扩展fileinfo
    linux中whereis、which、find、location的区别和用法
    Linux 命令学习记录
    windows 下 redis 的安装及使用
  • 原文地址:https://www.cnblogs.com/yuxiaoyiyou/p/8482124.html
Copyright © 2011-2022 走看看