这是我遇到的问题。我有一个可从网络加载声音并随后播放的应用程序。同时,该应用程序具有录制和播放语音的功能。我为这两个功能使用了两个不同的视图控制器。对于这些任务,我创建了一个单例。
当我启动应用程序并直接直接进入Record View Controller时-一切正常(我可以录制声音,播放它,然后可以带着声音进入第二个View Controller,并且可以毫无问题地播放它也是如此)。
但是,如果我启动该应用并首先播放声音(使用第二个视图控制器),然后转到“记录视图控制器”并尝试记录某些内容,则出现以下崩溃消息:Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: '[[busArray objectAtIndexedSubscript:(NSUInteger)element] setFormat:format error:&nsErr]: returned false, error Error Domain=NSOSStatusErrorDomain Code=-10865 "(null)"'
>
当我录制recordButton时发生此崩溃。它是在线发生的-尝试records.record():
func startRecord() {
if AKSettings.headPhonesPlugged {
micBooster.gain = 1
}
micBooster.gain = 0
do {
try recorder.record()
} catch {
print("Can't record because: \(error)")
}
}
如果我将类别设置为.playAndRecord
,则会发生此崩溃try audioSession.setCategory(.playAndRecord, mode: .default, options: .mixWithOthers)
我的单例班:
class AudioKitSingleton {
var mic: AKMicrophone!
var micMixer: AKMixer!
var recorder: AKNodeRecorder!
var tape: AKAudioFile!
var player: AKPlayer!
var micBooster: AKBooster!
var mainMixer: AKMixer!
var url: URL?
var name: String?
var artist: String?
var uploader: String?
var performer: String?
var load: Bool = false
var isPlay: Bool = false
var categoryID: Int? = nil
static let shared = AudioKitSingleton()
func initMic() {
stopAudioKitEngine()
AKAudioFile.cleanTempDirectory()
AKSettings.bufferLength = .medium
AKSettings.defaultToSpeaker = true
setupRecordSession()
mic = AKMicrophone()
micMixer = AKMixer(mic)
micBooster = AKBooster(micMixer)
micBooster.gain = 0
recorder = try? AKNodeRecorder(node: micMixer)
if let file = recorder.audioFile {
player = AKPlayer(audioFile: file)
}
player.isLooping = false
mainMixer = AKMixer(player, micBooster)
AudioKit.output = mainMixer
startAudioKitEngine()
}
func deinitMic() {
stopAudioKitEngine()
mic = nil
micMixer = nil
recorder = nil
tape = nil
player = nil
micBooster = nil
mainMixer = nil
}
func startRecord() {
if AKSettings.headPhonesPlugged {
micBooster.gain = 1
}
micBooster.gain = 0
do {
try recorder.record()
} catch {
print("Can't record because: \(error)")
}
}
func stopRecord() {
micBooster.gain = 0
tape = recorder.audioFile!
player.load(audioFile: tape)
player.prepare()
if let _ = player.audioFile?.duration {
recorder.stop()
}
}
func resetRecorder() {
do {
try recorder.reset()
} catch {
print("Can't reset recorder because: \(error)")
}
}
func playerPlayRecord() {
player.play()
}
func playerStopRecord() {
player.stop()
}
func setupRecordSession() {
do {
try audioSession.setCategory(.record, mode: .default, options: .mixWithOthers)
} catch {
print(error)
}
}
func startAudioKitEngine() {
do {
try AudioKit.start()
} catch {
AKLog("AudioKit did not start because: \(error)")
}
}
func stopAudioKitEngine() {
if AudioKit.engine.isRunning {
do {
try AudioKit.stop()
} catch {
AKLog("AudioKit did not start because: \(error)")
}
}
}
func setupPlayer(url: URL) {
if AudioKit.engine.isRunning {
stopAudioKitEngine()
}
player = try AKPlayer(url: url)
AudioKit.output = player
startAudioKitEngine()
}
func setupPlayer(mixloop: AVAudioFile) {
if AudioKit.engine.isRunning {
stopAudioKitEngine()
}
player = try AKPlayer(audioFile: mixloop)
AudioKit.output = player
startAudioKitEngine()
}
func play() {
try player?.play()
}
func resume() {
try player?.resume()
}
func stop() {
player?.stop()
}
func pause() {
player?.pause()
}
func remove() {
if AudioKit.engine.isRunning {
try? AudioKit.stop()
player?.stop()
player = nil
recorder = nil
AudioKit.output = nil
url = nil
name = nil
artist = nil
uploader = nil
load = false
isPlay = false
}
}
}
此崩溃发生在除iPhone 5s,iOS12之外的所有iPhone上。需要帮助。
答案 0 :(得分:1)
我很确定这将在今天的AudioKit 4.5.2版本中解决,并立即上传。