iOS Audio processing development (i) category configuration issues in iOS audiosession

Source: Internet
Author: User

How to choose the category of IOS Audiosession


1.kaudiosessioncategory_ambientsound or Avaudiosessioncategoryambient

Applications using this category will mute with mute keys and screen shutdowns. And will not stop other applications play sound, and will not be played by other applications sound stop, you can and other applications such as Ipod,safari, such as the simultaneous playback of sound. Note: The category cannot play the sound in the background, even if the application is powered on background Modes audio,airplay and picture in the picture mode

UInt32 sessioncategory = Kaudiosessioncategory_ambientsound;

Audiosessionsetproperty (Kaudiosessionproperty_audiocategory,

sizeof (Sessioncategory),

&sessioncategory);


2.kaudiosessioncategory_soloambientsound or Avaudiosessioncategorysoloambient

Using this category application will stop other applications from playing the sound and will mute with the mute key and the screen off. The category is the Avaudioplayer default category. Note: The category cannot play the sound in the background, even if the application is powered on background Modes audio,airplay and picture in the picture mode

UInt32 sessioncategory = Kaudiosessioncategory_soloambientsound;

Audiosessionsetproperty (Kaudiosessionproperty_audiocategory,

sizeof (Sessioncategory),

&sessioncategory);


3.kaudiosessioncategory_mediaplayback or Avaudiosessioncategoryplayback

Using this category application, the other application will be interrupted to play the sound, and other applications will interrupt its sound playback, will not mute with the mute key and screen off. Note: You can play the sound in the background, but take the initiative to open background Modes audio,airplay and picture in the picture mode

UInt32 sessioncategory = Kaudiosessioncategory_mediaplayback;

Audiosessionsetproperty (Kaudiosessionproperty_audiocategory,

sizeof (Sessioncategory),

&sessioncategory);


4. Kaudiosessioncategory_recordaudio or Avaudiosessioncategoryrecord

The category is used for applications that require recording, and the category will not be played except for the ringing, alarm or calendar reminders. This category only provides a simple recording function. Note that this time I found that the volume of mobile phone system has no effect.

UInt32 sessioncategory = Kaudiosessioncategory_recordaudio;

Audiosessionsetproperty (Kaudiosessionproperty_audiocategory,

sizeof (Sessioncategory),

&sessioncategory);


5. Kaudiosessioncategory_playandrecord or Avaudiosessioncategoryplayandrecord

The category is used for applications that require both sound playback and recording. If our applications need to use the handset on the iphone, then this category is our only option, under the category the default exit for the sound is the handset (in the absence of an external device). Of course, if we want to use this category, but also the sound from the speaker out, then we can go to modify the Audiosession kaudiosessionproperty_ The Overrideaudioroute property is Kaudiosessionoverrideaudioroute_speaker. But if you don't use this category, you can't let the sound go to the handset. When necessary, the category of audiosession must be actively switched.

By default:

UInt32 sessioncategory = Kaudiosessioncategory_playandrecord;

Audiosessionsetproperty (Kaudiosessionproperty_audiocategory,

sizeof (Sessioncategory),

&sessioncategory);

Let the sound play out from the speaker:

UInt32 sessioncategory = Kaudiosessioncategory_playandrecord;

Audiosessionsetproperty (Kaudiosessionproperty_audiocategory,

sizeof (Sessioncategory),

&sessioncategory);

UInt32 audiorouteoverride = Kaudiosessionoverrideaudioroute_speaker;

Audiosessionsetproperty (Kaudiosessionproperty_overrideaudioroute, sizeof (Audiorouteoverride),

&audiorouteoverride);


Note : It is not an application can only use a category, the program should be based on the actual need to switch settings for different category, for example, recording, you need to set to Avaudiosessioncategoryrecord, When the recording is finished, you should change the category to avaudiosessioncategoryambient according to the procedure. One of the avaudiosessioncategorysoloambient or Avaudiosessioncategoryplayback.



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.