The background music is interrupted during ios playback.

Source: Internet
Author: User

The background music is interrupted during ios playback.
 

Today, I encountered a problem where the background music was interrupted during ios playback. In my app, if AVAudioSession was called to play the audio, QQ music in the background could not be recovered occasionally, netease cloud music cannot resume playing once. After studying AVAudioSession, I called [audioSession setActive: NO error: & err]. There is another method.

/* 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 will be problematic.

Note that this method will throw an exception in apps linked on or after iOS 8 if the session is set inactive while it has 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 witexceptions :( AVAudioSessionSetActiveOptions) options error :( NSError **) outError NS_AVAILABLE_IOS (6_0 );

AVAudioSessionSetActiveOptions

/* Options for use when calling setActive: witexceptions: error:

AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation --

Using Y an interrupted app that the interruption has ended and it may resume playback. Only valid on

Session deactivation .*/

Typedef NS_OPTIONS (NSUInteger, AVAudioSessionSetActiveOptions)

{

Avaudiosessionsetactiveoption=yothersondeactivation = 1

} NS_AVAILABLE_IOS (6_0 );

The meaning of the comment is: "The interrupted program has ended and playback can be resumed .... ",

It seems that the playing sound may cause occasional failure to recover QQ music in the background, while Netease cloud music cannot resume playing once.

 

Then change it to [[AVAudioSession sharedInstance] setActive: NO witexceptions: avaudiosessionsetactiveoption=yothersondeactivation error: nil]. NetEase cloud music can be restored. After reading the official Apple article, there is a picture on it.

 

 

Related Article

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.