swift 音频被中断处理

2020-09-28  本文已影响0人  Style_月月
NotificationCenter.default.addObserver(self, selector: #selector(audioStart(_:)), name:  NSNotification.Name.AVAudioSessionInterruption, object: nil)
public enum InterruptionType : UInt {

        case began = 1

        case ended = 0
    }
@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 收到音频中断结束通知")
            //恢复音频
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读