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