Solve the problem of using a background music to change the volume

Source: Internet
Author: User

Problem Description:

Project integration after the push, if the background app is playing music, the result of the opening of the Project app, the music is playing the volume is automatically reduced.

solution : After initializing a push, add the following code to

  Avaudiosession *audiosession = [avaudiosession sharedinstance];    Nserror *setcategoryerror = nil;    BOOL success = [Audiosession setcategory:avaudiosessioncategoryplayback withoptions: Avaudiosessioncategoryoptionmixwithothers error:&setcategoryerror];    if (!success)    {        nsloge (@ "avaudiosession setcategory error:%@", setcategoryerror);    }    else    {        nserror *setactiveerror=nil;        Success=[audiosession setactive:no withoptions:avaudiosessionsetactiveoptionnotifyothersondeactivation Error: &setActiveError];        if (!success)        {            nsloge (@ "avaudiosession setActive error:%@", setcategoryerror);        }    }

  
The actual effect is:

There will be a flash volume down, but immediately recover, because the call setactive for no, but the above setcategory parameters can not be arbitrarily modified, the actual test process changes, the effect is gone.

To be verified are:

If you do this, you can still request enough time slices to run the push code.

Resources:

Technical q&a qa1668:playing Media while in the background using AV Foundation on IOS

Https://developer.apple.com/library/ios/qa/qa1668/_index.html

Defining an Audio Session
https://developer.apple.com/library/prerelease/tvos/documentation/Audio/Conceptual/ Audiosessionprogrammingguide/configuringanaudiosession/configuringanaudiosession.html

IOS Development Beginner: Audio Audio session-songrotek column-Blog channel-csdn.net
http://blog.csdn.net/songrotek/article/details/8887983

By:asiontang

at:2015 November 13 12:11:27

Solve the problem of using a background music to change the volume

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.