iOS play sounds interrupt background music issues

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.