#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 __TVOS_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 或 kAudioSessionCategory_AmbientSound微信
用于非以语音为主的应用,使用这个category的应用会随着静音键和屏幕关闭而静音。而且不会停止其它应用播放声音,能够和其它自带应用如iPod,safari等同时播放声音。注意:该Category没法在后台播放声音app
AVAudioSessionCategorySoloAmbient 或 kAudioSessionCategory_SoloAmbientSoundide
相似于AVAudioSessionCategoryAmbient 不一样之处在于它会停止其它应用播放声音。 这个category为默认category。该Category没法在后台播放声音ui
AVAudioSessionCategoryPlayback 或 kAudioSessionCategory_MediaPlaybackthis
用于以语音为主的应用,使用这个category的应用不会随着静音键和屏幕关闭而静音。可在后台播放声音编码
AVAudioSessionCategoryRecord 或 kAudioSessionCategory_RecordAudiospa
用于须要录音的应用,设置该category后,除了来电铃声,闹钟或日历提醒以外的其它系统声音都不会被播放。该Category只提供单纯录音功能。code
AVAudioSessionCategoryPlayAndRecord 或 kAudioSessionCategory_PlayAndRecordorm
用于既须要播放声音又须要录音的应用,语音聊天应用(如微信)应该使用这个category。该Category提供录音和播放功能。若是你的应用须要用到iPhone上的听筒,该category是你惟一的选择,在该Category下声音的默认出口为听筒(在没有外接设备的状况下)。input
AVAudioSessionCategoryAudioProcessing
使用硬件解码器处理音频,该音频会话使用期间,不能播放或录音
这个类别用于音频处理,好比编码解码时/不播放音频/未录音时使用。设置了这种模式,你在应用中就不能播放和录制任何声音。调用AVAPlayer
的prepareToPlay
和play
方法都将返回false
。其余应用的音频也会在此模式下中止。
这个类别能够实现同时能够有多种输出,例如:usb和耳机同时输出,但并不是全部输入输出方式均支持.输入方式仅包括:AVAudioSessionPortUSBAudio/AVAudioSessionPortHeadsetMic AVAudioSessionPortBuiltInMic
;输出仅包括:AVAudioSessionPortUSBAudio /AVAudioSessionPortLineOut /AVAudioSessionPortHeadphones /AVAudioSessionPortHDMI AVAudioSessionPortBuiltInSpeaker
注意:并非一个应用只能使用一个category,程序应该根据实际须要来切换设置不一样的category,举个例子,录音的时候,须要设置为AVAudioSessionCategoryRecord,当录音结束时,应根据程序须要更改category为AVAudioSessionCategoryAmbient,AVAudioSessionCategorySoloAmbient或AVAudioSessionCategoryPlayback中的一种。