APP啟動(dòng)的時(shí)候會(huì)自動(dòng)激活A(yù)VAudioSession單例,但是建議在使用前再次進(jìn)行激活。

AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation:通知中斷的程序中斷已經(jīng)結(jié)束,可以恢復(fù)播放

獲取設(shè)備支持的categories列表

AVAudioSession設(shè)置

AVAudioSessionCategory枚舉:
AVAudioSessionCategoryAmbient ?只支持播放

AVAudioSessionCategorySoloAmbient ?系統(tǒng)默認(rèn),只支持播放

AVAudioSessionCategoryPlayback ?只支持播放,常用于音樂(lè)播放類app,不會(huì)因鎖屏而停止播放,后臺(tái)播放

AVAudioSessionCategoryRecord ?只支持錄制

AVAudioSessionCategoryPlayAndRecord ? ?支持錄制及播放,可同時(shí)錄制并播放

AVAudioSessionCategoryAudioProcessing ? ?只支持本地音頻編解碼

AVAudioSessionCategoryMultiRoute ? ?支持錄制及播放,支持多條音頻流的同步輸入和輸出,例如藍(lán)牙耳機(jī)和藍(lán)牙播放器可以同時(shí)使用

AVAudioSessionMode枚舉:
AVAudioSessionModeDefault ?系統(tǒng)默認(rèn)mode

AVAudioSessionModeVoiceChat ?適用于語(yǔ)音聊天

AVAudioSessionModeGameChat ?適用于游戲模式,不需要主動(dòng)設(shè)置。
適用GKVoiceChat對(duì)象時(shí),系統(tǒng)會(huì)自動(dòng)配置AVAudioSessionModeGameChat和AVAudioSessionCategoryPlayAndRecord。若不想用GKVoiceChat但希望達(dá)到類似功能,可以使用AVAudioSessionModeVoiceChat。

AVAudioSessionModeVideoRecording ?適用于使用攝像頭采集視頻的應(yīng)用

AVAudioSessionModeMeasurement ?

AVAudioSessionModeMoviePlayback ?適用于AVAudioSessionCategoryPlayback下的視頻播放

AVAudioSessionModeVideoChat ?適用于視頻聊天
設(shè)置mode為AVAudioSessionModeVideoChat,系統(tǒng)會(huì)自動(dòng)配置AVAudioSessionCategoryOptionAllowBluetooth和AVAudioSessionCategoryOptionDefaultToSpeaker。會(huì)選擇最佳的內(nèi)置麥克風(fēng)組合支持聊天。

AVAudioSessionModeSpokenAudio ?iOS9.0新添加的
當(dāng)其他應(yīng)用程序播放短暫的語(yǔ)音提示時(shí),希望自己的音頻暫停而不是回避(聲音變?。r(shí)使用。

AVAudioSessionModeVoicePrompt ?當(dāng)程序內(nèi)音頻為簡(jiǎn)單的語(yǔ)音提示時(shí)使用。

AVAudioSessionCategoryOptions:

AVAudioSessionCategoryOptionMixWithOthers


AVAudioSessionCategoryOptionDuckOthers


AVAudioSessionCategoryOptionAllowBluetooth


AVAudioSessionCategoryOptionDefaultToSpeaker


AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers


AVAudioSessionCategoryOptionAllowBluetoothA2DP


AVAudioSessionCategoryOptionAllowAirPlay

