1、記錄音頻的類別Category
#pragma mark -- Values for the category property --
/* Use this category for background sounds such as rain, car engine noise, etc.
Mixes with other music. */
AVF_EXPORT NSString *const AVAudioSessionCategoryAmbient;
/* Use this category for background sounds. Other music will stop playing. */
AVF_EXPORT NSString *const AVAudioSessionCategorySoloAmbient;
/* Use this category for music tracks.*/
AVF_EXPORT NSString *const AVAudioSessionCategoryPlayback;
/* Use this category when recording audio. */
AVF_EXPORT NSString *const AVAudioSessionCategoryRecord;
/* Use this category when recording and playing back audio. */
AVF_EXPORT NSString *const AVAudioSessionCategoryPlayAndRecord;
/* Use this category when using a hardware codec or signal processor while
not playing or recording audio. */
AVF_EXPORT NSString *const AVAudioSessionCategoryAudioProcessing NS_DEPRECATED_IOS(3_0, 10_0) __TVOS_PROHIBITED __WATCHOS_PROHIBITED;
/* Use this category to customize the usage of available audio accessories and built-in audio hardware.
For example, this category provides an application with the ability to use an available USB output
and headphone output simultaneously for separate, distinct streams of audio data. Use of
this category by an application requires a more detailed knowledge of, and interaction with,
the capabilities of the available audio routes. May be used for input, output, or both.
Note that not all output types and output combinations are eligible for multi-route. Input is limited
to the last-in input port. Eligible inputs consist of the following:
AVAudioSessionPortUSBAudio, AVAudioSessionPortHeadsetMic, and AVAudioSessionPortBuiltInMic.
Eligible outputs consist of the following:
AVAudioSessionPortUSBAudio, AVAudioSessionPortLineOut, AVAudioSessionPortHeadphones, AVAudioSessionPortHDMI,
and AVAudioSessionPortBuiltInSpeaker.
Note that AVAudioSessionPortBuiltInSpeaker is only allowed to be used when there are no other eligible
outputs connected. */
AVF_EXPORT NSString *const AVAudioSessionCategoryMultiRoute NS_AVAILABLE_IOS(6_0);
AVAudioSessionCategoryAmbient
: 此類別適用于伴奏模式
應用,例如用戶在使用音樂應用播放時播放的伴奏。當使用該類別時,來自其他應用程序的音頻會與當前的音頻混合。屏幕鎖定和Silent開關【靜音開關】會使其靜音
。AVAudioSessionCategorySoloAmbient
: 系統(tǒng)默認會話類別。默認情況下,使用該類別意味著應用程序的音頻不可混合
,激活應用中的會話將終止其它音頻
會話不可混合。如允許混合,則改用 AVAudioSessionCategoryAmbient。AVAudioSessionCategoryPlayback
:用于播放錄制音樂或者其它聲音的類別。靜音開關或者鎖屏不會影響音頻的播放
。如要在應用程序轉(zhuǎn)換到后臺時繼續(xù)播放(鎖屏情況下)在xcode
中設置UIBackgroundModes
即可。默認情況下,使用此類別意味著,應用的音頻不可混合,激活音頻會話將中斷其它不可混合的音頻會話。如要使用混音,則使用 AVAudioSessionCategoryOptionMixWithOthers。AVAudioSessionCategoryRecord
: 錄制音頻的類別,此類別使播放音頻靜音。只要該會話處于活動狀態(tài)
,此類別會使系統(tǒng)上的所有輸出停止
。除非需要防止播放其它的聲音,否則建議使用 AVAudioSessionCategoryPlayAndRecord。要在應用程序在后臺繼續(xù)錄制音頻(鎖屏情況)在xcode中設置 UIBackgroundModes 即可。
用戶必須授權音頻錄制權限(iPhone 麥克風權限)。
此類別會話會被 電話呼叫、鬧鐘或者其它非混音音頻會話中斷
-
AVAudioSessionCategoryPlayAndRecord
:錄音(輸入)和播放(輸出)音頻的類別
,例如VoIP(互聯(lián)網(wǎng)語音協(xié)議)應用程序。
靜音鍵開啟和鎖屏都不會影響音頻繼續(xù)播放。如要在應用程序轉(zhuǎn)換到后臺時繼續(xù)播放(鎖屏情況下)在xcode中設置 UIBackgroundModes 即可。此類別適用于同時錄制和播放(語音連麥)
,也適用于錄音/播放(IM語音條)
。但不能同時播放
。默認情況下,使用此類別意味著應用程序的音頻不可混合。激活會話將終端任何其他音頻會話也是不可混合的。要允許為此類別混音,請使用AVAudioSessionCategoryOptionMixWithOthers選項
用戶必須授權音頻錄制權限(iPhone 麥克風權限)
此類別支持Airplay的鏡像版本。但是,如果AVAudioSessionModeVoiceChat模式與此類別一起使用,則AirPlay鏡像將被禁用。
-
AVAudioSessionCategoryMultiRoute
: 用于將不同音頻數(shù)據(jù)流同時路由到不同輸出設備的類別
。此類別可用于輸入,輸出或兩者。 例如,使用此類別將音頻路由到USB設備和一組耳機。 使用這個類別需要對可用音頻路由的功能有更詳細的了解,并與之互動。
路由更改可能會使部分或全部多路由配置失效。 使用AVAudioSessionCategoryMultiRoute類別時,必須注冊以觀察AVAudioSessionRouteChangeNotification通知并根據(jù)需要更新配置。
可用于輸入,輸出或兩者。
請注意,并非所有輸出類型和輸出組合都適用于多路徑。輸入是有限的
到最后一個輸入端口。合格的輸入包括以下內(nèi)容:
AVAudioSessionPortUSBAudio,AVAudioSessionPortHeadsetMic和AVAudioSessionPortBuiltInMic。
符合條件的產(chǎn)出包括以下內(nèi)容:
AVAudioSessionPortUSBAudio,AVAudioSessionPortLineOut,AVAudioSessionPortHeadphones,AVAudioSessionPortHDMI,
和AVAudioSessionPortBuiltInSpeaker。
請注意,AVAudioSessionPortBuiltInSpeaker只允許在沒有其他符合條件時使用
輸出連接。