美文网首页
swift 音频被中断处理

swift 音频被中断处理

作者: Style_月月 | 来源:发表于2020-09-28 16:50 被阅读0次
  • 1、监听音频打断事件
NotificationCenter.default.addObserver(self, selector: #selector(audioStart(_:)), name:  NSNotification.Name.AVAudioSessionInterruption, object: nil)
  • 2、在通知方法中处理音频中断事件
    AVAudioSessionInterruptionType有两种类型:beganended
public enum InterruptionType : UInt {

        case began = 1

        case ended = 0
    }
  • began表示收到中断事件开始的通知
  • ended表示收到中断事件结束的通知
@objc private func audioStart(_ note: Notification){
        print("addInterruptionSession \(note) \(note.userInfo![AVAudioSessionInterruptionTypeKey])")
        
        if AVAudioSessionInterruptionType.began.rawValue == note.userInfo![AVAudioSessionInterruptionTypeKey] as? UInt{
            print("addInterruptionSession 收到音频中断开始通知")
            //暂停音频

        } else if AVAudioSessionInterruptionType.ended.rawValue == note.userInfo![AVAudioSessionInterruptionTypeKey]as? UInt{
            print("addInterruptionSession 收到音频中断结束通知")
            //恢复音频
        }
    }

相关文章

  • swift 音频被中断处理

    1、监听音频打断事件 2、在通知方法中处理音频中断事件AVAudioSessionInterruptionType...

  • iOS音频被QQ音乐 中断的处理

    项目需要播放一个用户提示声音。但是在首版APP中测试发现,当播放了别的声音之后,例如打开QQ音乐,自己的闹钟会被打...

  • 音频会话的中断处理

    音频会话中断 当有人打来电话时, 音频会话会中断播放音频 当电话挂断后, 音频是不会重新开始播放的 为了处理这种情...

  • 音频会话(Audio Session)编码向导

    概述 概览 音频会话管理音频行为 categories 代表音频规则 中断处理通知 通知支持音频路由的更改 音频会...

  • iOS音频播放中断的处理

    当前app在播放音频,此时打开另外一个app,或者系统铃声响起,会我们的app被打断的现象,此时我们需要暂停我们的...

  • 音频中断

    1、持有AVAudioSession的类添加AVAudioSessionInterruptionNotificat...

  • iOS音频播放处理来电话中断

    在音频播放的基类里,init方法中或者viewdidload里添加 [[NSNotificationCenter ...

  • 嵌入式中断处理的简单描述

    嵌入式中断处理的简单描述 ## 通用的中断处理过程: 中断源---》中断路径---》中断响应 中断由中断源发出,进...

  • 中断处理

    1、中断机制 (1)中断机制需要硬件的支持,eg:中断控制器、CPU现场保存与恢复机制、IDT表。 eg:完成I/...

  • Linux IO多路复用底层原理(刚接触,知识还不成体系,等懂得

    Linux 操作系统中断 什么是系统中断系统处理中断的过程: 首先由需要紧急处理的程序向处理器发送中断请求,处理器...

网友评论

      本文标题:swift 音频被中断处理

      本文链接:https://www.haomeiwen.com/subject/hrtjuktx.html