Today encountered an iOS play sound interrupt background music problem, in my app if call Avaudiosession play sound, backstage QQ music occasionally can not restore, and NetEase cloud music can not resume playback, study a bit avaudiosession, I call before [audiosession setactive:no error:&err]; There's another way
/* Set the session active or inactive. Note that activating an audio session is a synchronous (blocking) operation.
Therefore, we recommend that applications not activate their session from a thread where a long blocking operation would be Problematic.
Note that this method would throw a exception in apps linked on or after IOS 8 if the session was set inactive while it had Running or
Paused I/O (e.g. audio queues, players, recorders, converters, remote I/Os, etc).
*/
-(bool) setActive: (bool) Active error: (nserror * *) outerror;
-(bool) setActive: (bool) Active Withoptions: (avaudiosessionsetactiveoptions) options Error: (nserror *) outerror Ns_available_ios(6_0);
and Avaudiosessionsetactiveoptions This enumeration
/* Options for use when calling SetActive:withOptions:error:
Avaudiosessionsetactiveoptionnotifyothersondeactivation--
The Notify an interrupted app, the interruption have ended and it may resume playback. Only valid on
Session deactivation. */
typedef ns_options(Nsuinteger, avaudiosessionsetactiveoptions)
{
Avaudiosessionsetactiveoptionnotifyothersondeactivation = 1
} Ns_available_ios(6_0);
The note means: "Notification Interrupt program interrupt has ended, can resume playback ...." “,
It seems that this should be caused by the playing sound caused by the background of QQ music occasionally can not be restored, and NetEase cloud music can not be restored to play the place
< Span class= "S3" > [[ avaudiosession sharedinstance setactive< span class= "s2" >:no withoptions: avaudiosessionsetactiveoptionnotifyothersondeactivation Error:nil; Sure enough, NetEase cloud music can also be restored, read the official Apple article, there is a picture
iOS play sounds interrupt background music issues