|
|
@ -455,8 +455,7 @@ public class AudioSessionHub { |
|
|
|
|
|
|
|
|
/// 处理音频中断 |
|
|
/// 处理音频中断 |
|
|
@objc private func handleAudioSessionInterruption(notification: Notification) { |
|
|
@objc private func handleAudioSessionInterruption(notification: Notification) { |
|
|
os_log("🔊 收到音频会话中断通知", log: logger, type: .info) |
|
|
os_log("🔔 收到音频会话中断通知 userInfo:", notification.userInfo ?? [:]) |
|
|
|
|
|
|
|
|
guard let userInfo = notification.userInfo, |
|
|
guard let userInfo = notification.userInfo, |
|
|
let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt, |
|
|
let typeValue = userInfo[AVAudioSessionInterruptionTypeKey] as? UInt, |
|
|
let type = AVAudioSession.InterruptionType(rawValue: typeValue) else { |
|
|
let type = AVAudioSession.InterruptionType(rawValue: typeValue) else { |
|
|
@ -467,17 +466,25 @@ public class AudioSessionHub { |
|
|
switch type { |
|
|
switch type { |
|
|
case .began: |
|
|
case .began: |
|
|
// 中断开始 |
|
|
// 中断开始 |
|
|
isInterrupted = true |
|
|
isInterrupted = !isInterrupted |
|
|
os_log("🚫 音频会话中断开始", log: logger, type: .info) |
|
|
os_log("🚫 音频会话中断: %{public}@", log: logger, type: .info, isInterrupted ? "开始" : "结束") |
|
|
os_log(" - 中断状态: %{public}@", log: logger, type: .info, isInterrupted ? "是" : "否") |
|
|
if (isInterrupted){ |
|
|
|
|
|
// 发送中断开始通知给其他服务 |
|
|
// 发送中断开始通知给其他服务 |
|
|
NotificationCenter.default.post( |
|
|
NotificationCenter.default.post( |
|
|
name: NSNotification.Name("AudioSessionInterruptionBegan"), |
|
|
name: NSNotification.Name("AudioSessionInterruptionBegan"), |
|
|
object: nil, |
|
|
object: nil, |
|
|
userInfo: ["type": "began"] |
|
|
userInfo: ["type": "began"] |
|
|
) |
|
|
) |
|
|
}else{ |
|
|
|
|
|
// 发送中断结束通知给其他服务,包含恢复建议 |
|
|
|
|
|
NotificationCenter.default.post( |
|
|
|
|
|
name: NSNotification.Name("AudioSessionInterruptionEnded"), |
|
|
|
|
|
object: nil, |
|
|
|
|
|
userInfo: [ |
|
|
|
|
|
"type": "ended" |
|
|
|
|
|
] |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
case .ended: |
|
|
case .ended: |
|
|
// 中断结束 |
|
|
// 中断结束 |
|
|
isInterrupted = false |
|
|
isInterrupted = false |
|
|
@ -586,17 +593,6 @@ public class AudioSessionHub { |
|
|
os_log("🔧 音频类别已变化", log: logger, type: .info) |
|
|
os_log("🔧 音频类别已变化", log: logger, type: .info) |
|
|
os_log(" - 当前类别: %{public}@", log: logger, type: .info, audioSession.category.rawValue) |
|
|
os_log(" - 当前类别: %{public}@", log: logger, type: .info, audioSession.category.rawValue) |
|
|
os_log(" - 当前模式: %{public}@", log: logger, type: .info, audioSession.mode.rawValue) |
|
|
os_log(" - 当前模式: %{public}@", log: logger, type: .info, audioSession.mode.rawValue) |
|
|
|
|
|
|
|
|
// 发送中断结束通知给其他服务,包含恢复建议 |
|
|
|
|
|
NotificationCenter.default.post( |
|
|
|
|
|
name: NSNotification.Name("AudioSessionInterruptionEnded"), |
|
|
|
|
|
object: nil, |
|
|
|
|
|
userInfo: [ |
|
|
|
|
|
"type": "ended", |
|
|
|
|
|
"shouldResume": false, |
|
|
|
|
|
"options": 0 |
|
|
|
|
|
] |
|
|
|
|
|
) |
|
|
|
|
|
case .override: |
|
|
case .override: |
|
|
os_log("🔀 音频路由被覆盖", log: logger, type: .info) |
|
|
os_log("🔀 音频路由被覆盖", log: logger, type: .info) |
|
|
|
|
|
|
|
|
|