Using Haishinkit streaming worked fine with last iOS version (iOS 15), But after version update (iOS 16) Its getting hang when start streaming with audio attach
rtmpStream.attachAudio(AVCaptureDevice.default(for: .audio)) { error in
print(error.description)
}
Without this line streaming is working fine but cannot get streaming audio, after add this line for attach audio, video stream hangup and cannot able to stream further. This issue happening after update iOS 16.0.2 version. Any suggestions, Add audio for streaming greatly appreciated!
CodePudding user response:
Make sure you setup and activate your AVAudioSession before start stream.
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)
}