使用 Haishinkit 流式傳輸在上一個 iOS 版本(iOS 15)上運行良好,但在版本更新后(iOS 16)開始使用音頻附加流式傳輸時它會掛起
rtmpStream.attachAudio(AVCaptureDevice.default(for: .audio)) { error in
print(error.description)
}
如果沒有這條線,流媒體作業正常,但無法獲得流媒體音頻,在添加這條線以附加音頻后,視頻流掛斷并且無法進一步流式傳輸。此問題在更新 iOS 16.0.2 版本后發生。任何建議,非常感謝為流媒體添加音頻!
uj5u.com熱心網友回復:
確保在開始流之前設定并激活 AVAudioSession。
import AVFoundation
let session = AVAudioSession.sharedInstance()
do {
// https://stackoverflow.com/questions/51010390/avaudiosession-setcategory-swift-4-2-ios-12-play-sound-on-silent
if #available(iOS 10.0, *) {
try session.setCategory(.playAndRecord, mode: .default, options: [.defaultToSpeaker, .allowBluetooth])
} else {
session.perform(NSSelectorFromString("setCategory:withOptions:error:"), with: AVAudioSession.Category.playAndRecord, with: [
AVAudioSession.CategoryOptions.allowBluetooth,
AVAudioSession.CategoryOptions.defaultToSpeaker]
)
try session.setMode(.default)
}
try session.setActive(true)
} catch {
print(error)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/518208.html
上一篇:具有同步功能的任務組
下一篇:SwiftUI字典中的有序串列
