AVAudioSession中的一些枚举

一、Values for the category property
AVAudioSessionCategoryAmbient:后台播放(可与其他音乐混合):下雨声、骑车发动机噪音等。静音停止!
AVAudioSessionCategorySoloAmbient:后台播放,其他音乐都会停止。静音停止!
AVAudioSessionCategoryPlayback:音乐轨道,独占。静音不停止!
AVAudioSessionCategoryRecord:录制音频。静音不停止!
AVAudioSessionCategoryPlayAndRecord:播放音频并且录制。静音不停止!
AVAudioSessionCategoryAudioProcessing:在硬件解码信号过程中不能播放和录制音频,静音不停止!
AVAudioSessionCategoryMultiRoute (6.0以上):通过可以用的音频辅助设备和内置音频硬件设备,我们可以自定义使用类型;
前提input/output限制为下面几种:

Eligible Input

AVAudioSessionPortUSBAudio
AVAudioSessionPortHeadsetMic
AVAudioSessionPortBuiltInMic
Eligible Output

AVAudioSessionPortUSBAudio
AVAudioSessionPortLineOut
AVAudioSessionPortHeadphones
AVAudioSessionPortHDMI
AVAudioSessionPortBuiltInSpeaker
二、Values for the mode property
类别的选择是基于App的基本行为;
而模式的选择多用于专业音频的范畴,选择一个模式将进一步确认App的音频行为。一共7种模式。

AVAudioSessionModeDefault:默认模式
AVAudioSessionModeVideoRecording:使用摄像头捕捉视频。Record类别搭配
AVAudioSessionModeMeasurement:减少设备在处理音频I/O 的信号量时的影响
AVAudioSessionModeMoviePlayback:只能用于内置扬声器,电影播放场景中适当的信号处理
AVAudioSessionModeVideoChat:
AVAudioSessionModeSpokenAudio:
AVAudioSessionModeVoiceChat:Voip,这样模式只能跟PlayAndRecord模式搭配。信号通过系统优化语音,(再理解)
AVAudioSessionModeGameChat:游戏程序(不介绍)
三、ENUM
1.AVAudioSessionInterruptionOptions

AVAudioSessionInterruptionOptionShouldResume:重启
2.AVAudioSessionSetActiveOptions

AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation:通知中断的应用程序被中断已结束,可以申请恢复播放。只有有效的Session才会失活。
3.AVAudioSessionPortOverride

AVAudioSessionPortOverrideNone:返回当前音频默认状态
AVAudioSessionPortOverrideSpeaker:音频输出到扬声器,重写‘播放和录音’属性,通过默认输出路径到接受者。(重新理解)
4.AVAudioSessionRouteChangeReason

这个枚举值是AVAudioSessionRouteChangeNotification字典中的value值。

AVAudioSessionRouteChangeReasonUnknown:原因不明
AVAudioSessionRouteChangeReasonNewDeviceAvailable:一个新设备可用(例如:耳机已经插入)
AVAudioSessionRouteChangeReasonOldDeviceUnavailable:一个旧设备不可用(例如:耳机已经拔出)
AVAudioSessionRouteChangeReasonCategoryChange:音频类别已经改变(例如:Audio从Play back 已给变为Play And Record)
AVAudioSessionRouteChangeReasonOverride:音频route 已经被重写(例如:类别是Play And Record,输出设备已经从默认的接收器改变成为扬声器)
AVAudioSessionRouteChangeReasonWakeFromSleep:设备从休眠中醒来
AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory:没有路径能返回当前的类别(例如:Record类别当前没有输入设备)
AVAudioSessionRouteChangeReasonRouteConfigurationChange:当前输入/输出端口没变,但设置已经修改(例如:一个端口的数据选择已经改变)
5.AVAudioSessionCategoryOptions

使用方法:setCategory:withOptions:error:

AVAudioSessionCategoryOptionMixWithOthers
AVAudioSessionCategoryOptionDuckOthers
AVAudioSessionCategoryOptionAllowBluetooth
AVAudioSessionCategoryOptionDefaultToSpeaker
AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers
6.AVAudioSessionInterruptionType

AVAudioSessionInterruptionTypeBegan
AVAudioSessionInterruptionTypeEnded
7.AVAudioSessionSilenceSecondaryAudioHintType

AVAudioSessionSilenceSecondaryAudioHintTypeBegin
AVAudioSessionSilenceSecondaryAudioHintTypeEnd
8.AVAudioSessionRecordPermission(录音权限)

AVAudioSessionRecordPermissionUndetermined :待定的
AVAudioSessionRecordPermissionDenied :拒绝的
AVAudioSessionRecordPermissionGranted :授予的
9.AVAudioSessionErrorCode(错误原因)

