AVAudioSession(KSY) Category Reference

Declared in AVAudioSession+KSY.h

Overview

iOS的AVAudioSession 属性配置工具类

  1. 主要是保证推流时有采集和播放音频的权限 AVAudioSessionCategoryPlayAndRecord
  2. 将一些常用的AVAudioSession的配置项提取为属性, 方便设置
  3. 提供查询和修改当前音频采集设备相关的工具函数 比如查询是否有耳机

– setDefaultCfg

设置默认配置

- (void)setDefaultCfg

Discussion

bInterruptOtherAudio : NO

bDefaultToSpeaker : YES

bAllowBluetooth : YES

AVAudioSessionCategory : AVAudioSessionCategoryPlayAndRecord

Declared In

AVAudioSession+KSY.h

  bInterruptOtherAudio

是否打断其他后台的音乐播放 (默认为NO)

@property (nonatomic, assign) BOOL bInterruptOtherAudio

Discussion

也可以理解为是否允许在其他后台音乐播放的同时进行采集

YES:开始采集时,会打断其他的后台播放音乐,也会被其他音乐打断(采集过程中,启动其他音乐播放,音频采集被中止)

NO: 可以与其他后台播放共存,相互之间不会被打断

参考 AVAudioSessionCategoryOptionMixWithOthers

Declared In

AVAudioSession+KSY.h

  bDefaultToSpeaker

启动采集后,是否从扬声器播放声音 (默认为YES)

@property (nonatomic, assign) BOOL bDefaultToSpeaker

Discussion

启动声音采集后,iOS系统的行为是默认从听筒播放声音的

将该属性设为YES, 则改为默认从扬声器播放

参考 AVAudioSessionCategoryOptionDefaultToSpeaker

Declared In

AVAudioSession+KSY.h

  bAllowBluetooth

是否启用蓝牙设备 (默认为YES)

@property (nonatomic, assign) BOOL bAllowBluetooth

Discussion

参考 AVAudioSessionCategoryOptionAllowBluetooth

Declared In

AVAudioSession+KSY.h

  AVAudioSessionCategory

本SDK使用的AVAudioSession的类别 (默认为AVAudioSessionCategoryPlayAndRecord)

@property (nonatomic, assign) NSString *AVAudioSessionCategory

Discussion

用于指定推流过程中需要采集和播放音频的权限

Warning: 如无必要请勿修改

Declared In

AVAudioSession+KSY.h

+ isBluetoothInputAvaible

是否有蓝牙麦克风可用

+ (BOOL)isBluetoothInputAvaible

Return Value

是/否有蓝牙麦克风可用

Declared In

AVAudioSession+KSY.h

+ switchBluetoothInput:

选择是否使用蓝牙麦克风

+ (BOOL)switchBluetoothInput:(BOOL)onOrOff

Parameters

onOrOff

: YES 使用蓝牙麦克风 NO

Return Value

是/否有蓝牙麦克风可用

Declared In

AVAudioSession+KSY.h

+ isHeadsetInputAvaible

是否有耳机麦克风可用

+ (BOOL)isHeadsetInputAvaible

Return Value

是/否有耳机麦克风

Declared In

AVAudioSession+KSY.h

+ isHeadsetPluggedIn

查询当前是否有耳机(包括蓝牙耳机)

+ (BOOL)isHeadsetPluggedIn

Declared In

AVAudioSession+KSY.h

  currentMicType

当前使用的音频采集设备

@property KSYMicType currentMicType

Discussion

当设置新值时, 如果修改成功, 重新查询为新值, 修改不成功值不变

参考 KSYMicType

Declared In

AVAudioSession+KSY.h