RTMP流在swift中与iOS 16挂起

sd2nnvve  于 2022-10-31  发布在  Swift
关注(0)|答案(1)|浏览(145)

使用Haishinkit流媒体工作正常与上一个iOS版本(iOS 15),但版本更新后(iOS 16)它得到挂起时,开始流媒体与音频附加

rtmpStream.attachAudio(AVCaptureDevice.default(for: .audio)) { error in
     print(error.description)
}

如果没有这条线,流媒体工作正常,但无法获得流媒体音频,添加这条线后,附加音频,视频流挂起,无法进一步流媒体。此问题发生后,更新iOS 16.0.2版本。任何建议,添加音频流非常感谢!

0lvr5msh

0lvr5msh1#

请确保在开始流之前设置并激活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)
}

相关问题