我们的项目遇到异常:
2019-08-08 10:18:28.703708-0600 AppName[99385:5069475] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: !destNodeMixerConns.empty() && !isDestNodeConnectedToIONode' *** First throw call stack: ( 0 CoreFoundation 0x000000010ee2e8db __exceptionPreprocess + 331 1 libobjc.A.dylib 0x000000010e21bac5 objc_exception_throw + 48 2 CoreFoundation 0x000000010ee2e662 +[NSException raise:format:arguments:] + 98 3 AVFAudio 0x0000000111b94dbc _Z19AVAE_RaiseExceptionP8NSStringz + 156 4 AVFAudio 0x0000000111bf3937 _Z11_AVAE_CheckPKciS0_S0_b + 295 5 AVFAudio 0x0000000111b8cb8f _ZN18AVAudioEngineGraph8_ConnectEP19AVAudioNodeImplBaseS1_jjP13AVAudioFormat + 1031 6 AVFAudio 0x0000000111bfb598 _ZN17AVAudioEngineImpl7ConnectEP11AVAudioNodeS1_mmP13AVAudioFormat + 194 7 AVFAudio 0x0000000111bfb5ff -[AVAudioEngine connect:to:format:] + 83 8 AppName 0x000000010a424c10 $s8AudioKitAAC6outputAA6AKNodeCSgvWZTf4dd_n + 2576 9 AppName 0x000000010a4230fd $s8AudioKitAAC6outputAA6AKNodeCSgvsZ + 93 10 AppName 0x000000010a2ba3a3 $s6AppName7MaestroC17setUpTrackPlayers7fileURLy10Foundation0H0V_tF + 1235
检查常见的陷阱视频,我看到抛出了类似的异常required condition is false: !nodeMixerConns.empty() && !hasDirectConnToIONode
,这是由于允许变量超出范围而不是保留在类中引起的。
因此,当我们创建一个AKPlayer
保留在类中的,然后AKTimePitch
使用此播放器创建一个也保留在该类中的播放器,并最终将其分配给AudioKit.output
触发异常的播放器时,就会发生这种情况。之后,我们将保存播放器和时间间隔的类存储在一个数组中,因此我希望在创建它之后将其上移,希望是问题所在,但我看到了相同的异常。
有趣的是,此代码最初在加载第一首歌曲时可以正常工作,但是在按下下一首按钮以加载下一首歌曲时崩溃。
final class Maestro : NSObject { static let shared = Maestro() var audioPlayers = [TrackPlayer]() func setUpTrackPlayers(fileURL: URL) { let playerOne= TrackPlayer(url: fileURL) audioPlayers.append(playerOne) AudioKit.output = playerOne.handleMixerChain() //boom do { try AudioKit.start() } catch { print("Maestro AudioKit.start error: \(error)") } } func next() { for player in audioPlayers { player.stop() } audioPlayers.removeAll() setUpTrackPlayers(fileURL: newSong.getFileUrl()) } } final class TrackPlayer { let player : AKPlayer lazy var timePitch = AKTimePitch() init(url: URL) { player = AKPlayer(url: url)! } func handleMixerChain(pitch: Double = 0.0, tempo: Double = 1.0) -> AKTimePitch { timePitch = AKTimePitch(player) timePitch.pitch = pitch timePitch.rate = tempo return timePitch } }
有任何想法吗?如果您需要更多信息,请告诉我。可能需要注意的是,我们是从AudioKit 4.5.5更新的,我们没有遇到此崩溃。