AVAudioSession ducking stops when AVAssetWriter.startWriting is called

偶尔善良 提交于 2019-12-25 00:51:02

问题


When I call startWriting for a video capture session, the ducking for my audio session stops, and the external audio goes back to full volume. How can I prevent this from happening?

Audio session setup:

try! AVAudioSession.sharedInstance().setCategory(.playback, mode: .spokenAudio, options: [.duckOthers, .interruptSpokenAudioAndMixWithOthers])
try! AVAudioSession.sharedInstance().setActive(true)
// ducking starts here, as expected

Video session setup:

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

Full example: https://www.paste.org/98057

来源:https://stackoverflow.com/questions/55601427/avaudiosession-ducking-stops-when-avassetwriter-startwriting-is-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!