Avaudiorecorder background troubleshooting

Source: Internet
Author: User

Avaudiorecorder performs recording, and the background music is relentlessly stopped. The solution is as follows:

First, set [[avaudiosession sharedinstance] setactive: Yes error: Nil] before starting the recording.

[[Avaudiosession sharedinstance] setcategory: avaudiosessioncategoryplayandrecord error: Nil];

After the recording is completed, it is in its callback function.

-(Void) audiorecorderdidfinishrecording :( avaudiorecorder *) arecorder successfully :( bool) Flag

Add: [[avaudiosession sharedinstance] setactive: no error: Nil];
You can.

(Using avaudioplayer to play music is also handled)

The active attribute of avaudiosession is to set the startup and shutdown of your audio session. After your recording ends, you must disable avaudiosession to enable the background music on your own. (Many examples on the Internet only start it, but it is not closed. As a result, avaudiosession is always active and the normal playing of background music is blocked) the category attribute of avaudiosession is to set its category. It has the following categories:

Get input hardware get output hardware and iPod mix
Follow the ringtone/mute
Avaudiosessioncategoryambient No Yes

Avaudiosessioncategorysoloambient No Yes No

Avaudiosessioncategoryplayback No Yes No

Avaudiosessioncategoryrecord: No

Avaudiosessioncategoryplayandrecord Yes No

If you want your music to continue playing in the background after the program exits,

You can set it as follows:

[[Avaudiosession sharedinstance] setcategory: avaudiosessioncategoryplayandrecord error: Nil];

Add it to the plist of your project

Add in info. plist

<Key> required background modes </key>


<String> app plays audio </string>


You can.

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.