AVAudioSession错误:取消激活已运行I/O的音频会话

xuy*_*fei 6 ios avaudiosession

2017-02-24 14:56:44.280 PropertyManager[10172:5336578] 14:56:44.280 ERROR:    [0x1a0a24000] AVAudioSession.mm:692: -[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.

2017-02-24 14:56:44.281 PropertyManager[10172:5336578] error === Error Domain=NSOSStatusErrorDomain Code=560030580 "(null)"
PropertyManager was compiled with optimization - stepping may behave oddly; variables may not be available.
Run Code Online (Sandbox Code Playgroud)

NSN*_*oob 11

您的错误日志非常简洁自我表达:

Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session
Run Code Online (Sandbox Code Playgroud)

它告诉你问题以及解决方案.

现在你正在做这样的事情:

[[AVAudioSession sharedInstance] setActive:NO
               withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation
                                             error:nil];
Run Code Online (Sandbox Code Playgroud)

但是,您应首先停止音频播放器实例,然后将激活状态设置为是或否.

[yourAudioPlayer stop];
[[AVAudioSession sharedInstance] setActive:NO
                   withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation
                                                 error:nil];
Run Code Online (Sandbox Code Playgroud)

请参阅Apple文档以查看枚举AudioSessionSetActiveOption的值.

另请参阅:setActive上的Apple文档:withOptions方法

至于你的第二个错误

PropertyManager was compiled with optimization - stepping may behave oddly; variables may not be available.
Run Code Online (Sandbox Code Playgroud)

看到这个优秀的答案.

  • 即使确定播放器已暂停,我仍然会收到错误消息。在尝试停用会话之前,我什至将其设置为零,但是没有任何改变。 (2认同)