当我致电startWriting
进行视频捕获会话时,音频会话的回避将停止,并且外部音频将恢复到全音量。如何防止这种情况发生?
音频会话设置:
try! AVAudioSession.sharedInstance().setCategory(.playback, mode: .spokenAudio, options: [.duckOthers, .interruptSpokenAudioAndMixWithOthers])
try! AVAudioSession.sharedInstance().setActive(true)
// ducking starts here, as expected
视频会话设置:
let videoSettings:[String: Any] = [AVVideoCodecKey: AVVideoCodecType.h264, AVVideoWidthKey: 200, AVVideoHeightKey: 200]
let path = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0] + "/video"
let fileURL = URL(fileURLWithPath: path)
do {
try FileManager.default.removeItem(at: fileURL)
} catch {}
let assetWriter = try! AVAssetWriter(url: fileURL, fileType: AVFileType.mov)
let writeInput = AVAssetWriterInput(mediaType: AVMediaType.video, outputSettings: videoSettings)
assert(assetWriter.canAdd(writeInput))
assetWriter.add(writeInput)
assert(assetWriter.startWriting())
// ducking stops here unexpectedly