typedef NS_ENUM(NSInteger, AVAudioSessionErrorCode)
{
AVAudioSessionErrorCodeNone = 0,
AVAudioSessionErrorCodeMediaServicesFailed = 'msrv', /* 0x6D737276, 1836282486 /
AVAudioSessionErrorCodeIsBusy = '!act', /
0x21616374, 560030580 /
AVAudioSessionErrorCodeIncompatibleCategory = '!cat', /
0x21636174, 560161140 /
AVAudioSessionErrorCodeCannotInterruptOthers = '!int', /
0x21696E74, 560557684 /
AVAudioSessionErrorCodeMissingEntitlement = 'ent?', /
0x656E743F, 1701737535 /
AVAudioSessionErrorCodeSiriIsRecording = 'siri', /
0x73697269, 1936290409 /
AVAudioSessionErrorCodeCannotStartPlaying = '!pla', /
0x21706C61, 561015905 /
AVAudioSessionErrorCodeCannotStartRecording = '!rec', /
0x21726563, 561145187 /
AVAudioSessionErrorCodeBadParam = -50,
AVAudioSessionErrorInsufficientPriority = '!pri', /
0x21707269, 561017449 /
AVAudioSessionErrorCodeResourceNotAvailable = '!res', /
0x21726573, 561145203 /
AVAudioSessionErrorCodeUnspecified = 'what' /
0x77686174, 2003329396 */
} NS_AVAILABLE_IOS(7_0);
四、constants for port types
1.input port types

AVAudioSessionPortLineIn
AVAudioSessionPortBuiltInMic :内置麦克风
AVAudioSessionPortHeadsetMic :耳机线中的麦克风
2.output port types

AVAudioSessionPortLineOut
AVAudioSessionPortHeadphones :耳机或者耳机式输出设备
AVAudioSessionPortBuiltInReceiver :帖耳朵时候内置扬声器(打电话的时候的听筒)
AVAudioSessionPortBuiltInSpeaker :iOS设备的扬声器
AVAudioSessionPortBluetoothA2DP :A2DP协议式的蓝牙设备
AVAudioSessionPortHDMI :高保真多媒体接口设备
AVAudioSessionPortAirPlay :远程AirPlay设备
AVAudioSessionPortBluetoothLE :蓝牙低电量输出设备
3.可以支持input or output 端口类型

AVAudioSessionPortBluetoothHFP :在蓝牙免提上的input or output
AVAudioSessionPortUSBAudio
AVAudioSessionPortCarAudio
五、SourceLocation&Orientations&PolarPattern&ChannelRoles(~ ~!)
1.Source Location

AVAudioSessionLocationUpper
AVAudioSessionLocationLower
2.Orientation

AVAudioSessionOrientationTop
AVAudioSessionOrientationBottom
AVAudioSessionOrientationFront
AVAudioSessionOrientationBack
AVAudioSessionOrientationLeft
AVAudioSessionOrientationRight
3.Polar pattern

AVAudioSessionPolarPatternOmnidirectional
AVAudioSessionPolarPatternCardioid
AVAudioSessionPolarPatternSubcardioid
六、Helper Class Interface

  1. AVAudioSessionChannelDescription

  2. AVAudioSessionPortDescription

  3. AVAudioSessionRouteDescription

七、 AVAudioSessionDelegate protocol

beginInterruption : 一些东西导致音频被打断(监听回调)
endInterruptionWithFlags :参数只有一个:AVAudioSessionInterruptionOptions,打断结束了
endInterruption :如果执行这个方法,就会默认执行endInterruptionWithFlags
inputIsAvailableChanged:通知input设备是有效的或者无效的

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,585评论 4 365
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,923评论 1 301
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 110,314评论 0 248
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,346评论 0 214
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,718评论 3 291
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,828评论 1 223
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,020评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,758评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,486评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,722评论 2 251
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,196评论 1 262
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,546评论 3 258
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,211评论 3 240
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,132评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,916评论 0 200
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,904评论 2 283
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,758评论 2 274

推荐阅读更多精彩内容

  • 2018-09-09菡菡食物记 早:绿豆粥 午:绿豆粥 晚:芋头+红烧带鱼+青菜+米饭 冥想25min 2018-...
    何不可阅读 520评论 4 0
  • 流水无言而去花儿欢笑而开春的最后跫音叩响夏的沸腾之夜漫坐星光闪闪之下沙土堆上的少年翘首而望一颗流星划过天籁心愿无数...
    昊水长天阅读 263评论 1 3
  • (一)人生若只如初见 七月流火,盛夏时节岳阳城的夜。 我抱着断了弦的焦尾琴站立在《清乐坊》的门前,扣响门扉。 《清...
    笔间流年阅读 398评论 0 0