How to avoid AVErrorMediaServicesWereReset error when there is delay in network

Our app's main feature is to provide online .m4a audio files to users to listen. Recently, there were many users complaining that they had encountered playback failure.


Some of the errors were:


- avPlayer.currentItem.error = Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo={NSLocalizedDescription=Cannot Complete Action, NSLocalizedRecoverySuggestion=Try again later.}


- avPlayer.currentItem.error = Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (352107053), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x281aade90 {Error Domain=NSOSStatusErrorDomain Code=352107053 "(null)"}}


Apart from the error, they all received AVAudioSessionMediaServicesWereResetNotification.


We found that it can be reproduced by using Network Link Conditioner and setting the Delay to around 400ms. In that case, after around 9-10s of loading, the player will throw the AVErrorMediaServicesWereReset error.


Is it possible to set the timeout of the AVPlayer, or is there any other way to handle this problem?