When I receive the InterruptionBegan notification (the interruption type is AVAudioSessionInterruptionTypeBegan) , I pause playing music. When I receive the InterruptionEnded notification (the interruption type is AVAudioSessionInterruptionTypeEnded), I resume playing music. however, sometimes i has got the error code: AVAudioSessionErrorCodeCannotInterruptOthers (560557684)
If some malicious app to take up the audio, which leads to the third party app music playback recovery fails, an error AVAudioSessionErrorCodeCannotInterruptOthers.
In this case, can we know which apps are maliciously hogging the audio?
Please refer to the documentation for AVAudioSession.ErrorCode.cannotInterruptOthers. It states that you get this error when trying to activate in the background an audio session that is not mixable, that is, an audio session that does not include the mixWithOthers option, for example.
Please also see AVAudioSession.InterruptionOptions.shouldResume for a discussion on how to correctly handle an interruption notification of type AVAudioSession.InterruptionType.ended. It's not always appropriate to resume audio playback without user input.