There is such a scene, first we recorded, recording and then playback found that the volume has become smaller;
Best of all, view API Discovery Avaudiosession There is an option
If your app involves audio and video calls and plays other sounds, you can look at the following configuration when the sound gets smaller.
Avaudiosessioncategoryoptionduckothers
The Apple document says that if Avaduiosession is configured like this, the other sounds will be smaller in the current scenario.
For example, when using the mobile phone to play music, then when the navigation of the sound play, the sound of music needs to be small, to achieve the navigation of the voice is not affected;
After the navigation sound plays, we need to make the sound of the music back to normal, then it can be reconfigured to activate;
The current scene can also use two players, directly control the volume to achieve;
The following code
// in our audio and video scene configuration, specify that other sounds are forced to become smaller Avaudiosession *ses = [avaudiosession sharedinstance]; [SES setcategory:avaudiosessioncategoryplayandrecord withoptions:avaudiosessioncategoryoptionduckothers Error:nil]; // when our scene ends, the sound becomes smaller in order not to affect other scenes; Avaudiosession *ses = [avaudiosession sharedinstance]; [ses setactive:no error:nil]; [SES setcategory:avaudiosessioncategoryplayandrecord withoptions: Avaudiosessioncategoryoptiondefaulttospeaker Error:nil]; [ses setactive:yes error:nil];
I. Configuring the Avaudiosession interface
/* * *-(BOOL) Setcategory: (NSString *) Category error: (Nserror *) outerror; /* */-(BOOL) Setcategory: (NSString *) category withoptions: (avaudiosessioncategoryoptions) options Error: (Nserror *) outerror Ns_available_ios (6_0); /* */-(BOOL) Setcategory: (NSString *) Category mode: (NSString *) mode options: ( avaudiosessioncategoryoptions) Options Error: (Nserror *) Outerror Ns_available_ios (10_0);
Two. Turn off and activate the Avaudiosession configuration interface
/* 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);
Three. Some configuration options for audio development
Avaudiosessioncategory
AVAudioSessionCategoryAmbient
The current app's play sounds can coexist with the sounds played by other apps, stopping when the lock screen or press mute.
AVAudioSessionCategorySoloAmbient
Only the sound of the current app can be played, and the rest of the app's sounds will stop when the lock screen or press mute is stopped.
AVAudioSessionCategoryPlayback
Only the sound of the current app can be played, and the rest of the app's sounds will stop and will not stop when the lock screen or press mute.
AVAudioSessionCategoryRecord
Can only be used for recording, other app sounds will stop and will not stop when the lock screen or press Mute
AVAudioSessionCategoryPlayAndRecord
Play other sounds while recording, and do not stop when the lock screen or press Mute
AVAudioSessionCategoryAudioProcessing
Use a hardware decoder to process audio that cannot be played or recorded during the use of the audio session
AVAudioSessionCategoryMultiRoute
A variety of audio input and output, such as headphones, USB devices can play simultaneously
Avaudionsessionmode
AVAudioSessionModeDefault
default mode, suitable for all scenarios
AVAudioSessionModeVoiceChat
Applicable category Avaudiosessioncategoryplayandrecord, application scenario VoIP
AVAudioSessionModeGameChat
Applicable category Avaudiosessioncategoryplayandrecord, application scenario game recording, automatically set by Gkvoicechat, no need to call manually
AVAudioSessionModeVideoRecording
Applicable category Avaudiosessioncategoryplayandrecord,avaudiosessioncategoryrecord video recording of application scenarios
AVAudioSessionModeMoviePlayback
Applicable category Avaudiosessioncategoryplayback application scenario video playback
AVAudioSessionModeVideoChat
Applicable category Avaudiosessioncategoryplayandrecord, Video call for application scenario
AVAudioSessionModeMeasurement
Applicable category Avaudiosessioncategoryplayandrecord,avaudiosessioncategoryrecord,avaudiosessioncategoryplayback
AVAudioSessionModeSpokenAudio
IOS9 new additions to the
Avaudiosessioncategoryoptions
AVAudioSessionCategoryOptionMixWithOthers
Suitable for Avaudiosessioncategoryplayandrecord, Avaudiosessioncategoryplayback, and Avaudiosessioncategorymultiroute, Used to mix with other apps
AVAudioSessionCategoryOptionDuckOthers
Suitable for avaudiosessioncategoryambient, Avaudiosessioncategoryplayandrecord, Avaudiosessioncategoryplayback, and Avaudiosessioncategorymultiroute, used to lower the volume of other sound playback, making the period volume smaller
AVAudioSessionCategoryOptionAllowBluetooth
For Avaudiosessioncategoryrecord and Avaudiosessioncategoryplayandrecord, for Bluetooth device headset support, etc.
AVAudioSessionCategoryOptionDefaultToSpeaker
For Avaudiosessioncategoryplayandrecord, used to play sound from speaker, speaker, i.e. hands-free
AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers
For Avaudiosessioncategoryplayandrecord, Avaudiosessioncategoryplayback, and Avaudiosessioncategorymultiroute, iOS9 The newly added
AVAudioSessionCategoryOptionAllowBluetoothA2DP
Suitable for Avaudiosessioncategoryplayandrecord, Bluetooth and A2DP
AVAudioSessionCategoryOptionAllowAirPlay
Suitable for Avaudiosessioncategoryplayandrecord,airplay
Avaudiosessioncategoryoptionduckothers
When setting Categoryplayandrecord, set option to duckothers at the same time, which will depress the other volume playback
Workaround, reset.
This allows a application to set whether or is not the other active audio apps would be a ducked when your app ' s audio
Session goes active. A example of the The Nike app, which provides periodic updates to its user (it reduces the
Volume of any music currently being played while it provides its status). This is defaults to OFF. Note that the other
Audio would be ducked-as long as the current session is active. You'll need to deactivate your audio
Session when you want full volume playback of the other audio.
Reference: HTTP://WWW.JIANSHU.COM/P/3E0A399380DF
IOS avaudiosession configuration (sound becomes smaller after recording)